Created
June 3, 2018 09:03
-
-
Save pyliaorachel/79dc77a6a37916f0c06a4e687d3cb2a5 to your computer and use it in GitHub Desktop.
OpenAI Gym CartPole - Q table (get state)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_state(observation, n_buckets, state_bounds): | |
| state = [0] * len(observation) | |
| for i, s in enumerate(observation): # 每個 feature 有不同的分配 | |
| l, u = state_bounds[i][0], state_bounds[i][1] # 每個 feature 值的範圍上下限 | |
| if s <= l: # 低於下限,分配為 0 | |
| state[i] = 0 | |
| elif s >= u: # 高於上限,分配為最大值 | |
| state[i] = n_buckets[i] - 1 | |
| else: # 範圍內,依比例分配 | |
| state[i] = int(((s - l) / (u - l)) * n_buckets[i]) | |
| return tuple(state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment