| Total Complexity | 11 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| 1 | #!/usr/bin/env python |
||
| 7 | class ComputationalGraph(NeuralNetwork): |
||
| 8 | """ |
||
| 9 | A simple neural network that the last layer outputs cost. |
||
| 10 | """ |
||
| 11 | |||
| 12 | def __init__(self, input_dim=0, model=None, input_tensor=None, |
||
| 13 | cost=None, output=None, blocks=None, input_vars=None, target_vars=None): |
||
| 14 | """ |
||
| 15 | Create a basic network. |
||
| 16 | |||
| 17 | Parameters: |
||
| 18 | input_dim - dimension of input variable |
||
| 19 | model - a short hand to specify the model |
||
| 20 | config - network configuration |
||
| 21 | input_tensor - specify the tensor of input if it's special |
||
| 22 | """ |
||
| 23 | super(ComputationalGraph, self).__init__(input_dim, input_tensor=input_tensor) |
||
| 24 | if model: |
||
| 25 | self.stack(model) |
||
| 26 | if output: |
||
| 27 | self.stack(output) |
||
| 28 | if cost: |
||
| 29 | self.stack(cost) |
||
| 30 | if blocks: |
||
| 31 | self.register(*blocks) |
||
| 32 | if input_vars: |
||
| 33 | self.input_variables = [t.tensor for t in input_vars] |
||
| 34 | if target_vars: |
||
| 35 | self.target_variables = [t.tensor for t in target_vars] |
||
| 36 | |||
| 37 | |||
| 38 | @property |
||
| 39 | def cost(self): |
||
| 40 | return self.output |
||
| 41 | |||
| 42 | @property |
||
| 43 | def test_cost(self): |
||
| 44 | return self.test_output |