| Total Complexity | 7 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python |
||
| 10 | class NeuralRegressor(NeuralNetwork): |
||
| 11 | """ |
||
| 12 | A class of defining stacked neural network regressors. |
||
| 13 | """ |
||
| 14 | def __init__(self, input_dim, target_tensor=2, clip_value=None, input_tensor=None): |
||
| 15 | self.target_tensor = dim_to_var(target_tensor, "k") if type(target_tensor) == int else target_tensor |
||
| 16 | self.clip_value = clip_value |
||
| 17 | super(NeuralRegressor, self).__init__(input_dim, input_tensor=input_tensor) |
||
| 18 | |||
| 19 | def setup_variables(self): |
||
| 20 | super(NeuralRegressor, self).setup_variables() |
||
| 21 | self.k = self.target_tensor |
||
| 22 | self.target_variables.append(self.k) |
||
| 23 | |||
| 24 | def _cost_func(self, y): |
||
| 25 | if self.clip_value: |
||
| 26 | y = T.clip(y, -self.clip_value, self.clip_value) |
||
| 27 | return DT.costs.least_squares(y, self.k) |
||
| 28 | |||
| 29 | @property |
||
| 30 | def cost(self): |
||
| 31 | return self._cost_func(self.output) |
||
| 32 | |||
| 33 | @property |
||
| 34 | def test_cost(self): |
||
| 35 | return self._cost_func(self.test_output) |