ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkRBFLayer.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 __itkRBFLayer_h
00019 #define __itkRBFLayer_h
00020 
00021 #include "itkCompletelyConnectedWeightSet.h"
00022 #include "itkLayerBase.h"
00023 #include "itkObject.h"
00024 #include "itkMacro.h"
00025 #include "itkRadialBasisFunctionBase.h"
00026 #include "itkEuclideanDistanceMetric.h"
00027 
00028 namespace itk
00029 {
00030 namespace Statistics
00031 {
00038 template<class TMeasurementVector, class TTargetVector>
00039 class RBFLayer : public LayerBase<TMeasurementVector, TTargetVector>
00040 {
00041 public:
00042   typedef RBFLayer                                     Self;
00043   typedef LayerBase<TMeasurementVector, TTargetVector> Superclass;
00044   typedef SmartPointer<Self>                           Pointer;
00045   typedef SmartPointer<const Self>                     ConstPointer;
00046 
00048   itkTypeMacro(RBFLayer, LayerBase);
00049   itkNewMacro(Self);
00051 
00052   typedef typename Superclass::ValueType          ValueType;
00053   typedef typename Superclass::ValuePointer       ValuePointer;
00054   typedef vnl_vector<ValueType>                   NodeVectorType;
00055   typedef typename Superclass::InternalVectorType InternalVectorType;
00056   typedef typename Superclass::OutputVectorType   OutputVectorType;
00057   typedef typename Superclass::LayerInterfaceType LayerInterfaceType;
00058   typedef CompletelyConnectedWeightSet<TMeasurementVector,TTargetVector>
00059                                                   WeightSetType;
00060 
00061   typedef typename Superclass::WeightSetInterfaceType        WeightSetInterfaceType;
00062   typedef typename Superclass::InputFunctionInterfaceType    InputFunctionInterfaceType;
00063   typedef typename Superclass::TransferFunctionInterfaceType TransferFunctionInterfaceType;
00064 
00065   //Distance Metric
00066   typedef EuclideanDistanceMetric<InternalVectorType> DistanceMetricType;
00067   typedef typename DistanceMetricType::Pointer        DistanceMetricPointer;
00068   typedef RadialBasisFunctionBase<ValueType>          RBFType;
00069 
00070   //Member Functions
00071   itkGetConstReferenceMacro(RBF_Dim, unsigned int);
00072   void SetRBF_Dim(unsigned int size);
00073   virtual void SetNumberOfNodes(unsigned int numNodes);
00074   virtual ValueType GetInputValue(unsigned int i) const;
00075   void SetInputValue(unsigned int i, ValueType value);
00076 
00077   virtual ValueType GetOutputValue(unsigned int) const;
00078   virtual void SetOutputValue(unsigned int, ValueType);
00079 
00080   virtual ValueType * GetOutputVector();
00081   void SetOutputVector(TMeasurementVector value);
00082 
00083   virtual void ForwardPropagate();
00084   virtual void ForwardPropagate(TMeasurementVector input);
00085 
00086   virtual void BackwardPropagate();
00087   virtual void BackwardPropagate(TTargetVector itkNotUsed(errors)){};
00088 
00089   virtual void SetOutputErrorValues(TTargetVector);
00090   virtual ValueType GetOutputErrorValue(unsigned int node_id) const;
00091 
00092   virtual ValueType GetInputErrorValue(unsigned int node_id) const;
00093   virtual ValueType * GetInputErrorVector();
00094   virtual void SetInputErrorValue(ValueType, unsigned int node_id);
00095 
00096   //TMeasurementVector GetCenter(int i);
00097   InternalVectorType GetCenter(unsigned int i) const;
00098   void SetCenter(TMeasurementVector c,unsigned int i);
00099 
00100   ValueType GetRadii(unsigned int i) const;
00101   void SetRadii(ValueType c,unsigned int i);
00102 
00103   virtual ValueType Activation(ValueType);
00104   virtual ValueType DActivation(ValueType);
00105 
00107   itkSetMacro( Bias, ValueType );
00108   itkGetConstReferenceMacro( Bias, ValueType );
00110 
00111   void SetDistanceMetric(DistanceMetricType* f);
00112   itkGetObjectMacro( DistanceMetric, DistanceMetricType );
00113   itkGetConstObjectMacro( DistanceMetric, DistanceMetricType );
00114 
00115   itkSetMacro(NumClasses,unsigned int);
00116   itkGetConstReferenceMacro(NumClasses,unsigned int);
00117 
00118   void SetRBF(RBFType* f);
00119   itkGetObjectMacro(RBF, RBFType);
00120   itkGetConstObjectMacro(RBF, RBFType);
00121 
00122 protected:
00123 
00124   RBFLayer();
00125   virtual ~RBFLayer();
00126 
00128   virtual void PrintSelf( std::ostream& os, Indent indent ) const;
00129 
00130 private:
00131 
00132   NodeVectorType   m_NodeInputValues;
00133   NodeVectorType   m_NodeOutputValues;
00134   NodeVectorType   m_InputErrorValues;
00135   NodeVectorType   m_OutputErrorValues;
00136 
00137   typename DistanceMetricType::Pointer  m_DistanceMetric;
00138 
00139   std::vector<InternalVectorType>       m_Centers;  // ui....uc
00140   InternalVectorType                    m_Radii;
00141   unsigned int                          m_NumClasses;
00142   ValueType                             m_Bias;
00143   unsigned int                          m_RBF_Dim;
00144   typename RBFType::Pointer             m_RBF;
00145 };
00146 
00147 } // end namespace Statistics
00148 } // end namespace itk
00149 
00150 #ifndef ITK_MANUAL_INSTANTIATION
00151 #include "itkRBFLayer.hxx"
00152 #endif
00153 
00154 #endif
00155