ITK  4.2.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 
41 public:
42  typedef LayerBase Self;
46 
48  itkTypeMacro(LayerBase, LightProcessObject);
49 
50  typedef TMeasurementVector InputVectorType;
51  typedef TTargetVector OutputVectorType;
52 
53  typedef typename TMeasurementVector::ValueType ValueType;
55  typedef const ValueType* ValueConstPointer;
58 
64 
65  //The only valid layer types
67 
68  virtual void SetNumberOfNodes(unsigned int);
69  unsigned int GetNumberOfNodes() const;
70 
71  virtual ValueType GetInputValue(unsigned int) const = 0;
72  virtual ValueType GetOutputValue(unsigned int) const = 0;
73  virtual ValuePointer GetOutputVector() = 0;
74 
75  virtual void ForwardPropagate(){};
76  virtual void ForwardPropagate(TMeasurementVector){};
77 
78  virtual void BackwardPropagate(){};
80 
81  virtual ValueType GetOutputErrorValue(unsigned int) const = 0;
82  virtual void SetOutputErrorValues(TTargetVector) {};
83 
84  virtual ValueType GetInputErrorValue(unsigned int) const = 0;
85  virtual ValuePointer GetInputErrorVector() = 0;
86  virtual void SetInputErrorValue(ValueType, unsigned int) {};
87 
88  //itkSetObjectMacro(InputWeightSet, WeightSetInterfaceType);
90  itkGetObjectMacro(InputWeightSet, WeightSetInterfaceType);
91  itkGetConstObjectMacro(InputWeightSet, WeightSetInterfaceType);
92 
93  //itkSetObjectMacro(OutputWeightSet, WeightSetInterfaceType);
95  itkGetObjectMacro(OutputWeightSet, WeightSetInterfaceType);
96  itkGetConstObjectMacro(OutputWeightSet, WeightSetInterfaceType);
97 
99  itkGetObjectMacro(NodeInputFunction, InputFunctionInterfaceType);
100  itkGetConstObjectMacro(NodeInputFunction, InputFunctionInterfaceType);
101 
103  itkGetObjectMacro(ActivationFunction, TransferFunctionInterfaceType);
104  itkGetConstObjectMacro(ActivationFunction, TransferFunctionInterfaceType);
105 
106  virtual ValueType Activation(ValueType) = 0;
107  virtual ValueType DActivation(ValueType) = 0;
108 
109  itkSetEnumMacro(LayerTypeCode, LayerTypeCode);
110  itkGetEnumMacro(LayerTypeCode, LayerTypeCode);
111 
112  //#define __USE_OLD_INTERFACE Comment out to ensure that new interface works
113 #ifdef __USE_OLD_INTERFACE
114  void SetLayerType(const LayerTypeCode value) { SetLayerTypeCode(value); }
115  LayerTypeCode GetLayerType(void) { return GetLayerTypeCode(); }
116  //For backwards compatibility
117  void SetLayerType(const unsigned int value)
118  {
119  switch(value)
120  {
121  case 0:
122  SetLayerType(INVALIDLAYER);
123  break;
124  case 1:
125  SetLayerType(INPUTLAYER);
126  break;
127  case 2:
128  SetLayerType(HIDDENLAYER);
129  break;
130  case 3:
131  SetLayerType(OUTPUTLAYER);
132  break;
133  default:
134  //Throw Exception Here
135  break;
136  }
137  }
138 #endif
139  itkSetMacro(LayerId,unsigned int);
140  itkGetConstReferenceMacro(LayerId,unsigned int);
141 
142  //virtual void SetBias(const ValueType) = 0;
143  //virtual const ValueType & GetBias() const = 0;
144 
145 protected:
146  LayerBase();
147  ~LayerBase();
148 
150  virtual void PrintSelf( std::ostream& os, Indent indent ) const;
151 
152  LayerTypeCode m_LayerTypeCode; //input, hidden, output
153  unsigned int m_LayerId;
154  unsigned int m_NumberOfNodes;
155 
158 
161 
162 }; //class layer base
163 
164 } //namespace itk
165 } //namespace statistics
166 
167 #ifndef ITK_MANUAL_INSTANTIATION
168 #include "itkLayerBase.hxx"
169 #endif
170 
171 #endif
172