ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkOneHiddenLayerBackPropagationNeuralNetwork_h 00019 #define __itkOneHiddenLayerBackPropagationNeuralNetwork_h 00020 00021 #include "itkMultilayerNeuralNetworkBase.h" 00022 #include "itkBackPropagationLayer.h" 00023 #include "itkSigmoidTransferFunction.h" 00024 #include "itkLogSigmoidTransferFunction.h" 00025 #include "itkTanSigmoidTransferFunction.h" 00026 #include "itkHardLimitTransferFunction.h" 00027 #include "itkSignedHardLimitTransferFunction.h" 00028 #include "itkGaussianTransferFunction.h" 00029 #include "itkIdentityTransferFunction.h" 00030 #include "itkSumInputFunction.h" 00031 00032 00033 namespace itk 00034 { 00035 namespace Statistics 00036 { 00043 template<class TMeasurementVector, class TTargetVector> 00044 class OneHiddenLayerBackPropagationNeuralNetwork : 00045 public MultilayerNeuralNetworkBase<TMeasurementVector, TTargetVector, BackPropagationLayer<TMeasurementVector, TTargetVector> > 00046 { 00047 public: 00048 typedef OneHiddenLayerBackPropagationNeuralNetwork Self; 00049 typedef MultilayerNeuralNetworkBase<TMeasurementVector, TTargetVector, BackPropagationLayer<TMeasurementVector, TTargetVector> > 00050 Superclass; 00051 typedef SmartPointer<Self> Pointer; 00052 typedef SmartPointer<const Self> ConstPointer; 00053 00054 typedef typename Superclass::ValueType ValueType; 00055 typedef typename Superclass::MeasurementVectorType MeasurementVectorType; 00056 typedef typename Superclass::TargetVectorType TargetVectorType; 00057 typedef typename Superclass::NetworkOutputType NetworkOutputType; 00058 00059 typedef typename Superclass::LayerInterfaceType LayerInterfaceType; 00060 typedef typename Superclass::LearningLayerType LearningLayerType; 00061 00062 typedef typename Superclass::WeightVectorType WeightVectorType; 00063 typedef typename Superclass::LayerVectorType LayerVectorType; 00064 00065 typedef typename Superclass::TransferFunctionInterfaceType 00066 TransferFunctionInterfaceType; 00067 typedef typename Superclass::InputFunctionInterfaceType 00068 InputFunctionInterfaceType; 00069 00071 itkTypeMacro(OneHiddenLayerBackPropagationNeuralNetwork, 00072 MultilayerNeuralNetworkBase); 00073 itkNewMacro(Self); 00075 00076 //Add the layers to the network. 00077 // 1 input, 1 hidden, 1 output 00078 void Initialize(); 00079 00080 itkSetMacro(NumOfInputNodes, unsigned int); 00081 itkGetConstReferenceMacro(NumOfInputNodes, unsigned int); 00082 00083 itkSetMacro(NumOfFirstHiddenNodes, unsigned int); 00084 itkGetConstReferenceMacro(NumOfFirstHiddenNodes, unsigned int); 00085 00086 itkSetMacro(NumOfOutputNodes, unsigned int); 00087 itkGetConstReferenceMacro(NumOfOutputNodes, unsigned int); 00088 00089 itkSetMacro(FirstHiddenLayerBias, ValueType); 00090 itkGetConstReferenceMacro(FirstHiddenLayerBias, ValueType); 00091 00092 //#define __USE_OLD_INTERFACE Comment out to ensure that new interface works 00093 #ifdef __USE_OLD_INTERFACE 00094 //Original Function name before consistency naming changes 00095 inline void SetNumOfHiddenNodes(const unsigned int & x) { SetNumOfFirstHiddenNodes(x); } 00096 inline unsigned int GetNumOfHiddenNodes(void) const { return GetNumOfFirstHiddenNodes(); } 00097 inline void SetHiddenLayerBias(const ValueType & bias) { SetFirstHiddenLayerBias(bias); } 00098 ValueType GetHiddenLayerBias(void) const { return GetFirstHiddenLayerBias();} 00099 #endif 00100 itkSetMacro(OutputLayerBias, ValueType); 00101 itkGetConstReferenceMacro(OutputLayerBias, ValueType); 00102 00103 virtual NetworkOutputType GenerateOutput(TMeasurementVector samplevector); 00104 00105 void SetInputFunction(InputFunctionInterfaceType* f); 00106 void SetInputTransferFunction(TransferFunctionInterfaceType* f); 00107 #ifdef __USE_OLD_INTERFACE 00108 //Original Function name before consistency naming changes 00109 inline void SetHiddenTransferFunction(TransferFunctionInterfaceType* f) { SetFirstHiddenTransferFunction (f); } 00110 #endif 00111 void SetFirstHiddenTransferFunction(TransferFunctionInterfaceType* f); 00112 void SetOutputTransferFunction(TransferFunctionInterfaceType* f); 00113 protected: 00114 00115 OneHiddenLayerBackPropagationNeuralNetwork(); 00116 virtual ~OneHiddenLayerBackPropagationNeuralNetwork(){}; 00117 00119 virtual void PrintSelf( std::ostream& os, Indent indent ) const; 00120 00121 private: 00122 00123 unsigned int m_NumOfInputNodes; 00124 unsigned int m_NumOfFirstHiddenNodes; 00125 unsigned int m_NumOfOutputNodes; 00126 00127 ValueType m_FirstHiddenLayerBias; 00128 ValueType m_OutputLayerBias; 00129 00130 typename InputFunctionInterfaceType::Pointer m_InputFunction; 00131 typename TransferFunctionInterfaceType::Pointer m_InputTransferFunction; 00132 typename TransferFunctionInterfaceType::Pointer m_FirstHiddenTransferFunction; 00133 typename TransferFunctionInterfaceType::Pointer m_OutputTransferFunction; 00134 }; 00135 00136 } // end namespace Statistics 00137 } // end namespace itk 00138 00139 #ifndef ITK_MANUAL_INSTANTIATION 00140 #include "itkOneHiddenLayerBackPropagationNeuralNetwork.hxx" 00141 #endif 00142 00143 #endif 00144