MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / sample_action

Method sample_action

rl2/mountaincar/q_learning.py:87–97  ·  view source on GitHub ↗
(self, s, eps)

Source from the content-addressed store, hash-verified

85 self.models[a].partial_fit(X, [G])
86
87 def sample_action(self, s, eps):
88 # eps = 0
89 # Technically, we don't need to do epsilon-greedy
90 # because SGDRegressor predicts 0 for all states
91 # until they are updated. This works as the
92 # "Optimistic Initial Values" method, since all
93 # the rewards for Mountain Car are -1.
94 if np.random.random() < eps:
95 return self.env.action_space.sample()
96 else:
97 return np.argmax(self.predict(s))
98
99
100# returns a list of states_and_rewards, and the total reward

Callers 1

play_oneFunction · 0.45

Calls 2

predictMethod · 0.95
sampleMethod · 0.45

Tested by

no test coverage detected