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

Class Model

rl/cartpole.py:44–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class Model:
45 def __init__(self, env):
46 # fit the featurizer to data
47 self.env = env
48 samples = gather_samples(env)
49 self.featurizer = RBFSampler()
50 self.featurizer.fit(samples)
51 dims = self.featurizer.n_components
52
53 # initialize linear model weights
54 self.w = np.zeros(dims)
55
56 def predict(self, s, a):
57 sa = np.concatenate((s, [a]))
58 x = self.featurizer.transform([sa])[0]
59 return x @ self.w
60
61 def predict_all_actions(self, s):
62 return [self.predict(s, a) for a in range(self.env.action_space.n)]
63
64 def grad(self, s, a):
65 sa = np.concatenate((s, [a]))
66 x = self.featurizer.transform([sa])[0]
67 return x
68
69
70def test_agent(model, env, n_episodes=20):

Callers 15

cartpole.pyFile · 0.70
ann.pyFile · 0.50
cnn.pyFile · 0.50
dropout.pyFile · 0.50
cnn_cifar.pyFile · 0.50
translation.pyFile · 0.50
sine2.pyFile · 0.50
sine.pyFile · 0.50
batchnorm.pyFile · 0.50
mlpFunction · 0.50

Calls

no outgoing calls

Tested by 4

lstm1Function · 0.40
lstm2Function · 0.40
gru1Function · 0.40
gru2Function · 0.40