ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNeuralNetworkFileReader.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 __itkNeuralNetworkFileReader_h
00019 #define __itkNeuralNetworkFileReader_h
00020 
00021 #include "metaTypes.h"
00022 #include "metaUtils.h"
00023 
00024 #include "itkMultilayerNeuralNetworkBase.h"
00025 
00026 #include "itkBackPropagationLayer.h"
00027 
00028 
00029 #include "itkSumInputFunction.h"
00030 #include "itkProductInputFunction.h"
00031 
00032 #include "itkIdentityTransferFunction.h"
00033 #include "itkLogSigmoidTransferFunction.h"
00034 #include "itkSigmoidTransferFunction.h"
00035 #include "itkTanSigmoidTransferFunction.h"
00036 #include "itkSymmetricSigmoidTransferFunction.h"
00037 
00038 namespace itk
00039 {
00056 template< class TNetwork >
00057 class NeuralNetworkFileReader:public Object
00058 {
00059 public:
00060 
00062   typedef NeuralNetworkFileReader    Self;
00063   typedef Object                     Superclass;
00064   typedef SmartPointer< Self >       Pointer;
00065   typedef SmartPointer< const Self > ConstPointer;
00066 
00068   itkTypeMacro(NeuralNetworkFileReader, Object);
00069 
00071   itkNewMacro(Self);
00072 
00073   typedef typename TNetwork::MeasurementVectorType MeasurementVectorType;
00074   typedef typename TNetwork::TargetVectorType      TargetVectorType;
00075   typedef Statistics::BackPropagationLayer<
00076     MeasurementVectorType, TargetVectorType >           BackPropagationLayerType;
00077   typedef typename BackPropagationLayerType::Pointer BackPropagationLayerPointer;
00078   typedef typename MeasurementVectorType::ValueType  MeasurementVectorValueType;
00079 
00080   typedef typename TNetwork::LayerInterfaceType      LayerInterfaceType;
00081   typedef typename LayerInterfaceType::WeightSetType WeightSetType;
00082   typedef typename WeightSetType::Pointer            WeightSetPointer;
00083 
00084 // typedef typename TNetwork::Pointer                       NetworkPointer;
00085 // typedef typename TNetwork::ConstPointer                  NetworkConstPointer;
00086 
00087 //  typedef typename LayerInterfaceType::TransferFunctionType::Pointer
00088 //      TransferFunctionPointer;
00089 //  typedef typename LayerInterfaceType::TransferFunctionType::ConstPointer
00090 // TransferFunctionConstPointer;
00091 
00092 //  typedef typename LayerInterfaceType::InputFunctionType::Pointer
00093 //         InputFunctionPointer;
00094 //  typedef typename LayerInterfaceType::InputFunctionType::ConstPointer
00095 //    InputFunctionConstPointer;
00096 
00097 //  typedef typename LayerInterfaceType::ValueType                    ValueType;
00098 
00100   itkSetStringMacro(FileName);
00101 
00103   itkGetStringMacro(FileName);
00104 
00106   void Update(void);
00107 
00108   TNetwork * GetOutput() const;
00109 
00110 #ifdef IGNORE
00111 #undef IGNORE
00112 #endif
00113   typedef enum { IGNORE = 0, ASCII = 1, BINARY = 2 } NetworkWriteWeightsType;
00114   itkSetEnumMacro(ReadWeightValuesType, NetworkWriteWeightsType);
00115   itkGetEnumMacro(ReadWeightValuesType, NetworkWriteWeightsType);
00116 protected:
00117   NeuralNetworkFileReader();
00118   ~NeuralNetworkFileReader();
00119   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00120 
00121 private:
00122 
00123   void ClearFields();
00124 
00125   typedef std::vector< MET_FieldRecordType * >                                                  FieldsContainerType;
00126   typedef std::vector< typename TNetwork::LayerInterfaceType::Pointer >                         LayersContainer;
00127   typedef std::vector< typename TNetwork::LayerInterfaceType::WeightSetInterfaceType::Pointer > WeightsContainer;
00128 
00129   typedef struct {
00130     std::string name;
00131     std::string value;
00132   }                                 LineType;
00133 
00134   typedef std::list< LineType > LinesContainer;
00135 
00136   typename TNetwork::Pointer m_Network;
00137 
00138   NetworkWriteWeightsType m_ReadWeightValuesType;
00139   LayersContainer         m_Layers;
00140   WeightsContainer        m_Weights;
00141   LinesContainer          m_NameValue;
00142   std::string             m_FileName;
00143   FieldsContainerType     m_Fields;
00144   std::ifstream           m_InputFile;
00145   bool                    m_BinaryDataByteOrderMSB;
00146 };
00147 } // namespace itk
00148 
00149 #ifndef ITK_MANUAL_INSTANTIATION
00150 #include "itkNeuralNetworkFileReader.hxx"
00151 #endif
00152 
00153 #endif
00154