RL-Projects-SK
RL-Projects-SK copied to clipboard
Questions about bucketize_state_value
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))