ITK  4.4.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;
55  typedef vnl_vector<ValueType> NodeVectorType;
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  itkGetModifiableObjectMacro(InputWeightSet, WeightSetInterfaceType);
90 
91  //itkSetObjectMacro(OutputWeightSet, WeightSetInterfaceType);
93  itkGetModifiableObjectMacro(OutputWeightSet, WeightSetInterfaceType);
94 
96  itkGetModifiableObjectMacro(NodeInputFunction, InputFunctionInterfaceType);
97 
99  itkGetModifiableObjectMacro(ActivationFunction, TransferFunctionInterfaceType);
100 
101  virtual ValueType Activation(ValueType) = 0;
102  virtual ValueType DActivation(ValueType) = 0;
103 
104  itkSetEnumMacro(LayerTypeCode, LayerTypeCode);
105  itkGetEnumMacro(LayerTypeCode, LayerTypeCode);
106 
107  //#define __USE_OLD_INTERFACE Comment out to ensure that new interface works
108 #ifdef __USE_OLD_INTERFACE
109  void SetLayerType(const LayerTypeCode value) { SetLayerTypeCode(value); }
110  LayerTypeCode GetLayerType(void) { return GetLayerTypeCode(); }
111  //For backwards compatibility
112  void SetLayerType(const unsigned int value)
113  {
114  switch(value)
115  {
116  case 0:
117  SetLayerType(INVALIDLAYER);
118  break;
119  case 1:
120  SetLayerType(INPUTLAYER);
121  break;
122  case 2:
123  SetLayerType(HIDDENLAYER);
124  break;
125  case 3:
126  SetLayerType(OUTPUTLAYER);
127  break;
128  default:
129  //Throw Exception Here
130  break;
131  }
132  }
133 #endif
134  itkSetMacro(LayerId,unsigned int);
135  itkGetConstReferenceMacro(LayerId,unsigned int);
136 
137  //virtual void SetBias(const ValueType) = 0;
138  //virtual const ValueType & GetBias() const = 0;
139 
140 protected:
141  LayerBase();
142  ~LayerBase();
143 
145  virtual void PrintSelf( std::ostream& os, Indent indent ) const;
146 
147  LayerTypeCode m_LayerTypeCode; //input, hidden, output
148  unsigned int m_LayerId;
149  unsigned int m_NumberOfNodes;
150 
153 
156 
157 }; //class layer base
158 
159 } //namespace itk
160 } //namespace statistics
161 
162 #ifndef ITK_MANUAL_INSTANTIATION
163 #include "itkLayerBase.hxx"
164 #endif
165 
166 #endif
167