MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / reward_function

Function reward_function

rl3/es_mujoco.py:141–169  ·  view source on GitHub ↗
(params, display=False)

Source from the content-addressed store, hash-verified

139
140
141def 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
172if __name__ == '__main__':

Callers 1

es_mujoco.pyFile · 0.70

Calls 5

set_paramsMethod · 0.95
resetMethod · 0.95
sample_actionMethod · 0.95
stepMethod · 0.95
ANNClass · 0.70

Tested by

no test coverage detected