ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkTwoHiddenLayerBackPropagationNeuralNetwork.h
Go to the documentation of this file.
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 __itkTwoHiddenLayerBackPropagationNeuralNetwork_h
00019 #define __itkTwoHiddenLayerBackPropagationNeuralNetwork_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 #include "itkProductInputFunction.h"
00032 
00033 namespace itk
00034 {
00035 namespace Statistics
00036 {
00043 template<class TMeasurementVector, class TTargetVector>
00044 class TwoHiddenLayerBackPropagationNeuralNetwork :
00045     public MultilayerNeuralNetworkBase<TMeasurementVector, TTargetVector, BackPropagationLayer<TMeasurementVector, TTargetVector> >
00046 {
00047 public:
00048   typedef TwoHiddenLayerBackPropagationNeuralNetwork 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 TransferFunctionInterfaceType;
00066   typedef typename Superclass::InputFunctionInterfaceType    InputFunctionInterfaceType;
00067 
00069   itkTypeMacro(TwoHiddenLayerBackPropagationNeuralNetwork,
00070                MultilayerNeuralNetworkBase);
00071   itkNewMacro(Self);
00073 
00074   //Add the layers to the network.
00075   // 1 input, 2 hidden, 1 output
00076   void Initialize();
00077 
00078   itkSetMacro(NumOfInputNodes, unsigned int);
00079   itkGetConstReferenceMacro(NumOfInputNodes, unsigned int);
00080 
00081   itkSetMacro(NumOfFirstHiddenNodes, unsigned int);
00082   itkGetConstReferenceMacro(NumOfFirstHiddenNodes, unsigned int);
00083 
00084   itkSetMacro(NumOfSecondHiddenNodes, unsigned int);
00085   itkGetConstReferenceMacro(NumOfSecondHiddenNodes,unsigned int);
00086   //#define __USE_OLD_INTERFACE  Comment out to ensure that new interface works
00087 #ifdef __USE_OLD_INTERFACE
00088   //Original Function name before consistency naming changes
00089   inline void SetNumOfHiddenNodes1(unsigned int x) { SetNumOfFirstHiddenNodes(x); }
00090   inline unsigned int GetNumOfHiddenNodes1(void) const { return GetNumOfFirstHiddenNodes(); }
00091   inline void SetNumOfHiddenNodes2(unsigned int x) { SetNumOfSecondHiddenNodes(x); }
00092   inline unsigned int GetNumOfHiddenNodes2(void) const { return GetNumOfSecondHiddenNodes(); }
00093 #endif
00094 
00095   itkSetMacro(NumOfOutputNodes, unsigned int);
00096   itkGetConstReferenceMacro(NumOfOutputNodes, unsigned int);
00097 
00098   itkSetMacro(FirstHiddenLayerBias, ValueType);
00099   itkGetConstReferenceMacro(FirstHiddenLayerBias, ValueType);
00100 
00101   itkSetMacro(SecondHiddenLayerBias, ValueType);
00102   itkGetConstReferenceMacro(SecondHiddenLayerBias, ValueType);
00103 
00104   itkSetMacro(OutputLayerBias, ValueType);
00105   itkGetConstReferenceMacro(OutputLayerBias, ValueType);
00106 
00107   virtual NetworkOutputType GenerateOutput(TMeasurementVector samplevector);
00108 
00109   void SetInputFunction(InputFunctionInterfaceType* f);
00110   void SetInputTransferFunction(TransferFunctionInterfaceType* f);
00111   void SetFirstHiddenTransferFunction(TransferFunctionInterfaceType* f);
00112   void SetSecondHiddenTransferFunction(TransferFunctionInterfaceType* f);
00113   void SetOutputTransferFunction(TransferFunctionInterfaceType* f);
00114 protected:
00115 
00116   TwoHiddenLayerBackPropagationNeuralNetwork();
00117   virtual ~TwoHiddenLayerBackPropagationNeuralNetwork() {};
00118 
00120   virtual void PrintSelf( std::ostream& os, Indent indent ) const;
00121 
00122 private:
00123 
00124   unsigned int m_NumOfInputNodes;
00125   unsigned int m_NumOfFirstHiddenNodes;
00126   unsigned int m_NumOfSecondHiddenNodes;
00127   unsigned int m_NumOfOutputNodes;
00128 
00129   ValueType m_FirstHiddenLayerBias;
00130   ValueType m_SecondHiddenLayerBias;
00131   ValueType m_OutputLayerBias;
00132 
00133   typename InputFunctionInterfaceType::Pointer    m_InputFunction;
00134   typename TransferFunctionInterfaceType::Pointer m_InputTransferFunction;
00135   typename TransferFunctionInterfaceType::Pointer m_FirstHiddenTransferFunction;
00136   typename TransferFunctionInterfaceType::Pointer m_SecondHiddenTransferFunction;
00137   typename TransferFunctionInterfaceType::Pointer m_OutputTransferFunction;
00138 };
00139 
00140 } // end namespace Statistics
00141 } // end namespace itk
00142 
00143 #ifndef ITK_MANUAL_INSTANTIATION
00144 #include "itkTwoHiddenLayerBackPropagationNeuralNetwork.hxx"
00145 #endif
00146 
00147 #endif
00148