Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkLayerBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLayerBase.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-01-24 21:33:49 $
00007   Version:   $Revision: 1.8 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkLayerBase_h
00018 #define __itkLayerBase_h
00019 
00020 #include <iostream>
00021 #include "itkLightProcessObject.h"
00022 #include "itkArray.h"
00023 #include "itkVector.h"
00024 #include "itkTransferFunctionBase.h"
00025 #include "itkInputFunctionBase.h"
00026 
00027 #include "itkWeightSetBase.h"
00028 #include "itkMacro.h"
00029 
00030 namespace itk
00031 {
00032 namespace Statistics
00033 {
00034 
00035 template<class TMeasurementVector, class TTargetVector>
00036 class LayerBase : public LightProcessObject
00037 {
00038 
00039 public:
00040   typedef LayerBase                Self;
00041   typedef LightProcessObject       Superclass;
00042   typedef SmartPointer<Self>       Pointer;
00043   typedef SmartPointer<const Self> ConstPointer;
00044 
00046   itkTypeMacro(LayerBase, LightProcessObject);
00047 
00048   typedef TMeasurementVector InputVectorType;
00049   typedef TTargetVector      OutputVectorType;
00050 
00051   typedef typename TMeasurementVector::ValueType ValueType;
00052   typedef ValueType*                             ValuePointer;
00053   typedef const ValueType*                       ValueConstPointer;
00054   typedef vnl_vector<ValueType>                  NodeVectorType;
00055   typedef Array<ValueType>                       InternalVectorType;
00056 
00057   typedef LayerBase                                       LayerInterfaceType;
00058   typedef WeightSetBase<TMeasurementVector,TTargetVector> WeightSetType;
00059   typedef WeightSetBase<TMeasurementVector,TTargetVector> WeightSetInterfaceType;
00060   typedef InputFunctionBase<ValueType*, ValueType>        InputFunctionInterfaceType;
00061   typedef TransferFunctionBase<ValueType>                 TransferFunctionInterfaceType;
00062 
00063   //The only valid layer types
00064   typedef enum {  INVALIDLAYER=0, INPUTLAYER=1, HIDDENLAYER=2, OUTPUTLAYER=3 } LayerTypeCode;
00065 
00066   virtual void SetNumberOfNodes(unsigned int);
00067   unsigned int GetNumberOfNodes() const;
00068 
00069   virtual ValueType GetInputValue(unsigned int) const = 0;
00070   virtual ValueType GetOutputValue(unsigned int) const = 0;
00071   virtual ValuePointer GetOutputVector() = 0;
00072 
00073   virtual void ForwardPropagate(){};
00074   virtual void ForwardPropagate(TMeasurementVector){};
00075 
00076   virtual void BackwardPropagate(){};
00077   virtual void BackwardPropagate(InternalVectorType){};
00078 
00079   virtual ValueType GetOutputErrorValue(unsigned int) const = 0;
00080   virtual void SetOutputErrorValues(TTargetVector) {};
00081 
00082   virtual ValueType GetInputErrorValue(unsigned int) const = 0;
00083   virtual ValuePointer GetInputErrorVector() = 0;
00084   virtual void SetInputErrorValue(ValueType, unsigned int) {};
00085 
00086   //itkSetObjectMacro(InputWeightSet, WeightSetInterfaceType);
00087   void SetInputWeightSet(WeightSetInterfaceType*);
00088   itkGetObjectMacro(InputWeightSet, WeightSetInterfaceType);
00089   itkGetConstObjectMacro(InputWeightSet, WeightSetInterfaceType);
00090 
00091   //itkSetObjectMacro(OutputWeightSet, WeightSetInterfaceType);
00092   void SetOutputWeightSet(WeightSetInterfaceType*);
00093   itkGetObjectMacro(OutputWeightSet, WeightSetInterfaceType);
00094   itkGetConstObjectMacro(OutputWeightSet, WeightSetInterfaceType);
00095 
00096   void SetNodeInputFunction(InputFunctionInterfaceType* f);
00097   itkGetObjectMacro(NodeInputFunction, InputFunctionInterfaceType);
00098   itkGetConstObjectMacro(NodeInputFunction, InputFunctionInterfaceType);
00099 
00100   void SetTransferFunction(TransferFunctionInterfaceType* f);
00101   itkGetObjectMacro(ActivationFunction, TransferFunctionInterfaceType);
00102   itkGetConstObjectMacro(ActivationFunction, TransferFunctionInterfaceType);
00103 
00104   virtual ValueType Activation(ValueType) = 0;
00105   virtual ValueType DActivation(ValueType) = 0;
00106 
00107   itkSetEnumMacro(LayerTypeCode, LayerTypeCode);
00108   itkGetEnumMacro(LayerTypeCode, LayerTypeCode);
00109 
00110   //#define __USE_OLD_INTERFACE  Comment out to ensure that new interface works
00111 #ifdef __USE_OLD_INTERFACE
00112   void SetLayerType(const LayerTypeCode value) { SetLayerTypeCode(value); }
00113   LayerTypeCode GetLayerType(void) { return GetLayerTypeCode(); }
00114   //For backwards compatibility
00115   void SetLayerType(const unsigned int value)
00116     {
00117     switch(value)
00118       {
00119       case 0:
00120         SetLayerType(INVALIDLAYER);
00121         break;
00122       case 1:
00123         SetLayerType(INPUTLAYER);
00124         break;
00125       case 2:
00126         SetLayerType(HIDDENLAYER);
00127         break;
00128       case 3:
00129         SetLayerType(OUTPUTLAYER);
00130         break;
00131       default:
00132         //Throw Exception Here
00133         break;
00134       }
00135     }
00136 #endif
00137   itkSetMacro(LayerId,unsigned int);
00138   itkGetConstReferenceMacro(LayerId,unsigned int);
00139 
00140   //virtual void SetBias(const ValueType) = 0;
00141   //virtual const ValueType & GetBias() const = 0;
00142 
00143 protected:
00144   LayerBase();
00145   ~LayerBase();
00146 
00148   virtual void PrintSelf( std::ostream& os, Indent indent ) const;
00149 
00150   LayerTypeCode m_LayerTypeCode; //input, hidden, output
00151   unsigned int  m_LayerId;
00152   unsigned int  m_NumberOfNodes;
00153 
00154   typename WeightSetInterfaceType::Pointer m_InputWeightSet;
00155   typename WeightSetInterfaceType::Pointer m_OutputWeightSet;
00156 
00157   typename TransferFunctionInterfaceType::Pointer m_ActivationFunction;
00158   typename InputFunctionInterfaceType::Pointer    m_NodeInputFunction;
00159 
00160 }; //class layer base
00161 
00162 } //namespace itk
00163 } //namespace statistics
00164 
00165 #ifndef ITK_MANUAL_INSTANTIATION
00166 #include "itkLayerBase.txx"
00167 #endif
00168 
00169 #endif
00170 

Generated at Fri Apr 16 18:56:52 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000