ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkLayerBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkLayerBase_h
19 #define __itkLayerBase_h
20 
21 #include <iostream>
23 #include "itkInputFunctionBase.h"
24 
25 #include "itkWeightSetBase.h"
26 
27 namespace itk
28 {
29 namespace Statistics
30 {
37 template<class TMeasurementVector, class TTargetVector>
39 {
40 public:
41  typedef LayerBase Self;
45 
47  itkTypeMacro(LayerBase, LightProcessObject);
48 
49  typedef TMeasurementVector InputVectorType;
50  typedef TTargetVector OutputVectorType;
51 
52  typedef typename TMeasurementVector::ValueType ValueType;
54  typedef const ValueType* ValueConstPointer;
57 
63 
64  //The only valid layer types
66 
67  virtual void SetNumberOfNodes(unsigned int);
68  unsigned int GetNumberOfNodes() const;
69 
70  virtual ValueType GetInputValue(unsigned int) const = 0;
71  virtual ValueType GetOutputValue(unsigned int) const = 0;
72  virtual ValuePointer GetOutputVector() = 0;
73 
74  virtual void ForwardPropagate(){};
75  virtual void ForwardPropagate(TMeasurementVector){};
76 
77  virtual void BackwardPropagate(){};
79 
80  virtual ValueType GetOutputErrorValue(unsigned int) const = 0;
81  virtual void SetOutputErrorValues(TTargetVector) {};
82 
83  virtual ValueType GetInputErrorValue(unsigned int) const = 0;
84  virtual ValuePointer GetInputErrorVector() = 0;
85  virtual void SetInputErrorValue(ValueType, unsigned int) {};
86 
87  //itkSetObjectMacro(InputWeightSet, WeightSetInterfaceType);
89  itkGetObjectMacro(InputWeightSet, WeightSetInterfaceType);
90  itkGetConstObjectMacro(InputWeightSet, WeightSetInterfaceType);
91 
92  //itkSetObjectMacro(OutputWeightSet, WeightSetInterfaceType);
94  itkGetObjectMacro(OutputWeightSet, WeightSetInterfaceType);
95  itkGetConstObjectMacro(OutputWeightSet, WeightSetInterfaceType);
96 
98  itkGetObjectMacro(NodeInputFunction, InputFunctionInterfaceType);
99  itkGetConstObjectMacro(NodeInputFunction, InputFunctionInterfaceType);
100 
102  itkGetObjectMacro(ActivationFunction, TransferFunctionInterfaceType);
103  itkGetConstObjectMacro(ActivationFunction, TransferFunctionInterfaceType);
104 
105  virtual ValueType Activation(ValueType) = 0;
106  virtual ValueType DActivation(ValueType) = 0;
107 
108  itkSetEnumMacro(LayerTypeCode, LayerTypeCode);
109  itkGetEnumMacro(LayerTypeCode, LayerTypeCode);
110 
111  //#define __USE_OLD_INTERFACE Comment out to ensure that new interface works
112 #ifdef __USE_OLD_INTERFACE
113  void SetLayerType(const LayerTypeCode value) { SetLayerTypeCode(value); }
114  LayerTypeCode GetLayerType(void) { return GetLayerTypeCode(); }
115  //For backwards compatibility
116  void SetLayerType(const unsigned int value)
117  {
118  switch(value)
119  {
120  case 0:
121  SetLayerType(INVALIDLAYER);
122  break;
123  case 1:
124  SetLayerType(INPUTLAYER);
125  break;
126  case 2:
127  SetLayerType(HIDDENLAYER);
128  break;
129  case 3:
130  SetLayerType(OUTPUTLAYER);
131  break;
132  default:
133  //Throw Exception Here
134  break;
135  }
136  }
137 #endif
138  itkSetMacro(LayerId,unsigned int);
139  itkGetConstReferenceMacro(LayerId,unsigned int);
140 
141  //virtual void SetBias(const ValueType) = 0;
142  //virtual const ValueType & GetBias() const = 0;
143 
144 protected:
145  LayerBase();
146  ~LayerBase();
147 
149  virtual void PrintSelf( std::ostream& os, Indent indent ) const;
150 
151  LayerTypeCode m_LayerTypeCode; //input, hidden, output
152  unsigned int m_LayerId;
153  unsigned int m_NumberOfNodes;
154 
157 
160 
161 }; //class layer base
162 
163 } //namespace itk
164 } //namespace statistics
165 
166 #ifndef ITK_MANUAL_INSTANTIATION
167 #include "itkLayerBase.hxx"
168 #endif
169 
170 #endif
171