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

Class Model

rl/approx_control.py:57–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55
56
57class Model:
58 def __init__(self, grid):
59 # fit the featurizer to data
60 samples = gather_samples(grid)
61 # self.featurizer = Nystroem()
62 self.featurizer = RBFSampler()
63 self.featurizer.fit(samples)
64 dims = self.featurizer.n_components
65
66 # initialize linear model weights
67 self.w = np.zeros(dims)
68
69 def predict(self, s, a):
70 sa = merge_state_action(s, a)
71 x = self.featurizer.transform([sa])[0]
72 return x @ self.w
73
74 def predict_all_actions(self, s):
75 return [self.predict(s, a) for a in ALL_POSSIBLE_ACTIONS]
76
77 def grad(self, s, a):
78 sa = merge_state_action(s, a)
79 x = self.featurizer.transform([sa])[0]
80 return x
81
82
83if __name__ == '__main__':

Callers 1

approx_control.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected