RL-Projects-SK icon indicating copy to clipboard operation
RL-Projects-SK copied to clipboard

Questions about bucketize_state_value

Open borninfreedom opened this issue 4 years ago • 2 comments

What's the means of the following codes? Is there any mathematical formula?

def bucketize_state_value(state_value):
    ''' Discretizes continuous values into fixed buckets'''
    #print('len(state_value):', len(state_value))
    bucket_indices = []
    for i in range(len(state_value)):
        if state_value[i] <= state_value_bounds[i][0]:   # violates lower bound
            bucket_index = 0
        elif state_value[i] >= state_value_bounds[i][1]: # violates upper bound
            bucket_index = no_buckets[i] - 1  # put in the last bucket
        else:
            bound_width = state_value_bounds[i][1] - state_value_bounds[i][0]
            offset = (no_buckets[i]-1) * state_value_bounds[i][0] / bound_width
            scaling = (no_buckets[i]-1) / bound_width
            bucket_index = int(round(scaling*state_value[i]-offset))

        bucket_indices.append(bucket_index)
    return(tuple(bucket_indices))

borninfreedom avatar Aug 24 '20 08:08 borninfreedom