| 41 | |
| 42 | |
| 43 | class Model: |
| 44 | def __init__(self, grid): |
| 45 | # fit the featurizer to data |
| 46 | samples = gather_samples(grid) |
| 47 | # self.featurizer = Nystroem() |
| 48 | self.featurizer = RBFSampler() |
| 49 | self.featurizer.fit(samples) |
| 50 | dims = self.featurizer.n_components |
| 51 | |
| 52 | # initialize linear model weights |
| 53 | self.w = np.zeros(dims) |
| 54 | |
| 55 | def predict(self, s): |
| 56 | x = self.featurizer.transform([s])[0] |
| 57 | return x @ self.w |
| 58 | |
| 59 | def grad(self, s): |
| 60 | x = self.featurizer.transform([s])[0] |
| 61 | return x |
| 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |