(params, env)
| 131 | |
| 132 | |
| 133 | def reward_function(params, env): |
| 134 | model = ANN(D, M, K) |
| 135 | model.set_params(params) |
| 136 | |
| 137 | # play one episode and return the total reward |
| 138 | episode_reward = 0 |
| 139 | episode_length = 0 # not sure if it will be used |
| 140 | done = False |
| 141 | obs = env.reset() |
| 142 | obs_dim = len(obs) |
| 143 | if HISTORY_LENGTH > 1: |
| 144 | state = np.zeros(HISTORY_LENGTH*obs_dim) # current state |
| 145 | state[obs_dim:] = obs |
| 146 | else: |
| 147 | state = obs |
| 148 | while not done: |
| 149 | # get the action |
| 150 | action = model.sample_action(state) |
| 151 | |
| 152 | # perform the action |
| 153 | obs, reward, done = env.step(action) |
| 154 | |
| 155 | # update total reward |
| 156 | episode_reward += reward |
| 157 | episode_length += 1 |
| 158 | |
| 159 | # update state |
| 160 | if HISTORY_LENGTH > 1: |
| 161 | state = np.roll(state, -obs_dim) |
| 162 | state[-obs_dim:] = obs |
| 163 | else: |
| 164 | state = obs |
| 165 | print("Reward:", episode_reward) |
| 166 | |
| 167 | |
| 168 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected