NeuralRegressor.__init__()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from theano import tensor as T
5
import deepy.tensor as DT
6
from . import NeuralNetwork
7
from deepy.utils import dim_to_var
8
9
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)