(self, D, ft, hidden_layer_sizes=[])
| 151 | # approximates V(s) |
| 152 | class ValueModel: |
| 153 | def __init__(self, D, ft, hidden_layer_sizes=[]): |
| 154 | self.ft = ft |
| 155 | |
| 156 | # create the graph |
| 157 | self.layers = [] |
| 158 | M1 = D |
| 159 | for M2 in hidden_layer_sizes: |
| 160 | layer = HiddenLayer(M1, M2) |
| 161 | self.layers.append(layer) |
| 162 | M1 = M2 |
| 163 | |
| 164 | # final layer |
| 165 | layer = HiddenLayer(M1, 1, lambda x: x) |
| 166 | self.layers.append(layer) |
| 167 | |
| 168 | # get all params for gradient later |
| 169 | params = [] |
| 170 | for layer in self.layers: |
| 171 | params += layer.params |
| 172 | |
| 173 | # inputs and targets |
| 174 | X = T.matrix('X') |
| 175 | Y = T.vector('Y') |
| 176 | |
| 177 | # calculate output and cost |
| 178 | Z = X |
| 179 | for layer in self.layers: |
| 180 | Z = layer.forward(Z) |
| 181 | Y_hat = T.flatten(Z) |
| 182 | cost = T.sum((Y - Y_hat)**2) |
| 183 | |
| 184 | # specify update rule |
| 185 | updates = adam(cost, params, lr0=1e-1) |
| 186 | |
| 187 | # compile functions |
| 188 | self.train_op = theano.function( |
| 189 | inputs=[X, Y], |
| 190 | updates=updates, |
| 191 | allow_input_downcast=True |
| 192 | ) |
| 193 | self.predict_op = theano.function( |
| 194 | inputs=[X], |
| 195 | outputs=Y_hat, |
| 196 | allow_input_downcast=True |
| 197 | ) |
| 198 | |
| 199 | def partial_fit(self, X, Y): |
| 200 | X = np.atleast_2d(X) |
nothing calls this directly
no test coverage detected