ITK  4.6.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<typename TMeasurementVector, typename 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 ITK_OVERRIDE;
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
virtual ValueType Activation(ValueType)=0
Array class with size defined at construction time.
Definition: itkArray.h:50
This is the itkLayerBase class.
Definition: itkLayerBase.h:38
This is the itkWeightSetBase class.
This is the itkTransferFunctionBase class.
TransferFunctionInterfaceType::Pointer m_ActivationFunction
Definition: itkLayerBase.h:154
WeightSetInterfaceType::Pointer m_OutputWeightSet
Definition: itkLayerBase.h:152
virtual void SetNumberOfNodes(unsigned int)
void SetTransferFunction(TransferFunctionInterfaceType *f)
virtual void SetOutputErrorValues(TTargetVector)
Definition: itkLayerBase.h:81
SmartPointer< Self > Pointer
Definition: itkLayerBase.h:43
TTargetVector OutputVectorType
Definition: itkLayerBase.h:50
TMeasurementVector InputVectorType
Definition: itkLayerBase.h:47
unsigned int GetNumberOfNodes() const
virtual ValueType GetInputValue(unsigned int) const =0
virtual ValueType GetInputErrorValue(unsigned int) const =0
This is the itkInputFunctionBase class.
void SetInputWeightSet(WeightSetInterfaceType *)
virtual ValuePointer GetInputErrorVector()=0
TMeasurementVector::ValueType ValueType
Definition: itkLayerBase.h:52
virtual ValueType GetOutputErrorValue(unsigned int) const =0
virtual void BackwardPropagate(InternalVectorType)
Definition: itkLayerBase.h:78
InputFunctionInterfaceType::Pointer m_NodeInputFunction
Definition: itkLayerBase.h:155
virtual void BackwardPropagate()
Definition: itkLayerBase.h:77
LayerTypeCode m_LayerTypeCode
Definition: itkLayerBase.h:147
virtual ValueType GetOutputValue(unsigned int) const =0
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
virtual void ForwardPropagate()
Definition: itkLayerBase.h:74
const ValueType * ValueConstPointer
Definition: itkLayerBase.h:54
SmartPointer< const Self > ConstPointer
Definition: itkLayerBase.h:44
virtual void ForwardPropagate(TMeasurementVector)
Definition: itkLayerBase.h:75
WeightSetBase< TMeasurementVector, TTargetVector > WeightSetType
Definition: itkLayerBase.h:59
void SetNodeInputFunction(InputFunctionInterfaceType *f)
WeightSetInterfaceType::Pointer m_InputWeightSet
Definition: itkLayerBase.h:151
vnl_vector< ValueType > NodeVectorType
Definition: itkLayerBase.h:55
LightProcessObject Superclass
Definition: itkLayerBase.h:42
virtual void SetLayerTypeCode(const LayerTypeCode _arg)
virtual ValueType DActivation(ValueType)=0
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Array< ValueType > InternalVectorType
Definition: itkLayerBase.h:56
InputFunctionBase< ValueType *, ValueType > InputFunctionInterfaceType
Definition: itkLayerBase.h:61
WeightSetBase< TMeasurementVector, TTargetVector > WeightSetInterfaceType
Definition: itkLayerBase.h:60
virtual void SetInputErrorValue(ValueType, unsigned int)
Definition: itkLayerBase.h:85
TransferFunctionBase< ValueType > TransferFunctionInterfaceType
Definition: itkLayerBase.h:62
virtual LayerTypeCode GetLayerTypeCode() const
virtual ValuePointer GetOutputVector()=0
void SetOutputWeightSet(WeightSetInterfaceType *)