(params, display=False)
| 139 | |
| 140 | |
| 141 | def reward_function(params, display=False): |
| 142 | model = ANN(D, M, K) |
| 143 | model.set_params(params) |
| 144 | |
| 145 | env = gym.make(ENV_NAME) |
| 146 | if display: |
| 147 | env = gym.wrappers.Monitor(env, 'es_monitor') |
| 148 | |
| 149 | # play one episode and return the total reward |
| 150 | episode_reward = 0 |
| 151 | episode_length = 0 # not sure if it will be used |
| 152 | done = False |
| 153 | state = env.reset() |
| 154 | while not done: |
| 155 | # display the env |
| 156 | if display: |
| 157 | env.render() |
| 158 | |
| 159 | # get the action |
| 160 | action = model.sample_action(state) |
| 161 | |
| 162 | # perform the action |
| 163 | state, reward, done, _ = env.step(action) |
| 164 | |
| 165 | # update total reward |
| 166 | episode_reward += reward |
| 167 | episode_length += 1 |
| 168 | |
| 169 | return episode_reward |
| 170 | |
| 171 | |
| 172 | if __name__ == '__main__': |
no test coverage detected