From 48532460367ab7b72ae149c7b93b0678cc469cf1 Mon Sep 17 00:00:00 2001 From: Romain Garrigues <romain.garrigues@c-s.fr> Date: Wed, 28 Jun 2006 15:35:15 +0000 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20ITK=20version=202.8.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Utilities/ITK/Code/Numerics/CMakeLists.txt | 9 +- .../ITK/Code/Numerics/FEM/CMakeLists.txt | 7 +- .../itkFEMElement2DC0LinearQuadrilateral.cxx | 6 +- .../Numerics/FEM/itkFEMElement2DC1Beam.cxx | 8 +- .../FEM/itkFEMElement3DC0LinearHexahedron.cxx | 6 +- .../itkFEMElement3DC0LinearTetrahedron.cxx | 6 +- .../Code/Numerics/FEM/itkFEMGenerateMesh.cxx | 14 +-- .../Numerics/FEM/itkFEMImageMetricLoad.txx | 16 +-- ...MLoadImplementationGenericLandmarkLoad.cxx | 6 +- .../FEM/itkFEMSolverCrankNicolson.cxx | 56 ++++----- .../Numerics/FEM/itkFEMSolverCrankNicolson.h | 6 +- .../Numerics/NeuralNetworks/CMakeLists.txt | 2 +- .../NeuralNetworks/itkBackPropagationLayer.h | 8 +- .../itkBackPropagationLayer.txx | 11 +- .../itkBatchSupervisedTrainingFunction.h | 5 +- .../itkBatchSupervisedTrainingFunction.txx | 21 +++- .../itkCompletelyConnectedWeightSet.txx | 8 +- .../NeuralNetworks/itkErrorFunctionBase.h | 11 +- .../itkGaussianRadialBasisFunction.txx | 12 +- .../itkIterativeSupervisedTrainingFunction.h | 5 +- ...itkIterativeSupervisedTrainingFunction.txx | 17 ++- .../Numerics/NeuralNetworks/itkLayerBase.h | 22 +++- .../Numerics/NeuralNetworks/itkLayerBase.txx | 24 +++- .../itkLogSigmoidTransferFunction.txx | 6 +- .../itkMeanSquaredErrorFunction.h | 7 +- .../itkMeanSquaredErrorFunction.txx | 21 +++- .../itkMultilayerNeuralNetworkBase.h | 21 ++-- .../itkMultilayerNeuralNetworkBase.txx | 36 +++++- .../itkMultiquadricRadialBasisFunction.txx | 6 +- .../NeuralNetworks/itkNeuralNetworkObject.h | 14 ++- ...eHiddenLayerBackPropagationNeuralNetwork.h | 10 +- ...iddenLayerBackPropagationNeuralNetwork.txx | 6 +- .../itkRBFBackPropagationLearningFunction.txx | 6 +- .../Numerics/NeuralNetworks/itkRBFLayer.h | 31 +++-- .../Numerics/NeuralNetworks/itkRBFLayer.txx | 78 ++++++++---- .../Numerics/NeuralNetworks/itkRBFNetwork.h | 17 ++- .../Numerics/NeuralNetworks/itkRBFNetwork.txx | 34 +++++- .../itkSigmoidTransferFunction.txx | 6 +- .../itkSquaredDifferenceErrorFunction.h | 7 +- .../itkSquaredDifferenceErrorFunction.txx | 20 +++- .../itkSymmetricSigmoidTransferFunction.txx | 6 +- .../itkTanHTransferFunction.txx | 10 +- .../itkTanSigmoidTransferFunction.txx | 6 +- .../NeuralNetworks/itkTrainingFunctionBase.h | 13 +- .../itkTrainingFunctionBase.txx | 11 +- ...oHiddenLayerBackPropagationNeuralNetwork.h | 9 +- ...iddenLayerBackPropagationNeuralNetwork.txx | 6 +- .../NeuralNetworks/itkWeightSetBase.h | 30 +++-- .../NeuralNetworks/itkWeightSetBase.txx | 25 ++-- .../Code/Numerics/Statistics/CMakeLists.txt | 7 +- .../Statistics/itkEuclideanDistance.txx | 10 +- ...ationMaximizationMixtureModelEstimator.txx | 8 +- .../Statistics/itkGaussianDensityFunction.txx | 8 +- .../itkGaussianGoodnessOfFitComponent.txx | 8 +- .../itkGaussianMixtureModelComponent.txx | 10 +- .../itkGoodnessOfFitFunctionBase.txx | 6 +- .../Code/Numerics/Statistics/itkHistogram.txx | 113 +++++------------- .../itkHistogramToEntropyImageFilter.h | 8 +- .../itkHistogramToLogProbabilityImageFilter.h | 8 +- .../itkListSampleToHistogramGenerator.h | 11 +- .../itkLogLikelihoodGoodnessOfFitFunction.txx | 6 +- .../Statistics/itkNormalVariateGenerator.cxx | 18 +-- .../itkSampleToHistogramProjectionFilter.txx | 14 +-- .../itkScalarImageToHistogramGenerator.h | 12 +- .../itkScalarImageToHistogramGenerator.txx | 28 ++++- .../itkCumulativeGaussianCostFunction.cxx | 10 +- .../itkCumulativeGaussianOptimizer.cxx | 16 +-- .../ITK/Code/Numerics/itkFRPROptimizer.cxx | 67 ++++++++--- .../ITK/Code/Numerics/itkFRPROptimizer.h | 22 +++- ...itkMultipleValuedNonLinearVnlOptimizer.cxx | 47 +++++++- .../itkMultipleValuedNonLinearVnlOptimizer.h | 32 ++++- ...tkMultipleValuedVnlCostFunctionAdaptor.cxx | 69 ++++++++++- .../itkMultipleValuedVnlCostFunctionAdaptor.h | 30 ++++- .../itkOnePlusOneEvolutionaryOptimizer.cxx | 8 +- .../ITK/Code/Numerics/itkSPSAOptimizer.cxx | 8 +- .../ITK/Code/Numerics/itkSPSAOptimizer.h | 4 + .../itkSingleValuedNonLinearVnlOptimizer.cxx | 7 +- .../itkSingleValuedVnlCostFunctionAdaptor.cxx | 9 +- 78 files changed, 872 insertions(+), 460 deletions(-) diff --git a/Utilities/ITK/Code/Numerics/CMakeLists.txt b/Utilities/ITK/Code/Numerics/CMakeLists.txt index f0c12e6cf7..a56fbeb696 100644 --- a/Utilities/ITK/Code/Numerics/CMakeLists.txt +++ b/Utilities/ITK/Code/Numerics/CMakeLists.txt @@ -33,7 +33,10 @@ ADD_LIBRARY(ITKNumerics lbfgsb.c ) -TARGET_LINK_LIBRARIES (ITKNumerics ITKCommon) +TARGET_LINK_LIBRARIES(ITKNumerics ITKCommon) -INSTALL_TARGETS(/lib/otb ITKNumerics) -INSTALL_FILES(/include/otb/Utilities/ITK/Numerics "(\\.h|\\.txx)$") +IF(ITK_LIBRARY_PROPERTIES) + SET_TARGET_PROPERTIES(ITKNumerics PROPERTIES ${ITK_LIBRARY_PROPERTIES}) +ENDIF(ITK_LIBRARY_PROPERTIES) +INSTALL_TARGETS(/lib/InsightToolkit ITKNumerics) +INSTALL_FILES(/include/InsightToolkit/Numerics "(\\.h|\\.txx)$") diff --git a/Utilities/ITK/Code/Numerics/FEM/CMakeLists.txt b/Utilities/ITK/Code/Numerics/FEM/CMakeLists.txt index 20da66f0ea..e7da0a3797 100644 --- a/Utilities/ITK/Code/Numerics/FEM/CMakeLists.txt +++ b/Utilities/ITK/Code/Numerics/FEM/CMakeLists.txt @@ -188,5 +188,8 @@ IF(UNIX) TARGET_LINK_LIBRARIES (ITKFEM -lm ) ENDIF(UNIX) -INSTALL_TARGETS(/lib/otb ITKFEM) -INSTALL_FILES(/include/otb/Utilities/ITK/Numerics/FEM "(\\.h|\\.txx)$") +IF(ITK_LIBRARY_PROPERTIES) + SET_TARGET_PROPERTIES(ITKFEM PROPERTIES ${ITK_LIBRARY_PROPERTIES}) +ENDIF(ITK_LIBRARY_PROPERTIES) +INSTALL_TARGETS(/lib/InsightToolkit ITKFEM) +INSTALL_FILES(/include/InsightToolkit/Numerics/FEM "(\\.h|\\.txx)$") diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC0LinearQuadrilateral.cxx b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC0LinearQuadrilateral.cxx index 7b98e732d4..67fbfbbe57 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC0LinearQuadrilateral.cxx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC0LinearQuadrilateral.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMElement2DC0LinearQuadrilateral.cxx,v $ Language: C++ - Date: $Date: 2003/12/15 14:13:20 $ - Version: $Revision: 1.10 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.11 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -173,7 +173,7 @@ Element2DC0LinearQuadrilateral cn = (dx * ycn) - (dy * xcn); localPt[0] = (2 * ce) / (-sqrt((be * be) - (2 * J1 * ce)) - be); - localPt[1] = (2 * cn) / ( sqrt((bn * bn) + (2 * J2 * cn)) - bn); + localPt[1] = (2 * cn) / ( vcl_sqrt((bn * bn) + (2 * J2 * cn)) - bn); bool isInside=true; diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC1Beam.cxx b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC1Beam.cxx index 615c4c8e66..7537699900 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC1Beam.cxx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement2DC1Beam.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMElement2DC1Beam.cxx,v $ Language: C++ - Date: $Date: 2004/12/04 13:17:08 $ - Version: $Revision: 1.8 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.9 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -148,7 +148,7 @@ MatrixType kb(NDOF,NDOF); Float x=m_node[1]->GetCoordinates()[0]-m_node[0]->GetCoordinates()[0]; Float y=m_node[1]->GetCoordinates()[1]-m_node[0]->GetCoordinates()[1]; -Float l=sqrt(x*x+y*y); +Float l=vcl_sqrt(x*x+y*y); k[0][0]= 1; k[0][1]= 0; k[0][2]= 0; k[0][3]=-1; k[0][4]= 0; k[0][5]= 0; k[1][0]= 0; k[1][1]= 0; k[1][2]= 0; k[1][3]= 0; k[1][4]= 0; k[1][5]= 0; @@ -197,7 +197,7 @@ MatrixType k(NDOF,NDOF,0.0); Float x=m_node[1]->GetCoordinates()[0]-m_node[0]->GetCoordinates()[0]; Float y=m_node[1]->GetCoordinates()[1]-m_node[0]->GetCoordinates()[1]; -Float l=sqrt(x*x+y*y); +Float l=vcl_sqrt(x*x+y*y); m[0][0]=2.0; m[0][3]=1.0; m[3][0]=1.0; m[3][3]=2.0; diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearHexahedron.cxx b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearHexahedron.cxx index da7b228983..7395ea72cf 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearHexahedron.cxx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearHexahedron.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMElement3DC0LinearHexahedron.cxx,v $ Language: C++ - Date: $Date: 2003/12/15 14:13:20 $ - Version: $Revision: 1.6 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.7 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -234,7 +234,7 @@ Element3DC0LinearHexahedron // cn = (dx * ycn) - (dy * xcn); // localPt[0] = (2 * ce) / (-sqrt((be * be) - (2 * J1 * ce)) - be); -// localPt[1] = (2 * cn) / ( sqrt((bn * bn) + (2 * J2 * cn)) - bn); +// localPt[1] = (2 * cn) / ( vcl_sqrt((bn * bn) + (2 * J2 * cn)) - bn); // FIXME bool IsInside=false; diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearTetrahedron.cxx b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearTetrahedron.cxx index 75b3a628f2..82c5f90151 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearTetrahedron.cxx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMElement3DC0LinearTetrahedron.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMElement3DC0LinearTetrahedron.cxx,v $ Language: C++ - Date: $Date: 2004/07/22 15:52:10 $ - Version: $Revision: 1.7 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.8 $ Copyright (c) 2002 Insight Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -36,7 +36,7 @@ Element3DC0LinearTetrahedron // FIXME: Write rules for other integration orders pt.set_size(3); - Float d = 1.0/sqrt(3.0); + Float d = 1.0/vcl_sqrt(3.0); pt[0] = d; pt[1] = d; diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMGenerateMesh.cxx b/Utilities/ITK/Code/Numerics/FEM/itkFEMGenerateMesh.cxx index 77204a72f0..cb19b57a49 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMGenerateMesh.cxx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMGenerateMesh.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMGenerateMesh.cxx,v $ Language: C++ - Date: $Date: 2003/09/10 14:29:41 $ - Version: $Revision: 1.7 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.8 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -44,8 +44,8 @@ void Generate2DRectilinearMesh(itk::fem::Element::ConstPointer e0, Solver& S, vn S.node.clear(); // Number of nodes in each dimension - Nel[0]=floor(Nel[0]); - Nel[1]=floor(Nel[1]); + Nel[0]=vcl_floor(Nel[0]); + Nel[1]=vcl_floor(Nel[1]); double Ni=static_cast<double>(Nel[0]); double Nj=static_cast<double>(Nel[1]); @@ -101,9 +101,9 @@ void Generate3DRectilinearMesh } // Number of nodes in each dimension - Nel[0]=floor(Nel[0]); - Nel[1]=floor(Nel[1]); - Nel[2]=floor(Nel[2]); + Nel[0]=vcl_floor(Nel[0]); + Nel[1]=vcl_floor(Nel[1]); + Nel[2]=vcl_floor(Nel[2]); double Ni=static_cast<double>(Nel[0]); double Nj=static_cast<double>(Nel[1]); double Nk=static_cast<double>(Nel[2]); diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMImageMetricLoad.txx b/Utilities/ITK/Code/Numerics/FEM/itkFEMImageMetricLoad.txx index fe228c496c..fedd1908fe 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMImageMetricLoad.txx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMImageMetricLoad.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit (ITK) Module: $RCSfile: itkFEMImageMetricLoad.txx,v $ Language: C++ - Date: $Date: 2003/12/15 14:13:20 $ - Version: $Revision: 1.30 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.31 $ =========================================================================*/ #ifndef _itkFEMImageMetricLoad_txx_ @@ -146,7 +146,7 @@ ImageMetricLoad<TMoving , TFixed>::EvaluateMetricGivenSolution( Element::ArrayTy float tempe=0.0; try { - tempe=fabs(GetMetric(InVec)); + tempe=vcl_fabs(GetMetric(InVec)); } catch( itk::ExceptionObject & ) { @@ -164,7 +164,7 @@ ImageMetricLoad<TMoving , TFixed>::EvaluateMetricGivenSolution( Element::ArrayTy } //std::cout << " def e " << defe << " sim e " << energy*m_Gamma << std::endl; - return fabs((double)energy*(double)m_Gamma-(double)defe); + return vcl_fabs((double)energy*(double)m_Gamma-(double)defe); } @@ -192,7 +192,7 @@ ImageMetricLoad<TMoving , TFixed>::Fe for( unsigned int k = 0; k < ImageDimension; k++ ) { if ( vnl_math_isnan(Gpos[k]) || vnl_math_isinf(Gpos[k]) || vnl_math_isnan(Gsol[k]) || vnl_math_isinf(Gsol[k]) || - fabs(Gpos[k]) > 1.e33 || fabs(Gsol[k]) > 1.e33 ) + vcl_fabs(Gpos[k]) > 1.e33 || vcl_fabs(Gsol[k]) > 1.e33 ) { OutVec.set_size(ImageDimension); OutVec.fill(0.0); return OutVec; } @@ -201,7 +201,7 @@ ImageMetricLoad<TMoving , TFixed>::Fe // OutVec=this->GetPolynomialFitToMetric(Gpos,Gsol); // gradient direction // for( unsigned int k = 0; k < ImageDimension; k++ ) { // if ( vnl_math_isnan(OutVec[k]) || vnl_math_isinf(OutVec[k]) -// || fabs(OutVec[k]) > 1.e33 ) OutVec[k]=0.0; +// || vcl_fabs(OutVec[k]) > 1.e33 ) OutVec[k]=0.0; // else OutVec[k]=m_Sign*OutVec[k]; // } // return OutVec; @@ -270,9 +270,9 @@ ImageMetricLoad<TMoving , TFixed>::Fe // IN FACT, IT SEEMS MEANSQRS AND NCC POINT IN DIFFT DIRS //std::cout << " deriv " << derivative << " val " << measure << endl; //if (m_Temp !=0.0) - //return OutVec * exp(-1.*OutVec.magnitude()/m_Temp); + //return OutVec * vcl_exp(-1.*OutVec.magnitude()/m_Temp); //else - return OutVec/sqrt(gmag); + return OutVec/vcl_sqrt(gmag); } diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMLoadImplementationGenericLandmarkLoad.cxx b/Utilities/ITK/Code/Numerics/FEM/itkFEMLoadImplementationGenericLandmarkLoad.cxx index 18ff538e33..ee2ab356c8 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMLoadImplementationGenericLandmarkLoad.cxx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMLoadImplementationGenericLandmarkLoad.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMLoadImplementationGenericLandmarkLoad.cxx,v $ Language: C++ - Date: $Date: 2003/12/15 14:13:20 $ - Version: $Revision: 1.8 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.9 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -64,7 +64,7 @@ LoadImplementationGenericLandmarkLoad force = (load->m_target-new_source) / load->eta ; // std::cout << " disp " << disp << std::endl; - //force /= sqrt(fmag); + //force /= vcl_sqrt(fmag); new_source = (load->GetTarget() - new_source); // std::cout << " force = " << force << " distance " << new_source.magnitude() << std::endl; diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.cxx b/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.cxx index 14f1197a8f..76510b89d2 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.cxx +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMSolverCrankNicolson.cxx,v $ Language: C++ - Date: $Date: 2005/11/17 22:07:13 $ - Version: $Revision: 1.37 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.38 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -269,8 +269,8 @@ void SolverCrankNicolson::FindBracketingTriplet(Float* a, Float* b, Float* c) Float ax, bx,cx; ax=0.0; bx=1.; Float fc; - Float fa=fabs(EvaluateResidual(ax)); - Float fb=fabs(EvaluateResidual(bx)); + Float fa=vcl_fabs(EvaluateResidual(ax)); + Float fb=vcl_fabs(EvaluateResidual(bx)); Float ulim,u,r,q,fu,dum; @@ -281,10 +281,10 @@ void SolverCrankNicolson::FindBracketingTriplet(Float* a, Float* b, Float* c) } cx=bx+Gold*(bx-ax); // first guess for c - the 3rd pt needed to bracket the min - fc=fabs(EvaluateResidual(cx)); + fc=vcl_fabs(EvaluateResidual(cx)); - while (fb > fc /*&& fabs(ax) < 3. && fabs(bx) < 3. && fabs(cx) < 3.*/) + while (fb > fc /*&& vcl_fabs(ax) < 3. && vcl_fabs(bx) < 3. && vcl_fabs(cx) < 3.*/) { r=(bx-ax)*(fb-fc); q=(bx-cx)*(fb-fa); @@ -293,7 +293,7 @@ void SolverCrankNicolson::FindBracketingTriplet(Float* a, Float* b, Float* c) ulim=bx + Glimit*(cx-bx); if ((bx-u)*(u-cx) > 0.0) { - fu=fabs(EvaluateResidual(u)); + fu=vcl_fabs(EvaluateResidual(u)); if (fu < fc) { ax=bx; @@ -309,28 +309,28 @@ void SolverCrankNicolson::FindBracketingTriplet(Float* a, Float* b, Float* c) } u=cx+Gold*(cx-bx); - fu=fabs(EvaluateResidual(u)); + fu=vcl_fabs(EvaluateResidual(u)); } else if ( (cx-u)*(u-ulim) > 0.0) { - fu=fabs(EvaluateResidual(u)); + fu=vcl_fabs(EvaluateResidual(u)); if (fu < fc) { bx=cx; cx=u; u=cx+Gold*(cx-bx); - fb=fc; fc=fu; fu=fabs(EvaluateResidual(u)); + fb=fc; fc=fu; fu=vcl_fabs(EvaluateResidual(u)); } } else if ( (u-ulim)*(ulim-cx) >= 0.0) { u=ulim; - fu=fabs(EvaluateResidual(u)); + fu=vcl_fabs(EvaluateResidual(u)); } else { u=cx+Gold*(cx-bx); - fu=fabs(EvaluateResidual(u)); + fu=vcl_fabs(EvaluateResidual(u)); } ax=bx; bx=cx; cx=u; @@ -338,7 +338,7 @@ void SolverCrankNicolson::FindBracketingTriplet(Float* a, Float* b, Float* c) } - if ( fabs(ax) > 1.e3 || fabs(bx) > 1.e3 || fabs(cx) > 1.e3) + if ( vcl_fabs(ax) > 1.e3 || vcl_fabs(bx) > 1.e3 || vcl_fabs(cx) > 1.e3) { ax=-2.0; bx=1.0; cx=2.0; } // to avoid crazy numbers caused by bad bracket (u goes nuts) *a=ax; *b=bx; *c=cx; @@ -368,12 +368,12 @@ Element::Float SolverCrankNicolson::BrentsMethod(Float tol,unsigned int MaxIters b=((ax > cx) ? ax : cx); x=w=v=bx; - fw=fv=fx=fabs(EvaluateResidual(x)); + fw=fv=fx=vcl_fabs(EvaluateResidual(x)); for (iter = 1; iter <=MaxIters; iter++) { xm=0.5*(a+b); - tol2=2.0*(tol1=tol*fabs(x)+ZEPS); + tol2=2.0*(tol1=tol*vcl_fabs(x)+ZEPS); if (fabs(x-xm) <= (tol2-0.5*(b-a))) { xmin=x; @@ -387,10 +387,10 @@ Element::Float SolverCrankNicolson::BrentsMethod(Float tol,unsigned int MaxIters p=(x-v)*q-(x-w)*r; q=2.0*(q-r); if (q>0.0) p = -1.*p; - q=fabs(q); + q=vcl_fabs(q); etemp=e; e=d; - if (fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) + if (fabs(p) >= vcl_fabs(0.5*q*etemp) || p <= q*(a-x) || p >= q*(b-x)) d=CGOLD*(e=(x>=xm ? a-x : b-x)); else{ if (q == 0.0) q=q +ZEPS; @@ -403,7 +403,7 @@ Element::Float SolverCrankNicolson::BrentsMethod(Float tol,unsigned int MaxIters } u=(fabs(d) >= tol1 ? x+d : x + GSSign(tol1,d)); - fu=fabs(EvaluateResidual(u)); + fu=vcl_fabs(EvaluateResidual(u)); if (fu <= fx){ if ( u >= x ) a=x; else b=x; v=w; w=x;x=u; @@ -446,25 +446,25 @@ Element::Float SolverCrankNicolson::GoldenSection(Float tol,unsigned int MaxIter x0=ax; x3=cx; - if (fabs(cx-bx) > fabs(bx-ax)){ + if (fabs(cx-bx) > vcl_fabs(bx-ax)){ x1=bx; x2=bx+C*(cx-bx); } else { x2=bx; x1=bx-C*(bx-ax); } - f1=fabs(EvaluateResidual(x1)); - f2=fabs(EvaluateResidual(x2)); + f1=vcl_fabs(EvaluateResidual(x1)); + f2=vcl_fabs(EvaluateResidual(x2)); unsigned int iters=0; - while (fabs(x3-x0) > tol*(fabs(x1)+fabs(x2)) && iters < MaxIters) + while (fabs(x3-x0) > tol*(fabs(x1)+vcl_fabs(x2)) && iters < MaxIters) { iters++; if (f2 < f1){ x0=x1; x1=x2; x2=R*x1+C*x3; - f1=f2; f2=fabs(EvaluateResidual(x2)); + f1=f2; f2=vcl_fabs(EvaluateResidual(x2)); } else { x3=x2; x2=x1; x1=R*x2+C*x0; - f2=f1; f1=fabs(EvaluateResidual(x1)); + f2=f1; f1=vcl_fabs(EvaluateResidual(x1)); } } if (f1<f2){ @@ -581,7 +581,7 @@ Element::Float SolverCrankNicolson::EvaluateResidual(Float t) } DeformationEnergy+=iSolVal*TempRowVal; } - Float Energy=(Float) fabs(DeformationEnergy-ForceEnergy); + Float Energy=(Float) vcl_fabs(DeformationEnergy-ForceEnergy); return Energy; } @@ -610,7 +610,7 @@ void SolverCrankNicolson::AddToDisplacements(Float optimum) else if (CurrentSolution > maxs2 ) { maxs2=CurrentSolution; } - if (fabs(CurrentSolution) > absmax) absmax=fabs(CurrentSolution); + if (fabs(CurrentSolution) > absmax) absmax=vcl_fabs(CurrentSolution); // note: set rather than add - i.e. last solution of system not total solution #ifdef LOCE @@ -634,8 +634,8 @@ void SolverCrankNicolson::AddToDisplacements(Float optimum) m_ls->AddVectorValue(i , CurrentForce, ForceTotalIndex); CurrentTotSolution=m_ls->GetSolutionValue(i,TotalSolutionIndex); - if ( fabs(CurrentTotSolution) > maxs ) { - maxs=fabs(CurrentTotSolution); + if ( vcl_fabs(CurrentTotSolution) > maxs ) { + maxs=vcl_fabs(CurrentTotSolution); } diff --git a/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.h b/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.h index e06e1fc7c5..ec3aee735d 100644 --- a/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.h +++ b/Utilities/ITK/Code/Numerics/FEM/itkFEMSolverCrankNicolson.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFEMSolverCrankNicolson.h,v $ Language: C++ - Date: $Date: 2003/09/10 14:29:44 $ - Version: $Revision: 1.17 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.18 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -122,7 +122,7 @@ public: Float BrentsMethod(Float tol=0.01,unsigned int MaxIters=25); Float EvaluateResidual(Float t=1.0); Float GetDeformationEnergy(Float t=1.0); - inline Float GSSign(Float a,Float b) { return (b > 0.0 ? fabs(a) : -1.*fabs(a)); } + inline Float GSSign(Float a,Float b) { return (b > 0.0 ? vcl_fabs(a) : -1.*vcl_fabs(a)); } inline Float GSMax(Float a,Float b) { return (a > b ? a : b); } void SetEnergyToMin(Float xmin); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/CMakeLists.txt b/Utilities/ITK/Code/Numerics/NeuralNetworks/CMakeLists.txt index 00b40cc77d..3230606db2 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/CMakeLists.txt +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/CMakeLists.txt @@ -1 +1 @@ -INSTALL_FILES(/include/otb/Utilities/ITK/Numerics/NeuralNetworks "(\\.h|\\.txx)$") +INSTALL_FILES(/include/InsightToolkit/Numerics/NeuralNetworks "(\\.h|\\.txx)$") diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.h index 9d6c825f84..327ab56037 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkBackPropagationLayer.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 21:34:31 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -41,7 +41,7 @@ public: typedef typename Superclass::ValueType ValueType; typedef typename Superclass::ValuePointer ValuePointer; typedef vnl_vector<ValueType> NodeVectorType; - + typedef typename Superclass::InternalVectorType InternalVectorType; typedef typename Superclass::OutputVectorType OutputVectorType; //Member Functions @@ -58,7 +58,7 @@ public: void ForwardPropagate(); void ForwardPropagate(TVector); - void BackwardPropagate(TOutput e); + void BackwardPropagate(InternalVectorType e); void BackwardPropagate(); void SetOutputErrorValues(TOutput); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.txx index ceeab19507..cf9511d020 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBackPropagationLayer.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkBackPropagationLayer.txx,v $ Language: C++ - Date: $Date: 2005/08/09 20:27:15 $ - Version: $Revision: 1.4 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.5 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -210,7 +210,7 @@ BackPropagationLayer<TVector,TOutput> template<class TVector, class TOutput> void BackPropagationLayer<TVector,TOutput> -::BackwardPropagate(TOutput errors) +::BackwardPropagate(InternalVectorType errors) { int num_nodes = this->GetNumberOfNodes(); typename Superclass::WeightSetType::Pointer inputweightset; @@ -253,7 +253,10 @@ void BackPropagationLayer<TVector,TOutput> ::SetOutputErrorValues(TOutput errors) { - m_OutputErrorValues = errors.GetVnlVector(); + for(unsigned int i=0; i<errors.Size(); i++) + m_OutputErrorValues[i] = errors[i]; + + //m_OutputErrorValues = errors.GetVnlVector(); this->Modified(); } diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.h index a80e3a498e..d0541a17de 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkBatchSupervisedTrainingFunction.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/18 11:23:29 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -41,6 +41,7 @@ public: itkNewMacro(Self); typedef typename Superclass::NetworkType NetworkType; + typedef typename Superclass::InternalVectorType InternalVectorType; /** Set the number of iterations */ void SetNumOfIterations(long i); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.txx index 7e21621493..2bbf27a2cd 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkBatchSupervisedTrainingFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkBatchSupervisedTrainingFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/03 12:06:12 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -50,10 +50,16 @@ void BatchSupervisedTrainingFunction<TSample,TOutput,ScalarType> { this->SetTrainingSamples(samples); this->SetTargetValues(targets); - typename Superclass::OutputVectorType outputvector; + + InternalVectorType outputvector; + InternalVectorType errorvector; + outputvector.SetSize(targets->GetMeasurementVectorSize()); + errorvector.SetSize(targets->GetMeasurementVectorSize()); + std::cout<<"Target dim ="<<targets->GetMeasurementVectorSize()<<std::endl; + //typename Superclass::OutputVectorType outputvector; typename Superclass::VectorType inputvector; typename Superclass::OutputVectorType targetvector; - typename Superclass::OutputVectorType errorvector; + //typename Superclass::OutputVectorType errorvector; long num_iterations = this->GetIterations(); m_Stop = false; @@ -67,8 +73,11 @@ void BatchSupervisedTrainingFunction<TSample,TOutput,ScalarType> { inputvector = this->m_InputSamples[i]; targetvector = this->m_Targets[i]; - outputvector = net->GenerateOutput(inputvector); - errorvector = targetvector - outputvector; + + outputvector=net->GenerateOutput(inputvector); + + for(unsigned int k=0; k<targetvector.Size(); k++) + errorvector[k] = targetvector[k] - outputvector[k]; outf << this->m_PerformanceFunction->Evaluate(errorvector) << " "<<errorvector[0]<<std::endl; diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkCompletelyConnectedWeightSet.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkCompletelyConnectedWeightSet.txx index 433342db65..14df086197 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkCompletelyConnectedWeightSet.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkCompletelyConnectedWeightSet.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkCompletelyConnectedWeightSet.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:35:36 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -37,8 +37,8 @@ CompletelyConnectedWeightSet<TVector,TOutput> ::SetCompleteConnectivity() { vnl_matrix<int> c; - unsigned int rows = WeightSetBase<TVector, TOutput>::GetNumberOfInputNodes(); - unsigned int cols = WeightSetBase<TVector, TOutput>::GetNumberOfOutputNodes(); + unsigned int rows = WeightSetBase<TVector, TOutput>::GetNumberOfOutputNodes(); + unsigned int cols = WeightSetBase<TVector, TOutput>::GetNumberOfInputNodes(); std::cout << "Connectivity matrix size= " << rows << " " << cols << std::endl; c.set_size(rows, cols); c.fill(1); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkErrorFunctionBase.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkErrorFunctionBase.h index 0f3c4c31e6..2580f2d76c 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkErrorFunctionBase.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkErrorFunctionBase.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkErrorFunctionBase.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -44,10 +44,13 @@ public: /** Output type */ typedef TOutput OutputType; - virtual OutputType Evaluate(const ErrorVectorType&) const = 0; + typedef Array<double> InternalVectorType; - virtual ErrorVectorType EvaluateDerivative(const ErrorVectorType&) const = 0; + virtual OutputType Evaluate(const ErrorVectorType&) const = 0; + //virtual ErrorVectorType EvaluateDerivative(const ErrorVectorType&) const = 0; + virtual InternalVectorType EvaluateDerivative(const ErrorVectorType&) const = 0; + protected: ErrorFunctionBase(){}; diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkGaussianRadialBasisFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkGaussianRadialBasisFunction.txx index 74c6177426..db6185b507 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkGaussianRadialBasisFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkGaussianRadialBasisFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkGaussianRadialBasisFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/03 15:47:06 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/04/18 11:23:29 $ + Version: $Revision: 1.4 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -49,7 +49,7 @@ GaussianRadialBasisFunction< ScalarType> { ScalarType val; ScalarType radius = Superclass::GetRadius(); - val = exp(-0.5*pow(input,2)/pow(radius,2)); + val = vcl_exp(-0.5*vcl_pow(input,2)/vcl_pow(radius,2)); return val; } @@ -60,18 +60,18 @@ GaussianRadialBasisFunction< ScalarType> ::EvaluateDerivative(const ScalarType& dist,const ArrayType& input, char mode,int element_id) const { - ScalarType val; + ScalarType val = 0;; ScalarType radius=Superclass::GetRadius(); ArrayType center = Superclass::GetCenter(); if(mode=='u') //w.r.t centers { - ScalarType temp1= pow(radius,2); + ScalarType temp1= vcl_pow(radius,2); val=Evaluate(dist) *(input.GetElement(element_id)-center.GetElement(element_id))/temp1; } else if(mode=='s') // w.r.t radius { - val=Evaluate(dist)*pow(dist,2)/pow(radius,3); + val=Evaluate(dist)*vcl_pow(dist,2)/vcl_pow(radius,3); } return val; } diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.h index 52f3c368d1..200067c988 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkIterativeSupervisedTrainingFunction.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/18 11:23:29 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -43,6 +43,7 @@ public: itkNewMacro(Self); typedef typename Superclass::NetworkType NetworkType; + typedef typename Superclass::InternalVectorType InternalVectorType; void SetNumOfIterations(long i); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.txx index c151e92884..2d98aadfde 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkIterativeSupervisedTrainingFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkIterativeSupervisedTrainingFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -50,10 +50,16 @@ void IterativeSupervisedTrainingFunction<TSample,TOutput,ScalarType> { this->SetTrainingSamples(samples); this->SetTargetValues(targets); - typename Superclass::OutputVectorType outputvector; + + InternalVectorType outputvector; + InternalVectorType errorvector; + outputvector.SetSize(targets->GetMeasurementVectorSize()); + errorvector.SetSize(targets->GetMeasurementVectorSize()); + + //typename Superclass::OutputVectorType outputvector; typename Superclass::VectorType inputvector; typename Superclass::OutputVectorType targetvector; - typename Superclass::OutputVectorType errorvector; + //typename Superclass::OutputVectorType errorvector; std::ofstream outfile; outfile.open("output.txt"); @@ -67,7 +73,8 @@ void IterativeSupervisedTrainingFunction<TSample,TOutput,ScalarType> inputvector = this->m_InputSamples[temp]; targetvector = this->m_Targets[temp]; outputvector = Net->GenerateOutput(inputvector); - errorvector = targetvector - outputvector; + for(unsigned int k=0; k<targetvector.Size(); k++) + errorvector[k] = targetvector[k] - outputvector[k]; outfile <<errorvector[0] << std::endl; Net->BackwardPropagate(this->m_PerformanceFunction->EvaluateDerivative(errorvector)); Net->UpdateWeights(this->m_LearningRate); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.h index 887ef730c6..5844947ce8 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkLayerBase.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -51,6 +51,7 @@ public: typedef typename TVector::ValueType ValueType; typedef ValueType* ValuePointer; typedef vnl_vector<ValueType> NodeVectorType; + typedef Array<ValueType> InternalVectorType; typedef WeightSetBase<TVector,TOutput> WeightSetType; @@ -62,6 +63,8 @@ public: typedef typename TransferFunctionType::Pointer TransferFunctionPointer; + typedef typename WeightSetType::Pointer WeightSetPointer; + virtual void SetNumberOfNodes(unsigned int); unsigned int GetNumberOfNodes(); @@ -73,7 +76,7 @@ public: virtual void ForwardPropagate(TVector){}; - virtual void BackwardPropagate(TOutput){}; + virtual void BackwardPropagate(InternalVectorType){}; virtual void BackwardPropagate(){}; virtual ValueType GetOutputErrorValue(unsigned int) = 0; @@ -83,10 +86,12 @@ public: virtual ValuePointer GetInputErrorVector() = 0; virtual void SetInputErrorValue(ValueType, int) {}; - itkSetObjectMacro(InputWeightSet, WeightSetType); + //itkSetObjectMacro(InputWeightSet, WeightSetType); + void SetInputWeightSet(WeightSetType*); itkGetObjectMacro(InputWeightSet, WeightSetType); - itkSetObjectMacro(OutputWeightSet, WeightSetType); + //itkSetObjectMacro(OutputWeightSet, WeightSetType); + void SetOutputWeightSet(WeightSetType*); itkGetObjectMacro(OutputWeightSet, WeightSetType); void SetNodeInputFunction(InputFunctionType* f); @@ -101,9 +106,13 @@ public: itkSetMacro(LayerType, unsigned int); itkGetMacro(LayerType, unsigned int); + itkSetMacro(LayerId,int); + itkGetMacro(LayerId,int); + virtual void SetBias(ValueType) = 0; virtual ValueType GetBias() = 0; + protected: LayerBase(); @@ -113,6 +122,7 @@ protected: virtual void PrintSelf( std::ostream& os, Indent indent ) const; unsigned int m_LayerType; //input, hidden, output + unsigned int m_LayerId; //input, hidden, output unsigned int m_NumberOfNodes; typename WeightSetType::Pointer m_InputWeightSet; @@ -120,6 +130,8 @@ protected: TransferFunctionPointer m_ActivationFunction; InputFunctionPointer m_NodeInputFunction; + + }; //class layer base diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.txx index c5cfc34e75..b26796301d 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLayerBase.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkLayerBase.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -72,6 +72,26 @@ LayerBase<TVector,TOutput> this->Modified(); } +template<class TVector, class TOutput> +void +LayerBase<TVector,TOutput> +::SetInputWeightSet(WeightSetType* weightset) +{ + m_InputWeightSet=weightset; + m_InputWeightSet->SetOutputLayerId(m_LayerId); + this->Modified(); +} + +template<class TVector, class TOutput> +void +LayerBase<TVector,TOutput> +::SetOutputWeightSet(WeightSetType* weightset) +{ + m_OutputWeightSet=weightset; + m_OutputWeightSet->SetInputLayerId(m_LayerId); + this->Modified(); +} + /** Print the object */ template<class TVector, class TOutput> void diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLogSigmoidTransferFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLogSigmoidTransferFunction.txx index f88eb1b570..91faf66b94 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLogSigmoidTransferFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkLogSigmoidTransferFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkLogSigmoidTransferFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -45,7 +45,7 @@ ScalarType LogSigmoidTransferFunction<ScalarType> ::Evaluate(const ScalarType& input) const { - const ScalarType v = 1.0 / (1.0 + exp(-input)); + const ScalarType v = 1.0 / (1.0 + vcl_exp(-input)); return v; } diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.h index 9d235ce5c1..244f70204e 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMeanSquaredErrorFunction.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 21:34:31 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -37,6 +37,7 @@ public: typedef SmartPointer<Self> Pointer; typedef SmartPointer<const Self> ConstPointer; typedef typename Superclass::ErrorVectorType ErrorVectorType; + typedef typename Superclass::InternalVectorType InternalVectorType; /** Run-time type information (and related methods). */ itkTypeMacro(MeanSquaredErrorFunction, FunctionBase); @@ -47,7 +48,7 @@ public: /** Evaluate at the specified Error position */ ScalarType Evaluate(const TVector& Errors) const; - ErrorVectorType EvaluateDerivative(const TVector& Errors) const; + InternalVectorType EvaluateDerivative(const TVector& Errors) const; protected: diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.txx index 7d930df028..889e2f86fe 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMeanSquaredErrorFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMeanSquaredErrorFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -45,19 +45,28 @@ ScalarType MeanSquaredErrorFunction <TVector,ScalarType> ::Evaluate(const TVector& errors) const { - vnl_vector <ScalarType> temp(errors.GetVnlVector()); + vnl_vector <ScalarType> temp(errors.Size()); + for(unsigned int i=0; i<errors.Size(); i++) + { + temp[i]=errors[i]; + } return (temp.squared_magnitude() / temp.size()); } /** Evaluate derivatives */ template<class TVector, class ScalarType> typename MeanSquaredErrorFunction <TVector,ScalarType> -::ErrorVectorType +::InternalVectorType MeanSquaredErrorFunction <TVector,ScalarType> ::EvaluateDerivative(const TVector& errors) const { - ScalarType m = static_cast<ScalarType>(2) / errors.GetVectorDimension(); - return (errors * m); + ScalarType m = static_cast<ScalarType>(2) / errors.Size(); + InternalVectorType temp(errors.Size()); + for(int i=0; i<errors.Size(); i++) + { + temp[i]=errors[i]*m; + } + return temp; } /** Print the object */ diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.h index 8760724a5e..4df398c0f4 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMultilayerNeuralNetworkBase.h,v $ Language: C++ - Date: $Date: 2005/11/21 18:39:31 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/04/17 21:34:31 $ + Version: $Revision: 1.4 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -42,7 +42,7 @@ public: itkNewMacro( Self ); typedef typename Superclass::ValueType ValueType; - + typedef typename Superclass::NetworkOutputType NetworkOutputType; typedef typename Superclass::LayerType LayerType; typedef typename Superclass::WeightSetType WeightSetType; typedef typename Superclass::WeightSetPointer WeightSetPointer; @@ -55,17 +55,24 @@ public: itkSetMacro(NumOfLayers, int); itkGetConstReferenceMacro(NumOfLayers, int); + + itkSetMacro(NumOfWeightSets, int); + itkGetConstReferenceMacro(NumOfWeightSets, int); void AddLayer(LayerType*); + LayerType* GetLayer(int layer_id); void AddWeightSet(WeightSetType*); + WeightSetType* GetWeightSet(int id); void SetLearningFunction(LearningFunctionType* f); - virtual ValueType* GenerateOutput(TVector samplevector); - - virtual void BackwardPropagate(TOutput errors); + // virtual ValueType* GenerateOutput(TVector samplevector); + virtual NetworkOutputType GenerateOutput(TVector samplevector); +// virtual void BackwardPropagate(TOutput errors); + virtual void BackwardPropagate(NetworkOutputType errors); + virtual void UpdateWeights(ValueType); void SetLearningRule(LearningFunctionType*); @@ -83,7 +90,7 @@ protected: LearningFunctionPointer m_LearningFunction; ValueType m_LearningRate; int m_NumOfLayers; - + int m_NumOfWeightSets; /** Method to print the object. */ virtual void PrintSelf( std::ostream& os, Indent indent ) const; }; diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.txx index 41c70454eb..b6295179b9 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultilayerNeuralNetworkBase.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMultilayerNeuralNetworkBase.txx,v $ Language: C++ - Date: $Date: 2005/08/03 15:47:06 $ - Version: $Revision: 1.3 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.4 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -32,6 +32,7 @@ MultilayerNeuralNetworkBase<TVector,TOutput> m_LearningFunction = DefaultLearningFunctionType::New(); m_LearningRate = 0.001; m_NumOfLayers = 0; + m_NumOfWeightSets=0; } template<class TVector, class TOutput> @@ -67,7 +68,17 @@ MultilayerNeuralNetworkBase<TVector,TOutput> } template<class TVector, class TOutput> -typename MultilayerNeuralNetworkBase<TVector, TOutput>::ValueType* +typename MultilayerNeuralNetworkBase<TVector, TOutput>::LayerType* +MultilayerNeuralNetworkBase<TVector,TOutput> +::GetLayer(int layer_id) +{ + return m_Layers[layer_id].GetPointer(); +} + + + +template<class TVector, class TOutput> +typename MultilayerNeuralNetworkBase<TVector, TOutput>::NetworkOutputType MultilayerNeuralNetworkBase<TVector,TOutput> ::GenerateOutput(TVector samplevector) { @@ -78,13 +89,18 @@ MultilayerNeuralNetworkBase<TVector,TOutput> this->m_Weights[i]->ForwardPropagate(this->m_Layers[i]->GetOutputVector()); this->m_Layers[i + 1]->ForwardPropagate(); } - return this->m_Layers[i]->GetOutputVector(); + NetworkOutputType temp_output; + temp_output.SetSize(this->m_Layers[i]->GetNumberOfNodes()); + for(unsigned int k=0; k<temp_output.Size(); k++) + temp_output[k]=this->m_Layers[i]->GetOutputVector()[k]; +// return this->m_Layers[i]->GetOutputVector(); + return temp_output; } template<class TVector, class TOutput> void MultilayerNeuralNetworkBase<TVector,TOutput> -::BackwardPropagate(TOutput errors) +::BackwardPropagate(NetworkOutputType errors) { int i = this->m_Layers.size(); i--; @@ -129,8 +145,18 @@ MultilayerNeuralNetworkBase<TVector,TOutput> ::AddWeightSet(WeightSetType* weightset) { m_Weights.push_back(weightset); + m_NumOfWeightSets++; } +template<class TVector, class TOutput> +typename MultilayerNeuralNetworkBase<TVector, TOutput>::WeightSetType* +MultilayerNeuralNetworkBase<TVector,TOutput> +::GetWeightSet(int id) +{ + return m_Weights[id].GetPointer(); +} + + template<class TVector, class TOutput> void MultilayerNeuralNetworkBase<TVector,TOutput> diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultiquadricRadialBasisFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultiquadricRadialBasisFunction.txx index 8e6f04365c..c6d9cbafe5 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultiquadricRadialBasisFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkMultiquadricRadialBasisFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMultiquadricRadialBasisFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -45,7 +45,7 @@ ScalarType MultiquadricRadialBasisFunction<ScalarType> ::Evaluate(const ScalarType& input) const { - const ScalarType val = pow((input*input)+(m_Radius*m_Radius),0.5); + const ScalarType val = vcl_pow((input*input)+(m_Radius*m_Radius),0.5); return val; } diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkNeuralNetworkObject.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkNeuralNetworkObject.h index 300348ace4..dfc1591ea7 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkNeuralNetworkObject.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkNeuralNetworkObject.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkNeuralNetworkObject.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -40,7 +40,8 @@ public: typedef typename TVector::ValueType ValueType; typedef TOutput TargetVectorType; - + typedef Array<ValueType> NetworkOutputType; + typedef WeightSetBase<TVector, TOutput> WeightSetType; typedef LayerBase<TVector, TOutput> LayerType; typedef typename LayerType::Pointer LayerPointer; @@ -48,10 +49,11 @@ public: typedef LearningFunctionBase<LayerType, TOutput> LearningFunctionType; typedef typename LearningFunctionType::Pointer LearningFunctionPointer; - virtual ValueType* GenerateOutput(TVector samplevector) = 0; - - virtual void BackwardPropagate(TOutput errors) = 0; + //virtual ValueType* GenerateOutput(TVector samplevector) = 0; + virtual NetworkOutputType GenerateOutput(TVector samplevector)=0; + //virtual void BackwardPropagate(TOutput errors) = 0; + virtual void BackwardPropagate(NetworkOutputType errors) = 0; virtual void UpdateWeights(ValueType) = 0; protected: diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.h index 97c64661da..d65b704d75 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkOneHiddenLayerBackPropagationNeuralNetwork.h,v $ Language: C++ - Date: $Date: 2005/08/03 14:40:14 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/04/17 21:34:31 $ + Version: $Revision: 1.4 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -50,7 +50,8 @@ public: typedef SmartPointer<Self> Pointer; typedef SmartPointer<const Self> ConstPointer; typedef typename Superclass::ValueType ValueType; - + typedef typename Superclass::NetworkOutputType NetworkOutputType; + typedef TransferFunctionBase<ValueType> TransferFunctionType; typedef InputFunctionBase<ValueType*, ValueType> InputFunctionType; @@ -78,7 +79,8 @@ public: itkSetMacro(OutputLayerBias, ValueType); itkGetConstReferenceMacro(OutputLayerBias, ValueType); - ValueType* GenerateOutput(TVector samplevector); + //ValueType* GenerateOutput(TVector samplevector); + NetworkOutputType GenerateOutput(TVector samplevector); void SetInputTransferFunction(TransferFunctionType* f); void SetHiddenTransferFunction(TransferFunctionType* f); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.txx index 4c83606801..d1a25d9e88 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkOneHiddenLayerBackPropagationNeuralNetwork.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkOneHiddenLayerBackPropagationNeuralNetwork.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -144,7 +144,7 @@ OneHiddenLayerBackPropagationNeuralNetwork<TVector,TOutput> /** Generate output */ template<class TVector, class TOutput> -typename OneHiddenLayerBackPropagationNeuralNetwork<TVector, TOutput>::ValueType* +typename OneHiddenLayerBackPropagationNeuralNetwork<TVector, TOutput>::NetworkOutputType OneHiddenLayerBackPropagationNeuralNetwork<TVector,TOutput> ::GenerateOutput(TVector samplevector) { diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFBackPropagationLearningFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFBackPropagationLearningFunction.txx index 22034f4a21..6a061a33d3 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFBackPropagationLearningFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFBackPropagationLearningFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkRBFBackPropagationLearningFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/03 15:47:06 $ - Version: $Revision: 1.3 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.4 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -48,7 +48,7 @@ RBFBackPropagationLearningFunction<LayerType,TOutput> typedef RBFLayer<InputVectorType,OutputVectorType> RbfLayerType; - typedef typename RbfLayerType::NodeArrayType ArrayType; + typedef typename RbfLayerType::InternalVectorType ArrayType; typename LayerType::ValuePointer currentdeltavalues = inputweightset->GetTotalDeltaValues(); vnl_matrix<ValueType> DW_temp(currentdeltavalues,inputweightset->GetNumberOfOutputNodes(), inputweightset->GetNumberOfInputNodes()); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.h index dd00b03f63..219d0bd79a 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkRBFLayer.h,v $ Language: C++ - Date: $Date: 2005/08/26 00:03:39 $ - Version: $Revision: 1.5 $ + Date: $Date: 2006/04/17 21:34:31 $ + Version: $Revision: 1.7 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -45,18 +45,27 @@ public: typedef typename Superclass::ValueType ValueType; typedef typename Superclass::ValuePointer ValuePointer; typedef vnl_vector<ValueType> NodeVectorType; - typedef Array<ValueType> NodeArrayType; + //typedef Array<ValueType> NodeArrayType; + typedef typename Superclass::InternalVectorType InternalVectorType; + typedef typename Superclass::OutputVectorType OutputVectorType; typedef RadialBasisFunctionBase<ValueType> RBFType; //Distance Metric - typedef EuclideanDistance<TVector> DistanceMetricType; + typedef EuclideanDistance<InternalVectorType> DistanceMetricType; typedef typename DistanceMetricType::Pointer DistanceMetricPointer; //Member Functions - void SetNumberOfNodes(unsigned int); + void SetNumberOfNodes(unsigned int numNodes); + //void SetMeasurementVectorSize(unsigned int size); + itkGetMacro(RBF_Dim, unsigned int); + void SetRBF_Dim(unsigned int size); + + ValueType GetInputValue(unsigned int i); - void SetInputValue(unsigned int i, ValueType value); + void SetInputValue(unsigned int i,ValueType value); + + itkGetMacro(LayerType, unsigned int); ValueType GetOutputValue(int); void SetOutputValue(int, ValueType); @@ -78,7 +87,8 @@ public: ValuePointer GetInputErrorVector(); void SetInputErrorValue(ValueType, int node_id); - TVector GetCenter(int i); + //TVector GetCenter(int i); + InternalVectorType GetCenter(int i); void SetCenter(TVector c,int i); ValueType GetRadii(int i); @@ -110,14 +120,15 @@ protected: virtual void PrintSelf( std::ostream& os, Indent indent ) const; private: - + typename DistanceMetricType::Pointer m_DistanceMetric; NodeVectorType m_NodeInputValues; NodeVectorType m_NodeOutputValues; NodeVectorType m_InputErrorValues; NodeVectorType m_OutputErrorValues; - std::vector<TVector> m_Centers; // ui....uc - NodeArrayType m_Radii; + //std::vector<TVector> m_Centers; // ui....uc + std::vector<InternalVectorType> m_Centers; // ui....uc + InternalVectorType m_Radii; int m_NumClasses; ValueType m_Bias; int m_RBF_Dim; diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.txx index f543c93a1d..cd0c68d8cd 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFLayer.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkRBFLayer.txx,v $ Language: C++ - Date: $Date: 2005/08/10 19:53:43 $ - Version: $Revision: 1.4 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.5 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -34,9 +34,9 @@ RBFLayer<TVector,TOutput> typedef GaussianRadialBasisFunction<ValueType> GRBFType; m_RBF=GRBFType::New(); m_DistanceMetric = DistanceMetricType::New(); - TVector origin; +// TVector origin; - m_DistanceMetric->SetMeasurementVectorSize(origin.GetVectorDimension()); +// m_DistanceMetric->SetMeasurementVectorSize(origin.Size()); m_RBF_Dim = 0; } @@ -54,14 +54,22 @@ RBFLayer<TVector,TOutput> m_RBF = f; this->Modified(); } +template<class TVector, class TOutput> +void +RBFLayer<TVector,TOutput> +::SetRBF_Dim(unsigned int dim) +{ + m_RBF_Dim=dim; + m_DistanceMetric->SetMeasurementVectorSize(m_RBF_Dim); +} template<class TVector, class TOutput> void RBFLayer<TVector,TOutput> ::SetNumberOfNodes(unsigned int c) { - TVector sampleinputvector; - m_RBF_Dim= sampleinputvector.GetVectorDimension(); + //TVector sampleinputvector; + //m_RBF_Dim= sampleinputvector.Size(); Superclass::SetNumberOfNodes(c); this->m_NodeInputValues.set_size(m_RBF_Dim); //c); this->m_NodeOutputValues.set_size(c); @@ -70,7 +78,8 @@ RBFLayer<TVector,TOutput> if(this->GetLayerType()!=3) { - TVector temp; + //TVector temp; + InternalVectorType temp(m_RBF_Dim); for(unsigned int i=0; i<c; i++) { m_Centers.push_back(temp); @@ -155,12 +164,17 @@ void RBFLayer<TVector,TOutput> ::SetCenter(TVector c,int i) { - m_Centers[i]=c; + InternalVectorType temp(c.Size()); + for(int j=0; j<c.Size(); j++) + { + temp[j]=c[j]; + } + m_Centers[i]=temp; //c; this->Modified(); } template<class TVector, class TOutput> -TVector +typename RBFLayer<TVector,TOutput>::InternalVectorType RBFLayer<TVector,TOutput> ::GetCenter(int i) { @@ -257,11 +271,14 @@ RBFLayer<TVector,TOutput> width_increment.fill(0); width_increment= center_increment.get_column(inputweightset->GetNumberOfInputNodes()-1); ValueType temp_radius; - NodeArrayType temp_center; + InternalVectorType temp_center; temp_center.SetSize(m_RBF_Dim); - TVector tempvector1; - TVector tempvector2; - TVector tempcenter; + //TVector tempvector1; + //TVector tempvector2; + //TVector tempcenter; + InternalVectorType tempvector1(m_RBF_Dim); + InternalVectorType tempvector2(m_RBF_Dim); + InternalVectorType tempcenter(m_RBF_Dim); for (int i = 0; i < m_NumClasses; i++) { @@ -277,18 +294,21 @@ RBFLayer<TVector,TOutput> temp_radius = m_Radii.GetElement(i); temp_radius += width_increment[i]; m_Radii.SetElement(i,temp_radius); - NodeArrayType array1(m_NodeInputValues.size()); + InternalVectorType array1(m_NodeInputValues.size()); array1= m_NodeInputValues; - tempvector1.Set_vnl_vector(m_NodeInputValues); + for(int j=0; j<tempvector1.size(); j++) + tempvector1[j]=m_NodeInputValues[j]; + + //tempvector1.Set_vnl_vector(m_NodeInputValues); tempvector2=m_Centers[i]; tempcenter= m_Centers[i]; //double dt= m_DistanceMetric->Evaluate(tempvector1,tempvector2); //std::cout<<"Euclidean in layer ="<<dt<<std::endl; m_RBF->SetRadius(m_Radii.GetElement(i)); - NodeArrayType temp_array(m_RBF_Dim); - TVector temp_vector= m_Centers[i]; + InternalVectorType temp_array(m_RBF_Dim); + NodeVectorType temp_vector= m_Centers[i]; for(int ii=0; ii<m_RBF_Dim; ii++) temp_array.SetElement(ii,temp_vector[ii]); m_RBF->SetCenter(temp_array); @@ -327,7 +347,11 @@ void RBFLayer<TVector,TOutput> ::SetOutputErrorValues(TOutput errors) { - m_OutputErrorValues = errors.GetVnlVector(); + + for(unsigned int i=0; i<errors.Size(); i++) + m_OutputErrorValues[i] = errors[i]; + + this->Modified(); } template<class TVector, class TOutput> @@ -366,9 +390,13 @@ RBFLayer<TVector,TOutput> vnl_vector<ValueType> deltaww; deltaww.set_size(cols); deltaww.fill(0); + /* TVector tempvector1; - TVector tempvector2; - + TVector tempvector2;*/ + + InternalVectorType tempvector1(m_RBF_Dim); + InternalVectorType tempvector2(m_RBF_Dim); + for(int c1=0; c1<rows; c1++) { for(int c2=0; c2<cols; c2++) @@ -383,12 +411,14 @@ RBFLayer<TVector,TOutput> } //compute gradient for centers - NodeArrayType array1(m_NodeInputValues.size()); + InternalVectorType array1(m_NodeInputValues.size()); array1= m_NodeInputValues; vnl_matrix<ValueType> DW_temp(inputweightset->GetNumberOfOutputNodes(), inputweightset->GetNumberOfInputNodes()); DW_temp.fill(0.0); - tempvector1.Set_vnl_vector(array1); + + for(int k=0; k<array1.Size(); k++) + tempvector1[k]=array1[k]; for(int k=0; k<num_nodes; k++) { @@ -397,8 +427,8 @@ RBFLayer<TVector,TOutput> tempvector2=m_Centers[k]; double dist=m_DistanceMetric->Evaluate(tempvector1,tempvector2); m_RBF->SetRadius(m_Radii.GetElement(k)); - TVector temp_vector= m_Centers[k]; - NodeArrayType temp_array(m_RBF_Dim); + NodeVectorType temp_vector= m_Centers[k]; + InternalVectorType temp_array(m_RBF_Dim); for(int ii=0; ii<m_RBF_Dim; ii++) temp_array.SetElement(ii,temp_vector[ii]); m_RBF->SetCenter(temp_array); diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.h index 565db5a40c..7c61cd8d04 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkRBFNetwork.h,v $ Language: C++ - Date: $Date: 2005/08/03 14:40:14 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/04/18 11:23:29 $ + Version: $Revision: 1.4 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -49,11 +49,10 @@ public: typedef SmartPointer<const Self> ConstPointer; typedef typename Superclass::ValueType ValueType; typedef Array<ValueType> ArrayType; - typedef TransferFunctionBase<ValueType> TransferFunctionType; typedef RadialBasisFunctionBase<ValueType> RBFType; typedef InputFunctionBase<ValueType*, ValueType> InputFunctionType; - typedef EuclideanDistance<TVector> DistanceMetricType; + typedef EuclideanDistance<ArrayType> DistanceMetricType; typename InputFunctionType::Pointer InputFunction; typename DistanceMetricType::Pointer DistanceMetric; @@ -62,6 +61,8 @@ public: typename RBFType::Pointer HiddenTransferFunction; typename TransferFunctionType::Pointer OutputTransferFunction; + typedef typename Superclass::NetworkOutputType NetworkOutputType; + /* Method for creation through the object factory. */ itkTypeMacro(RBFNetwork, MultilayerNeuralNetworkBase); @@ -89,7 +90,8 @@ public: itkSetMacro(Classes, int); itkGetConstReferenceMacro(Classes,int); - ValueType* GenerateOutput(TVector samplevector); + // ValueType* GenerateOutput(TVector samplevector); + virtual NetworkOutputType GenerateOutput(TVector samplevector); void SetInputTransferFunction(TransferFunctionType* f); void SetDistanceMetric(DistanceMetricType* f); @@ -99,6 +101,9 @@ public: void SetInputFunction(InputFunctionType* f); void InitializeWeights(); + void SetCenter(TVector c); + void SetRadius(ValueType r); + protected: RBFNetwork(); @@ -115,6 +120,8 @@ private: int m_Classes; ValueType m_HiddenLayerBias; ValueType m_OutputLayerBias; + std::vector<TVector> m_Centers; // ui....uc + std::vector<double> m_Radii; }; } // end namespace Statistics diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.txx index f4c638ebbc..97ccb8ccbe 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkRBFNetwork.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkRBFNetwork.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -81,10 +81,12 @@ RBFNetwork<TVector,TOutput> typename rbflayertype::Pointer hiddenlayer = rbflayertype::New(); + hiddenlayer->SetRBF_Dim(m_NumOfInputNodes); hiddenlayer->SetLayerType(2); hiddenlayer->SetNumClasses(m_Classes); hiddenlayer->SetNumberOfNodes(m_NumOfHiddenNodes); + typename bplayertype::Pointer outputlayer = bplayertype::New(); hiddenlayer->SetNumClasses(m_Classes); outputlayer->SetLayerType(3); @@ -124,7 +126,7 @@ RBFNetwork<TVector,TOutput> Superclass::AddWeightSet(IW); Superclass::AddWeightSet(HW); - + /* TVector temp1; TVector temp2; temp1[0]=110; @@ -142,7 +144,13 @@ RBFNetwork<TVector,TOutput> hiddenlayer->SetRadii(2*width,0); hiddenlayer->SetRadii(2*width,1); - + */ + for(int j=0; j<m_Centers.size(); j++) + { + hiddenlayer->SetCenter(m_Centers[j],j); + hiddenlayer->SetRadii(m_Radii[j],j); + } + } template<class TVector, class TOutput> @@ -186,13 +194,29 @@ RBFNetwork<TVector,TOutput> } template<class TVector, class TOutput> -typename RBFNetwork<TVector, TOutput>::ValueType* +typename RBFNetwork<TVector, TOutput>::NetworkOutputType RBFNetwork<TVector,TOutput> ::GenerateOutput(TVector samplevector) { return Superclass::GenerateOutput(samplevector); } +template<class TVector, class TOutput> +void +RBFNetwork<TVector,TOutput> +::SetCenter(TVector c) +{ + m_Centers.push_back(c); +} + +template<class TVector, class TOutput> +void +RBFNetwork<TVector,TOutput> +::SetRadius(ValueType r) +{ + m_Radii.push_back(r); +} + /** Print the object */ template<class TVector, class TOutput> void diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSigmoidTransferFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSigmoidTransferFunction.txx index 50457fa139..0307bb8325 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSigmoidTransferFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSigmoidTransferFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkSigmoidTransferFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -49,7 +49,7 @@ SigmoidTransferFunction<ScalarType> ::Evaluate(const ScalarType& input) const { const ScalarType x = (static_cast<ScalarType>(input) - m_Beta) / m_Alpha; - const ScalarType e = 1.0 / (1.0 + exp(-x)); + const ScalarType e = 1.0 / (1.0 + vcl_exp(-x)); const ScalarType v = (m_OutputMaximum - m_OutputMinimum) * e + m_OutputMinimum; return v; diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.h index 9ac9232e41..b0a7946761 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkSquaredDifferenceErrorFunction.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 21:34:31 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -37,6 +37,7 @@ public: typedef SmartPointer<Self> Pointer; typedef SmartPointer<const Self> ConstPointer; typedef typename Superclass::ErrorVectorType ErrorVectorType; + typedef typename Superclass::InternalVectorType InternalVectorType; /** Run-time type information (and related methods). */ itkTypeMacro(SquaredDifferenceErrorFunction, FunctionBase); @@ -47,7 +48,7 @@ public: /** Evaluate at the specified Error position */ ScalarType Evaluate(const TVector& Errors) const; - ErrorVectorType EvaluateDerivative(const TVector& Errors) const; + InternalVectorType EvaluateDerivative(const TVector& Errors) const; protected: diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.txx index 8f8d3b9995..027e05da74 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSquaredDifferenceErrorFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkSquaredDifferenceErrorFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/03 12:06:12 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -45,19 +45,27 @@ ScalarType SquaredDifferenceErrorFunction <TVector,ScalarType> ::Evaluate(const TVector& errors) const { - vnl_vector <ScalarType> temp(errors.GetVnlVector()); + vnl_vector <ScalarType> temp; + temp.set_size(errors.Size()); + for(unsigned int i=0; i<errors.Size(); i++) + temp[i]=errors[i]; + + //temp.(errors.GetVnlVector()); + return (temp.squared_magnitude() / 2); } /** Evaluate derivatives */ template<class TVector, class ScalarType> typename SquaredDifferenceErrorFunction <TVector,ScalarType> -::ErrorVectorType +::InternalVectorType SquaredDifferenceErrorFunction <TVector,ScalarType> ::EvaluateDerivative(const TVector& errors) const { - TVector diff; - for(unsigned int i=0; i<errors.GetVectorDimension(); i++) + //TVector diff; + InternalVectorType diff; + diff.SetSize(errors.Size()); + for(unsigned int i=0; i<errors.Size(); i++) { if ((-0.1 < errors[i]) && (errors[i] < 0.1)) { diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSymmetricSigmoidTransferFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSymmetricSigmoidTransferFunction.txx index 5dadf8d839..d938219f5b 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSymmetricSigmoidTransferFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkSymmetricSigmoidTransferFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkSymmetricSigmoidTransferFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/03 17:30:12 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -54,7 +54,7 @@ SymmetricSigmoidTransferFunction<ScalarType> } else { - val= (ScalarType)1.0/(1.0+exp(-input))-0.5; + val= (ScalarType)1.0/(1.0+vcl_exp(-input))-0.5; } return val; } diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanHTransferFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanHTransferFunction.txx index 47ae4a66b0..e6bec9fec8 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanHTransferFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanHTransferFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkTanHTransferFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -42,8 +42,8 @@ ScalarType TanHTransferFunction<ScalarType> ::Evaluate(const ScalarType& input) const { - ScalarType x = exp(input); - ScalarType y = exp(-input); + ScalarType x = vcl_exp(input); + ScalarType y = vcl_exp(-input); return static_cast<ScalarType>((float) (x - y) / (x + y)); } @@ -54,7 +54,7 @@ TanHTransferFunction<ScalarType> ::EvaluateDerivative(const ScalarType& input) const { ScalarType f = Evaluate(input); - return 1 - pow(f, 2); + return 1 - vcl_pow(f, 2); } /** Print the object */ diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanSigmoidTransferFunction.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanSigmoidTransferFunction.txx index b81c7d74dc..70a1e3d046 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanSigmoidTransferFunction.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTanSigmoidTransferFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkTanSigmoidTransferFunction.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -43,7 +43,7 @@ TanSigmoidTransferFunction<ScalarType> ::Evaluate(const ScalarType& input) const { return static_cast<ScalarType>((2 - / (1 + exp(-2 * static_cast<ScalarType>(input)))) + / (1 + vcl_exp(-2 * static_cast<ScalarType>(input)))) - 1); } diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.h index 5556548fac..3d5413812c 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkTrainingFunctionBase.h,v $ Language: C++ - Date: $Date: 2005/08/10 18:28:38 $ - Version: $Revision: 1.4 $ + Date: $Date: 2006/04/18 11:23:29 $ + Version: $Revision: 1.6 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -43,15 +43,17 @@ public: /** Method for creation through the object factory. */ itkNewMacro(Self); + typedef ScalarType ValueType; typedef typename TSample::MeasurementVectorType VectorType; typedef typename TOutput::MeasurementVectorType OutputVectorType; + typedef Array<ValueType> InternalVectorType; typedef std::vector<VectorType> InputSampleVectorType; typedef std::vector<OutputVectorType> OutputSampleVectorType; - typedef ScalarType ValueType; typedef NeuralNetworkObject<VectorType, OutputVectorType> NetworkType; - typedef ErrorFunctionBase<OutputVectorType, ScalarType> PerformanceFunctionType; - typedef SquaredDifferenceErrorFunction<OutputVectorType, ScalarType> DefaultPerformanceType; + typedef ErrorFunctionBase<InternalVectorType, ScalarType> PerformanceFunctionType; + typedef SquaredDifferenceErrorFunction<InternalVectorType, ScalarType> DefaultPerformanceType; + //typedef MeanSquaredErrorFunction<InternalVectorType, ScalarType> DefaultPerformanceType; void SetTrainingSamples(TSample* samples); void SetTargetValues(TOutput* targets); @@ -85,6 +87,7 @@ public: targetconverter(typename TOutput::MeasurementVectorType v) { OutputVectorType temp; + for (unsigned int i = 0; i < v.Size(); i++) { temp[i] = static_cast<ScalarType>(v[i]) ; diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.txx index fdb055ea8d..cb13e0ffc2 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTrainingFunctionBase.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkTrainingFunctionBase.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -45,7 +45,9 @@ void TrainingFunctionBase<TSample,TOutput,ScalarType> typename TSample::ConstIterator iter = samples->Begin(); while (iter != samples->End()) { - m_InputSamples.push_back(defaultconverter(iter.GetMeasurementVector())); + //m_InputSamples.push_back(defaultconverter(iter.GetMeasurementVector())); + m_InputSamples.push_back(iter.GetMeasurementVector()); + ++iter; } } @@ -57,7 +59,8 @@ void TrainingFunctionBase<TSample,TOutput,ScalarType> typename TOutput::ConstIterator iter = targets->Begin(); while (iter != targets->End()) { - m_Targets.push_back(targetconverter(iter.GetMeasurementVector())); + //m_Targets.push_back(targetconverter(iter.GetMeasurementVector())); + m_Targets.push_back(iter.GetMeasurementVector()); ++iter; } std::cout << "Num of Sample Targets converted= " << m_Targets.size() diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.h index e33af2593a..f56a8f9dde 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkTwoHiddenLayerBackPropagationNeuralNetwork.h,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/18 11:23:29 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -48,6 +48,8 @@ public: typedef SmartPointer<Self> Pointer; typedef SmartPointer<const Self> ConstPointer; + typedef typename Superclass::NetworkOutputType NetworkOutputType; + /* Method for creation through the object factory. */ itkTypeMacro(TwoHiddenLayerBackPropagationNeuralNetwork, MultilayerNeuralNetworkBase); @@ -71,7 +73,8 @@ public: itkSetMacro(NumOfOutputNodes, int); itkGetConstReferenceMacro(NumOfOutputNodes, int); - ValueType* GenerateOutput(TVector samplevector); + //ValueType* GenerateOutput(TVector samplevector); + virtual NetworkOutputType GenerateOutput(TVector samplevector); protected: diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.txx index 4ae782fd29..63f78ec70c 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkTwoHiddenLayerBackPropagationNeuralNetwork.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkTwoHiddenLayerBackPropagationNeuralNetwork.txx,v $ Language: C++ - Date: $Date: 2005/08/02 19:17:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -123,7 +123,7 @@ TwoHiddenLayerBackPropagationNeuralNetwork<TVector,TOutput> } template<class TVector, class TOutput> -typename TwoHiddenLayerBackPropagationNeuralNetwork<TVector, TOutput>::ValueType* +typename TwoHiddenLayerBackPropagationNeuralNetwork<TVector, TOutput>::NetworkOutputType TwoHiddenLayerBackPropagationNeuralNetwork<TVector,TOutput> ::GenerateOutput(TVector samplevector) { diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.h b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.h index 71b8c5232a..5e08c1a722 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.h +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkWeightSetBase.h,v $ Language: C++ - Date: $Date: 2005/08/10 20:36:01 $ - Version: $Revision: 1.2 $ + Date: $Date: 2006/04/17 19:34:45 $ + Version: $Revision: 1.3 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -59,11 +59,11 @@ public: void SetConnectivityMatrix(vnl_matrix < int>); - void SetNumberOfInputNodes(int n); - int GetNumberOfInputNodes(); + void SetNumberOfInputNodes(unsigned int n); + unsigned int GetNumberOfInputNodes(); - void SetNumberOfOutputNodes(int n); - int GetNumberOfOutputNodes(); + void SetNumberOfOutputNodes(unsigned int n); + unsigned int GetNumberOfOutputNodes(); void SetRange(ValueType Range); @@ -102,6 +102,7 @@ public: ValuePointer GetPrevDeltaBValues(); ValuePointer GetWeightValues(); + void SetWeightValues(ValuePointer weights); @@ -125,6 +126,15 @@ public: void InitializeWeights(); + itkSetMacro(WeightSetId,int); + itkGetMacro(WeightSetId,int); + + itkSetMacro(InputLayerId,int); + itkGetMacro(InputLayerId,int); + + itkSetMacro(OutputLayerId,int); + itkGetMacro(OutputLayerId,int); + protected: WeightSetBase(); @@ -134,8 +144,8 @@ protected: virtual void PrintSelf( std::ostream& os, Indent indent ) const; typename RandomVariateGeneratorType::Pointer m_RandomGenerator; - int m_NumberOfInputNodes; - int m_NumberOfOutputNodes; + unsigned int m_NumberOfInputNodes; + unsigned int m_NumberOfOutputNodes; vnl_matrix<ValueType> m_OutputValues; vnl_matrix<ValueType> m_InputErrorValues; @@ -175,6 +185,10 @@ protected: bool m_FirstPass; bool m_SecondPass; ValueType m_Range; + int m_InputLayerId; + int m_OutputLayerId; + int m_WeightSetId; + }; //class } // end namespace Statistics diff --git a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.txx b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.txx index 82b1ae9fe5..3c0baa25bb 100644 --- a/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.txx +++ b/Utilities/ITK/Code/Numerics/NeuralNetworks/itkWeightSetBase.txx @@ -43,14 +43,14 @@ WeightSetBase<TVector,TOutput> template<class TVector, class TOutput> void WeightSetBase<TVector,TOutput> -::SetNumberOfInputNodes(int n) +::SetNumberOfInputNodes(unsigned int n) { m_NumberOfInputNodes = n + 1; //including bias this->Modified(); } template<class TVector, class TOutput> -int +unsigned int WeightSetBase<TVector,TOutput> ::GetNumberOfInputNodes() { @@ -60,14 +60,14 @@ WeightSetBase<TVector,TOutput> template<class TVector, class TOutput> void WeightSetBase<TVector,TOutput> -::SetNumberOfOutputNodes(int n) +::SetNumberOfOutputNodes(unsigned int n) { m_NumberOfOutputNodes = n; this->Modified(); } template<class TVector, class TOutput> -int +unsigned int WeightSetBase<TVector,TOutput> ::GetNumberOfOutputNodes() { @@ -130,15 +130,18 @@ void WeightSetBase<TVector,TOutput> ::InitializeWeights() { - int num_rows = m_WeightMatrix.rows(); - int num_cols = m_WeightMatrix.cols(); + unsigned int num_rows = m_WeightMatrix.rows(); + unsigned int num_cols = m_WeightMatrix.cols(); + std::cout<<num_rows <<" "<<num_cols<<std::endl; + std::cout<<"conectivity matrix size = "<<m_ConnectivityMatrix.rows()<<" " + << m_ConnectivityMatrix.cols()<<std::endl; - for (int i = 0; i < num_rows; i++) + for (unsigned int i = 0; i < num_rows; i++) { - for (int j = 0; j < num_cols; j++) + for (unsigned int j = 0; j < num_cols; j++) { if(m_ConnectivityMatrix[i][j]==1) - m_WeightMatrix(i, j) = RandomWeightValue(-m_Range,m_Range); + m_WeightMatrix(i, j) = RandomWeightValue(-1*m_Range,m_Range); else m_WeightMatrix(i, j) = 0; } @@ -208,8 +211,8 @@ WeightSetBase<TVector,TOutput> W_temp.copy_in(w); m_WeightMatrix = W_temp; - ValueType v=0.0; - m_WeightMatrix.set_column( m_NumberOfInputNodes-1,v); + // ValueType v=0.0; + // m_WeightMatrix.set_column( m_NumberOfInputNodes-1,v); this->Modified(); } diff --git a/Utilities/ITK/Code/Numerics/Statistics/CMakeLists.txt b/Utilities/ITK/Code/Numerics/Statistics/CMakeLists.txt index dbe2420ee9..bccce71715 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/CMakeLists.txt +++ b/Utilities/ITK/Code/Numerics/Statistics/CMakeLists.txt @@ -7,5 +7,8 @@ ADD_LIBRARY(ITKStatistics TARGET_LINK_LIBRARIES(ITKStatistics ITKCommon) -INSTALL_TARGETS(/lib/otb ITKStatistics) -INSTALL_FILES(/include/otb/Utilities/ITK/Numerics/Statistics "(\\.h|\\.txx)$") +IF(ITK_LIBRARY_PROPERTIES) + SET_TARGET_PROPERTIES(ITKStatistics PROPERTIES ${ITK_LIBRARY_PROPERTIES}) +ENDIF(ITK_LIBRARY_PROPERTIES) +INSTALL_TARGETS(/lib/InsightToolkit ITKStatistics) +INSTALL_FILES(/include/InsightToolkit/Numerics/Statistics "(\\.h|\\.txx)$") diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkEuclideanDistance.txx b/Utilities/ITK/Code/Numerics/Statistics/itkEuclideanDistance.txx index b10fc43008..4075948312 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkEuclideanDistance.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkEuclideanDistance.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkEuclideanDistance.txx,v $ Language: C++ - Date: $Date: 2005/07/26 16:03:09 $ - Version: $Revision: 1.11 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.12 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -40,7 +40,7 @@ EuclideanDistance< TVector > distance += temp * temp ; } - return sqrt(distance) ; + return vcl_sqrt(distance) ; } @@ -66,7 +66,7 @@ EuclideanDistance< TVector > distance += temp * temp ; } - return sqrt(distance) ; + return vcl_sqrt(distance) ; } template< class TVector > @@ -75,7 +75,7 @@ EuclideanDistance< TVector > ::Evaluate(const ValueType &a, const ValueType &b) const { double temp = a - b ; - return sqrt(temp * temp) ; + return vcl_sqrt(temp * temp) ; } template< class TVector > diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkExpectationMaximizationMixtureModelEstimator.txx b/Utilities/ITK/Code/Numerics/Statistics/itkExpectationMaximizationMixtureModelEstimator.txx index dded9149ac..d84f126e16 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkExpectationMaximizationMixtureModelEstimator.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkExpectationMaximizationMixtureModelEstimator.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkExpectationMaximizationMixtureModelEstimator.txx,v $ Language: C++ - Date: $Date: 2005/05/06 18:53:40 $ - Version: $Revision: 1.15 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.16 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -223,7 +223,7 @@ ExpectationMaximizationMixtureModelEstimator< TSample > for (componentIndex = 0 ; componentIndex < m_ComponentVector.size() ; componentIndex++) { - logProportion = log(m_Proportions[componentIndex]) ; + logProportion = vcl_log(m_Proportions[componentIndex]) ; for (measurementVectorIndex = 0 ; measurementVectorIndex < size ; measurementVectorIndex++) { @@ -231,7 +231,7 @@ ExpectationMaximizationMixtureModelEstimator< TSample > GetWeight(measurementVectorIndex) ; sum += temp * ( logProportion + - log( m_ComponentVector[componentIndex]-> + vcl_log(m_ComponentVector[componentIndex]-> GetWeight(measurementVectorIndex) ) ) ; } } diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkGaussianDensityFunction.txx b/Utilities/ITK/Code/Numerics/Statistics/itkGaussianDensityFunction.txx index fa6f1ab5ee..9597c33ed8 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkGaussianDensityFunction.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkGaussianDensityFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkGaussianDensityFunction.txx,v $ Language: C++ - Date: $Date: 2005/07/26 15:54:55 $ - Version: $Revision: 1.21 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.22 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -97,7 +97,7 @@ GaussianDensityFunction< TMeasurementVector > // calculate coefficient C of multivariate gaussian m_PreFactor = 1.0 / (sqrt(det) * - pow(sqrt(2.0 * vnl_math::pi), double(this->GetMeasurementVectorSize()))) ; + vcl_pow(sqrt(2.0 * vnl_math::pi), double(this->GetMeasurementVectorSize()))) ; } } @@ -152,7 +152,7 @@ GaussianDensityFunction< TMeasurementVector > temp += tempVector2[i] * tempVector[i] ; } - return m_PreFactor * exp( -0.5 * temp ) ; + return m_PreFactor * vcl_exp(-0.5 * temp ) ; } else { diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkGaussianGoodnessOfFitComponent.txx b/Utilities/ITK/Code/Numerics/Statistics/itkGaussianGoodnessOfFitComponent.txx index d9f3125290..866efbcf4f 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkGaussianGoodnessOfFitComponent.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkGaussianGoodnessOfFitComponent.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkGaussianGoodnessOfFitComponent.txx,v $ Language: C++ - Date: $Date: 2005/07/26 15:54:55 $ - Version: $Revision: 1.10 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.11 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -226,7 +226,7 @@ GaussianGoodnessOfFitComponent< TInputSample > double mean = 0.0 ; double standardDeviation = 1.0 ; - double nx = fabs( x - mean ) / standardDeviation ; + double nx = vcl_fabs(x - mean ) / standardDeviation ; double t = 1 / (1 + 0.2316419 * nx); double tt = t*t; @@ -234,7 +234,7 @@ GaussianGoodnessOfFitComponent< TInputSample > double tttt = ttt*t; double ttttt = tttt*t; - double z = exp(-nx*nx/2) / sqrt(2*vnl_math::pi); + double z = vcl_exp(-nx*nx/2) / vcl_sqrt(2*vnl_math::pi); if ( x > mean ) { diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkGaussianMixtureModelComponent.txx b/Utilities/ITK/Code/Numerics/Statistics/itkGaussianMixtureModelComponent.txx index dfab7aee82..b8f82d9ab4 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkGaussianMixtureModelComponent.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkGaussianMixtureModelComponent.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkGaussianMixtureModelComponent.txx,v $ Language: C++ -Date: $Date: 2005/07/26 15:54:55 $ -Version: $Revision: 1.15 $ +Date: $Date: 2006/03/19 04:37:20 $ +Version: $Revision: 1.16 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -149,7 +149,7 @@ GaussianMixtureModelComponent< TSample > } } - changes = sqrt(changes) ; + changes = vcl_sqrt(changes) ; return changes ; } @@ -177,7 +177,7 @@ GaussianMixtureModelComponent< TSample > { temp = m_Mean[i] - meanEstimate[i] ; changes = temp * temp ; - changes = sqrt(changes) ; + changes = vcl_sqrt(changes) ; if ( changes > this->GetMinimalParametersChange() ) { changed = true ; @@ -210,7 +210,7 @@ GaussianMixtureModelComponent< TSample > temp = m_Covariance.GetVnlMatrix().get(i, j) - covEstimate.GetVnlMatrix().get(i, j) ; changes = temp * temp ; - changes = sqrt(changes) ; + changes = vcl_sqrt(changes) ; if ( changes > this->GetMinimalParametersChange() ) { changed = true ; diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkGoodnessOfFitFunctionBase.txx b/Utilities/ITK/Code/Numerics/Statistics/itkGoodnessOfFitFunctionBase.txx index 6c5c7de848..6ec31833f5 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkGoodnessOfFitFunctionBase.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkGoodnessOfFitFunctionBase.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkGoodnessOfFitFunctionBase.txx,v $ Language: C++ - Date: $Date: 2003/09/10 14:29:45 $ - Version: $Revision: 1.6 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.7 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -27,7 +27,7 @@ GoodnessOfFitFunctionBase< TInputHistogram > ::GoodnessOfFitFunctionBase() { m_Epsilon = 1e-20 ; - m_LogEpsilon = log(m_Epsilon) ; + m_LogEpsilon = vcl_log(m_Epsilon) ; m_UseExpectedHistogram = true ; m_ObservedHistogram = 0 ; diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkHistogram.txx b/Utilities/ITK/Code/Numerics/Statistics/itkHistogram.txx index 91216bdd21..75881b3e62 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkHistogram.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkHistogram.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkHistogram.txx,v $ Language: C++ - Date: $Date: 2005/09/30 14:14:18 $ - Version: $Revision: 1.41 $ + Date: $Date: 2006/06/09 19:11:56 $ + Version: $Revision: 1.41.8.1 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -137,85 +137,8 @@ inline const typename Histogram<TMeasurement, VMeasurementVectorSize, Histogram<TMeasurement, VMeasurementVectorSize, TFrequencyContainer> ::GetIndex(const MeasurementVectorType& measurement) const { - // now using something similar to binary search to find - // index. - unsigned int dim ; - - int begin, mid, end ; - MeasurementType median ; - MeasurementType tempMeasurement ; - - for (dim = 0 ; dim < MeasurementVectorSize ; dim++) - { - tempMeasurement = measurement[dim] ; - begin = 0 ; - if (tempMeasurement < m_Min[dim][begin]) - { - // one of measurement is below the minimum - if(!m_ClipBinsAtEnds) - { - m_TempIndex[dim] = (long) 0 ; - } - else - { - // If clipping and this is below, then set to an illegal value - // then set to m_Size[dim] to flag this as an illegal index; - // Must be set to m_Size[dim] since -1 might not be a valid value. - // This is why you must call IsIndexOutOfBounds before using the - // index returned by this function. - m_TempIndex[dim] = (long) m_Size[dim] ; - itkWarningMacro(<<"One of the measurements is below the minimum"); - } - } - - end = m_Min[dim].size() - 1 ; - if (tempMeasurement >= m_Max[dim][end]) - { - // one of measurement is above the maximum - if(!m_ClipBinsAtEnds) - { - m_TempIndex[dim] = (long) m_Size[dim] - 1; - } - else - { - // If clipping and this is below, then set to an illegal value - // then set to m_Size[dim] to flag this as an illegal index; - // Must be set to m_Size[dim] since -1 might not be a valid value. - // This is why you must call IsIndexOutOfBounds before using the - // index returned by this function. - m_TempIndex[dim] = (long) m_Size[dim] ; - itkWarningMacro(<<"One of the measurements is above the maximum"); - } - } - - mid = (end + 1) / 2 ; - median = m_Min[dim][mid] ; - while(true) - { - if (tempMeasurement < median ) - { - end = mid - 1 ; - } - else if (tempMeasurement > median) - { - if (tempMeasurement < m_Max[dim][mid]) - { - m_TempIndex[dim] = mid ; - break ; - } - - begin = mid + 1 ; - } - else - { - // measurement[dim] = m_Min[dim][med] - m_TempIndex[dim] = mid ; - break ; - } - mid = begin + (end - begin) / 2 ; - median = m_Min[dim][mid] ; - } // end of while - } // end of for() + // Have this deprecated method call the un-deprecated one.. + this->GetIndex( measurement, m_TempIndex ); return m_TempIndex; } @@ -242,16 +165,34 @@ bool Histogram<TMeasurement, VMeasurementVectorSize, TFrequencyContainer> if (tempMeasurement < m_Min[dim][begin]) { // one of measurement is below the minimum - index[dim] = (long) m_Size[dim] ; - return false; + // its ok if we extend the bins to infinity.. not ok if we don't + if(!m_ClipBinsAtEnds) + { + index[dim] = (long) 0 ; + continue; + } + else + { // set an illegal value and return 0 + index[dim] = (long) m_Size[dim]; + return false; + } } end = m_Min[dim].size() - 1 ; if (tempMeasurement >= m_Max[dim][end]) { - // one of measurement is above the maximum - index[dim] = (long) m_Size[dim] ; - return false; + // one of measurement is below the minimum + // its ok if we extend the bins to infinity.. not ok if we don't + if(!m_ClipBinsAtEnds) + { + index[dim] = (long) m_Size[dim]-1; + continue; + } + else + { // set an illegal value and return 0 + index[dim] = (long) m_Size[dim]; + return false; + } } mid = (end + 1) / 2 ; diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToEntropyImageFilter.h b/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToEntropyImageFilter.h index ff7f153739..f2b47910a4 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToEntropyImageFilter.h +++ b/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToEntropyImageFilter.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkHistogramToEntropyImageFilter.h,v $ Language: C++ - Date: $Date: 2005/04/08 20:45:48 $ - Version: $Revision: 1.4 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.5 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -72,13 +72,13 @@ public: { const double p = static_cast<OutputPixelType>(A) / static_cast<OutputPixelType>(m_TotalFrequency); - return static_cast<OutputPixelType>( (-1) * p * log(p) / log(2.0)); + return static_cast<OutputPixelType>( (-1) * p * vcl_log(p) / vcl_log(2.0)); } else { const double p = static_cast<OutputPixelType>(A+1) / static_cast<OutputPixelType>(m_TotalFrequency); - return static_cast<OutputPixelType>( (-1) * p * log(p) / log(2.0)); + return static_cast<OutputPixelType>( (-1) * p * vcl_log(p) / vcl_log(2.0)); } } diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToLogProbabilityImageFilter.h b/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToLogProbabilityImageFilter.h index 61df35d997..e67cf5c063 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToLogProbabilityImageFilter.h +++ b/Utilities/ITK/Code/Numerics/Statistics/itkHistogramToLogProbabilityImageFilter.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkHistogramToLogProbabilityImageFilter.h,v $ Language: C++ - Date: $Date: 2005/04/08 21:32:05 $ - Version: $Revision: 1.4 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.5 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -66,12 +66,12 @@ public: if( A ) { return static_cast<OutputPixelType>(log( static_cast<OutputPixelType>(A) / - static_cast<OutputPixelType>(m_TotalFrequency)) / log(2.0) ); + static_cast<OutputPixelType>(m_TotalFrequency)) / vcl_log(2.0) ); } else { // Check for Log 0. Always assume that the frequency is atleast 1. return static_cast<OutputPixelType>(log( static_cast<OutputPixelType>(A+1) / - static_cast<OutputPixelType>(m_TotalFrequency)) / log(2.0) ); + static_cast<OutputPixelType>(m_TotalFrequency)) / vcl_log(2.0) ); } } diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.h b/Utilities/ITK/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.h index c7c2ededf3..434159b8dc 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.h +++ b/Utilities/ITK/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkListSampleToHistogramGenerator.h,v $ Language: C++ - Date: $Date: 2005/08/24 15:16:48 $ - Version: $Revision: 1.13 $ + Date: $Date: 2006/03/14 22:52:18 $ + Version: $Revision: 1.14 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -22,6 +22,7 @@ #include "itkHistogram.h" #include "itkStatisticsAlgorithm.h" #include "itkDenseFrequencyContainer.h" +#include "itkNumericTraits.h" namespace itk{ namespace Statistics{ @@ -87,7 +88,11 @@ public: itkStaticConstMacro(MeasurementVectorSize, unsigned int, TMeasurementVectorLength); - typedef Histogram< THistogramMeasurement, + /** Type needed for defining the limits of the histogram bins */ + typedef typename NumericTraits< THistogramMeasurement >::RealType + HistogramMeasurementRealType; + + typedef Histogram< HistogramMeasurementRealType, itkGetStaticConstMacro(MeasurementVectorSize), TFrequencyContainer > HistogramType ; diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkLogLikelihoodGoodnessOfFitFunction.txx b/Utilities/ITK/Code/Numerics/Statistics/itkLogLikelihoodGoodnessOfFitFunction.txx index aa8be17598..00cac5cfbe 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkLogLikelihoodGoodnessOfFitFunction.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkLogLikelihoodGoodnessOfFitFunction.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkLogLikelihoodGoodnessOfFitFunction.txx,v $ Language: C++ - Date: $Date: 2004/09/11 00:15:16 $ - Version: $Revision: 1.10 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.11 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -52,7 +52,7 @@ LogLikelihoodGoodnessOfFitFunction< TInputHistogram > if ( ratio > this->GetEpsilon() && px > 0 ) { - sum += px * log(ratio); + sum += px * vcl_log(ratio); } else { diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkNormalVariateGenerator.cxx b/Utilities/ITK/Code/Numerics/Statistics/itkNormalVariateGenerator.cxx index 7967af5d7c..4d9a3fbd87 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkNormalVariateGenerator.cxx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkNormalVariateGenerator.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkNormalVariateGenerator.cxx,v $ Language: C++ - Date: $Date: 2004/04/19 19:33:48 $ - Version: $Revision: 1.14 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.15 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -87,11 +87,11 @@ void NormalVariateGenerator::Initialize(int randomSeed) // Z = (sqrt (1/2TLEN)) * A * (B + n) // where: // B = C / A. -// We set chic1 = A * sqrt (0.5 / TLEN), chic2 = B +// We set chic1 = A * vcl_sqrt(0.5 / TLEN), chic2 = B fake = 1.0 + 0.125 / TLEN; // This is A - chic2 = sqrt (2.0 * TLEN - fake*fake) / fake; - chic1 = fake * sqrt (0.5 / TLEN); + chic2 = vcl_sqrt(2.0 * TLEN - fake*fake) / fake; + chic1 = fake * vcl_sqrt(0.5 / TLEN); actualRSD = 0.0 ; return; @@ -324,16 +324,16 @@ double NormalVariateGenerator::FastNorm(void) irs = (irs <= 0) ? ((irs << 1) ^ 333556017):(irs << 1); r = irs + lseed; if (r < 0) r = ~r; - tz = -2.0 * log ((r + 0.5) * Rcons); /* Sum of squares */ + tz = -2.0 * vcl_log((r + 0.5) * Rcons); /* Sum of squares */ ts += tz; - tz = sqrt ( tz / tr ); + tz = vcl_sqrt(tz / tr ); vec1 [p++] = (int) (Scale * tx * tz) ; vec1 [p++] = (int) (Scale * ty * tz) ; if (p < TLEN) goto nextpair; /* Horrid, but good enough */ /* Calc correction factor to make sum of squares = TLEN */ ts = TLEN / ts; /* Should be close to 1.0 */ - tr = sqrt (ts); + tr = vcl_sqrt(ts); for (p = 0; p < TLEN; p++) { tx = vec1 [p] * tr; vec1 [p] = (int) ((tx < 0.0) ? (tx - 0.5) : (tx + 0.5)) ; @@ -347,7 +347,7 @@ double NormalVariateGenerator::FastNorm(void) ts += (tx * tx); } /* Now ts should be Scale*Scale*TLEN or thereabouts */ - ts = sqrt (ts / (Scale * Scale * TLEN)); + ts = vcl_sqrt(ts / (Scale * Scale * TLEN)); actualRSD = 1.0 / ts; /* Reciprocal of actual Standard Devtn */ goto startpass; diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkSampleToHistogramProjectionFilter.txx b/Utilities/ITK/Code/Numerics/Statistics/itkSampleToHistogramProjectionFilter.txx index 976ecce612..8c6aa77d0d 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkSampleToHistogramProjectionFilter.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkSampleToHistogramProjectionFilter.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkSampleToHistogramProjectionFilter.txx,v $ Language: C++ -Date: $Date: 2005/07/26 15:55:05 $ -Version: $Revision: 1.13 $ +Date: $Date: 2006/03/19 04:37:20 $ +Version: $Revision: 1.14 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -242,7 +242,7 @@ SampleToHistogramProjectionFilter< TInputSample, THistogramMeasurement > { if (minWeight < 1.0) { - minWeight = 1.0 / (1.0 + exp(-minWeight / scale)) ; + minWeight = 1.0 / (1.0 + vcl_exp(-minWeight / scale)) ; } else { @@ -251,7 +251,7 @@ SampleToHistogramProjectionFilter< TInputSample, THistogramMeasurement > if (maxWeight < 1.0) { - maxWeight = 1.0 / (1.0 + exp(-maxWeight / scale)) ; + maxWeight = 1.0 / (1.0 + vcl_exp(-maxWeight / scale)) ; } else { @@ -295,7 +295,7 @@ SampleToHistogramProjectionFilter< TInputSample, THistogramMeasurement > if (m_HistogramBinOverlap) { - scale = log(1.0 + m_HistogramBinOverlap / 10.0 ) ; + scale = vcl_log(1.0 + m_HistogramBinOverlap / 10.0 ) ; } typename HistogramType::InstanceIdentifier binId ; @@ -332,7 +332,7 @@ SampleToHistogramProjectionFilter< TInputSample, THistogramMeasurement > } marginalDistance = - sqrt(vnl_math_abs(squaredDistance - dotProduct * dotProduct)) / + vcl_sqrt(vnl_math_abs(squaredDistance - dotProduct * dotProduct)) / ((*m_StandardDeviation) * extent) ; dotProduct /= (*m_StandardDeviation) ; @@ -360,7 +360,7 @@ SampleToHistogramProjectionFilter< TInputSample, THistogramMeasurement > if ( marginalDistance > -1.0 ) { marginalDistance = - 1.0 / (1.0 + exp(-marginalDistance / scale)) ; + 1.0 / (1.0 + vcl_exp(-marginalDistance / scale)) ; for (binId = 0 ; binId <= (numberOfBins / 2UL) ; binId++) diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.h b/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.h index ef40a52b89..65076814c6 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.h +++ b/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkScalarImageToHistogramGenerator.h,v $ Language: C++ - Date: $Date: 2005/08/24 15:16:56 $ - Version: $Revision: 1.7 $ + Date: $Date: 2006/03/14 22:01:52 $ + Version: $Revision: 1.8 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -48,10 +48,11 @@ public: > AdaptorType; typedef typename AdaptorType::Pointer AdaptorPointer; typedef typename ImageType::PixelType PixelType; + typedef typename NumericTraits< PixelType >::RealType RealPixelType; typedef itk::Statistics::ListSampleToHistogramGenerator< AdaptorType, - PixelType, + RealPixelType, DenseFrequencyContainer > GeneratorType; @@ -80,6 +81,11 @@ public: /** Set marginal scale value to be passed to the histogram generator */ void SetMarginalScale( double marginalScale ); + /** Set the minimum value from which the bins will be computed */ + void SetHistogramMin( RealPixelType minimumValue ); + + /** Set the maximum value from which the bins will be computed */ + void SetHistogramMax( RealPixelType maximumValue ); protected: ScalarImageToHistogramGenerator(); diff --git a/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.txx b/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.txx index 21986bc2d2..8a1109360e 100644 --- a/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.txx +++ b/Utilities/ITK/Code/Numerics/Statistics/itkScalarImageToHistogramGenerator.txx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkScalarImageToHistogramGenerator.txx,v $ Language: C++ - Date: $Date: 2003/12/05 18:47:38 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/03/14 22:01:52 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -75,6 +75,30 @@ ScalarImageToHistogramGenerator< TImage > } +template < class TImage > +void +ScalarImageToHistogramGenerator< TImage > +::SetHistogramMin( RealPixelType minimumValue ) +{ + typedef typename GeneratorType::MeasurementVectorType MeasurementVectorType; + MeasurementVectorType minVector; + minVector[0] = minimumValue; + m_HistogramGenerator->SetHistogramMin( minVector ); +} + + +template < class TImage > +void +ScalarImageToHistogramGenerator< TImage > +::SetHistogramMax( RealPixelType maximumValue ) +{ + typedef typename GeneratorType::MeasurementVectorType MeasurementVectorType; + MeasurementVectorType maxVector; + maxVector[0] = maximumValue; + m_HistogramGenerator->SetHistogramMax( maxVector ); +} + + template < class TImage > void diff --git a/Utilities/ITK/Code/Numerics/itkCumulativeGaussianCostFunction.cxx b/Utilities/ITK/Code/Numerics/itkCumulativeGaussianCostFunction.cxx index 2ac0bb7458..8485f9380c 100644 --- a/Utilities/ITK/Code/Numerics/itkCumulativeGaussianCostFunction.cxx +++ b/Utilities/ITK/Code/Numerics/itkCumulativeGaussianCostFunction.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkCumulativeGaussianCostFunction.cxx,v $ Language: C++ - Date: $Date: 2003/12/15 14:13:19 $ - Version: $Revision: 1.11 $ + Date: $Date: 2006/03/19 04:37:19 $ + Version: $Revision: 1.12 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -66,7 +66,7 @@ CumulativeGaussianCostFunction double fitError = 0.0; for(int i = 0; i < (int)(numberOfElements); i++) { - fitError += pow((setTestArray->get(i) - m_OriginalDataArray->get(i)), 2); + fitError += vcl_pow((setTestArray->get(i) - m_OriginalDataArray->get(i)), 2); } return(sqrt((1/numberOfElements) * fitError)); } @@ -148,7 +148,7 @@ CumulativeGaussianCostFunction ::GetValue( const ParametersType & parameters ) const { for(unsigned int i = 0; i < m_RangeDimension; i++) - m_Measure[i] = parameters.get(2) + ((parameters.get(3)-parameters.get(2))*(EvaluateCumulativeGaussian((i-parameters.get(0))/(parameters.get(1)*sqrt(2.0)))+1)/2); + m_Measure[i] = parameters.get(2) + ((parameters.get(3)-parameters.get(2))*(EvaluateCumulativeGaussian((i-parameters.get(0))/(parameters.get(1)*vcl_sqrt(2.0)))+1)/2); return m_Measure; } @@ -160,7 +160,7 @@ CumulativeGaussianCostFunction m_MeasurePointer->SetSize(m_RangeDimension); for(unsigned int i = 0; i < m_RangeDimension; i++) - m_MeasurePointer->put(i, parameters.get(2) + ((parameters.get(3)-parameters.get(2))*(EvaluateCumulativeGaussian((i-parameters.get(0))/(parameters.get(1)*sqrt(2.0)))+1)/2)); + m_MeasurePointer->put(i, parameters.get(2) + ((parameters.get(3)-parameters.get(2))*(EvaluateCumulativeGaussian((i-parameters.get(0))/(parameters.get(1)*vcl_sqrt(2.0)))+1)/2)); return m_MeasurePointer; } diff --git a/Utilities/ITK/Code/Numerics/itkCumulativeGaussianOptimizer.cxx b/Utilities/ITK/Code/Numerics/itkCumulativeGaussianOptimizer.cxx index c0a04c6a15..8849ac7f7f 100644 --- a/Utilities/ITK/Code/Numerics/itkCumulativeGaussianOptimizer.cxx +++ b/Utilities/ITK/Code/Numerics/itkCumulativeGaussianOptimizer.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkCumulativeGaussianOptimizer.cxx,v $ Language: C++ - Date: $Date: 2003/12/15 14:13:19 $ - Version: $Revision: 1.14 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.15 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -59,7 +59,7 @@ CumulativeGaussianOptimizer for(int i=0; i<(int)(extendedArray->GetNumberOfElements()); i++) { - extendedArray->put(i, amplitude * exp( - ( pow((i-mean),2) / (2*pow(sd,2)) ) )); + extendedArray->put(i, amplitude * vcl_exp(- ( vcl_pow((i-mean),2) / (2*vcl_pow(sd,2)) ) )); } // Then insert the originalArray over the middle section of extendedArray. for(int i=0; i<(int)(originalArray->GetNumberOfElements()); i++) @@ -162,15 +162,15 @@ void CumulativeGaussianOptimizer // Calculate the standard deviation for(int i = 0; i < (int)(array->GetNumberOfElements()); i++) - m_ComputedStandardDeviation += array->get(i) * pow( (i - m_ComputedMean), 2); + m_ComputedStandardDeviation += array->get(i) * vcl_pow((i - m_ComputedMean), 2); - m_ComputedStandardDeviation = sqrt( m_ComputedStandardDeviation/sum ); + m_ComputedStandardDeviation = vcl_sqrt(m_ComputedStandardDeviation/sum ); // For the ERF, sum is the difference between the lower and upper intensities. m_ComputedTransitionHeight = sum; // Calculate the amplitude. - m_ComputedAmplitude = sum / (m_ComputedStandardDeviation * sqrt(2*3.14159265)); + m_ComputedAmplitude = sum / (m_ComputedStandardDeviation * vcl_sqrt(2*3.14159265)); } void @@ -208,7 +208,7 @@ CumulativeGaussianOptimizer if( i < startingPointForInsertion || i >= startingPointForInsertion + (int)(originalArray->GetNumberOfElements()) ) { - extendedArray->put(i, amplitude * exp(-(pow((i - mean),2) / (2 * pow(sd,2))))); + extendedArray->put(i, amplitude * vcl_exp(-(pow((i - mean),2) / (2 * vcl_pow(sd,2))))); } } return extendedArray; @@ -254,7 +254,7 @@ CumulativeGaussianOptimizer // Generate new Gaussian array with final parameters. for(int i = 0; i < sampledGaussianArraySize; i++) - sampledGaussianArray->put(i, m_ComputedAmplitude * exp( - ( pow((i-m_ComputedMean),2) / (2*pow(m_ComputedStandardDeviation,2)) ) )); + sampledGaussianArray->put(i, m_ComputedAmplitude * vcl_exp(- ( vcl_pow((i-m_ComputedMean),2) / (2*vcl_pow(m_ComputedStandardDeviation,2)) ) )); // Add 0.5 to the mean of the sampled Gaussian curve to make up for the 0.5 // shift during derivation, then take the integral of the Gaussian sample diff --git a/Utilities/ITK/Code/Numerics/itkFRPROptimizer.cxx b/Utilities/ITK/Code/Numerics/itkFRPROptimizer.cxx index b1802f7afa..d1e36b838d 100644 --- a/Utilities/ITK/Code/Numerics/itkFRPROptimizer.cxx +++ b/Utilities/ITK/Code/Numerics/itkFRPROptimizer.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFRPROptimizer.cxx,v $ Language: C++ - Date: $Date: 2005/04/27 15:08:57 $ - Version: $Revision: 1.5 $ + Date: $Date: 2006/05/25 13:41:42 $ + Version: $Revision: 1.7 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -19,14 +19,16 @@ #include "itkFRPROptimizer.h" -#define FRPR_TINY 1e-20 namespace itk { +const double FRPR_TINY = 1e-20; + FRPROptimizer ::FRPROptimizer() { + m_OptimizationType = PolakRibiere; } FRPROptimizer @@ -94,18 +96,20 @@ FRPROptimizer this->SetSpaceDimension(m_CostFunction->GetNumberOfParameters()); + const unsigned int SpaceDimension = this->GetSpaceDimension(); + double gg, gam, dgg; - FRPROptimizer::ParametersType g(this->GetSpaceDimension()); - FRPROptimizer::ParametersType h(this->GetSpaceDimension()); - FRPROptimizer::ParametersType xi(this->GetSpaceDimension()); + FRPROptimizer::ParametersType g( SpaceDimension ); + FRPROptimizer::ParametersType h( SpaceDimension ); + FRPROptimizer::ParametersType xi( SpaceDimension ); - FRPROptimizer::ParametersType p(this->GetSpaceDimension()); + FRPROptimizer::ParametersType p( SpaceDimension ); p = this->GetInitialPosition(); double fp; this->GetValueAndDerivative(p, &fp, &xi); - for(i=0; i<this->GetSpaceDimension(); i++) + for( i = 0; i < SpaceDimension ; i++ ) { g[i] = -xi[i]; xi[i] = g[i]; @@ -127,7 +131,7 @@ FRPROptimizer if ( 2.0 * vcl_abs(fret - fp) <= this->GetValueTolerance() * (vcl_abs(fret)+ vcl_abs(fp) + FRPR_TINY) ) { - if(limitCount < this->GetSpaceDimension()) + if( limitCount < SpaceDimension ) { this->GetValueAndDerivative(p, &fp, &xi); xi[limitCount] = 1; @@ -148,11 +152,22 @@ FRPROptimizer gg = 0.0; dgg = 0.0; - for(i=0; i<this->GetSpaceDimension(); i++) + + if( m_OptimizationType == PolakRibiere ) { - gg += g[i] * g[i]; - //dgg += xi[i] * xi[i]; // Uncomment for Fletcher-Reeves - dgg += (xi[i] + g[i]) * xi[i]; // Uncoment for Polak-Ribiere + for( i=0; i< SpaceDimension ; i++ ) + { + gg += g[i] * g[i]; + dgg += (xi[i] + g[i]) * xi[i]; + } + } + if( m_OptimizationType == FletchReeves ) + { + for( i=0; i< SpaceDimension ; i++ ) + { + gg += g[i] * g[i]; + dgg += xi[i] * xi[i]; + } } if(gg == 0) @@ -163,7 +178,7 @@ FRPROptimizer } gam = dgg/gg; - for(i=0; i<this->GetSpaceDimension(); i++) + for( i = 0; i < SpaceDimension ; i++) { g[i] = -xi[i]; xi[i] = g[i] + gam * h[i]; @@ -178,6 +193,28 @@ FRPROptimizer this->InvokeEvent( EndEvent() ); } +/** + * + */ +void +FRPROptimizer +::SetToPolakRibiere() +{ + m_OptimizationType = PolakRibiere; +} + + +/** + * + */ +void +FRPROptimizer +::SetToFletchReeves() +{ + m_OptimizationType = FletchReeves; +} + + /** * */ @@ -186,6 +223,8 @@ FRPROptimizer ::PrintSelf(std::ostream& os, Indent indent) const { Superclass::PrintSelf(os,indent); + os << indent << "Optimization Type = " << m_OptimizationType << std::endl; + os << indent << "0=FletchReeves, 1=PolakRibiere" << std::endl; } } // end of namespace itk diff --git a/Utilities/ITK/Code/Numerics/itkFRPROptimizer.h b/Utilities/ITK/Code/Numerics/itkFRPROptimizer.h index 24fd9e1953..54adc0c7c3 100644 --- a/Utilities/ITK/Code/Numerics/itkFRPROptimizer.h +++ b/Utilities/ITK/Code/Numerics/itkFRPROptimizer.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkFRPROptimizer.h,v $ Language: C++ - Date: $Date: 2005/03/22 00:13:48 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/05/25 13:41:42 $ + Version: $Revision: 1.2 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -71,11 +71,17 @@ public: typedef CostFunctionType::Pointer CostFunctionPointer; /** Start optimization. */ - void StartOptimization() ; + void StartOptimization(); + /** Set it to the Fletch-Reeves optimizer */ + void SetToFletchReeves(); + + /** Set it to the Fletch-Reeves optimizer */ + void SetToPolakRibiere(); + protected: FRPROptimizer() ; - virtual ~FRPROptimizer() ; + virtual ~FRPROptimizer(); void PrintSelf(std::ostream& os, Indent indent) const; @@ -92,6 +98,14 @@ protected: private: FRPROptimizer(const FRPROptimizer&) ; // not implemented + typedef enum + { + FletchReeves, + PolakRibiere + } OptimizationType; + + OptimizationType m_OptimizationType; + } ; // end of class } // end of namespace itk diff --git a/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.cxx b/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.cxx index ffc3e5744b..ea21ff5410 100644 --- a/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.cxx +++ b/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMultipleValuedNonLinearVnlOptimizer.cxx,v $ Language: C++ - Date: $Date: 2005/03/09 03:41:38 $ - Version: $Revision: 1.11 $ + Date: $Date: 2006/05/12 12:58:27 $ + Version: $Revision: 1.12 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -30,6 +30,12 @@ MultipleValuedNonLinearVnlOptimizer { m_CostFunctionAdaptor = 0; m_UseGradient = true; + m_Command = CommandType::New(); + m_Command->SetCallbackFunction( this, + &MultipleValuedNonLinearVnlOptimizer::IterationReport ); + m_CachedValue.Fill(0); + m_CachedCurrentPosition.Fill(0); + m_CachedDerivative.Fill(0); } @@ -68,6 +74,7 @@ MultipleValuedNonLinearVnlOptimizer this->SetUseCostFunctionGradient(m_UseGradient); + m_CostFunctionAdaptor->AddObserver( IterationEvent(), m_Command ); } @@ -131,6 +138,42 @@ MultipleValuedNonLinearVnlOptimizer +/** The purpose of this method is to get around the lack of iteration reporting + * in VNL optimizers. By interfacing directly with the ITK cost function + * adaptor we are generating here Iteration Events. Note the iteration events + * here are produce PER EVALUATION of the metric, not per real iteration of the + * vnl optimizer. Optimizers that evaluate the metric multiple times at each + * iteration will generate a lot more of Iteration events here. */ +void +MultipleValuedNonLinearVnlOptimizer +::IterationReport( const EventObject & event ) +{ + const CostFunctionAdaptorType * adaptor = this->GetCostFunctionAdaptor(); + m_CachedValue = adaptor->GetCachedValue(); + m_CachedDerivative = adaptor->GetCachedDerivative(); + m_CachedCurrentPosition = adaptor->GetCachedCurrentParameters(); + this->InvokeEvent( event ); +} + + +/** + * PrintSelf + */ +void +MultipleValuedNonLinearVnlOptimizer +::PrintSelf(std::ostream& os, Indent indent) const +{ + Superclass::PrintSelf( os, indent ); + os << indent << "Cached Value: " << m_CachedValue << std::endl; + os << indent << "Cached Derivative: " << m_CachedDerivative << std::endl; + os << indent << "Cached current positiion: " + << m_CachedCurrentPosition << std::endl; + os << "Command observer " << m_Command.GetPointer() << std::endl; + os << "Cost Function adaptor" << m_CostFunctionAdaptor << std::endl; +} + + + } // end namespace itk diff --git a/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.h b/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.h index ab137c9b85..d365e813f5 100644 --- a/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.h +++ b/Utilities/ITK/Code/Numerics/itkMultipleValuedNonLinearVnlOptimizer.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMultipleValuedNonLinearVnlOptimizer.h,v $ Language: C++ - Date: $Date: 2005/09/24 21:20:58 $ - Version: $Revision: 1.23 $ + Date: $Date: 2006/05/12 12:58:27 $ + Version: $Revision: 1.24 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -19,6 +19,7 @@ #include "itkMultipleValuedNonLinearOptimizer.h" #include "itkMultipleValuedVnlCostFunctionAdaptor.h" +#include "itkCommand.h" namespace itk @@ -67,10 +68,21 @@ public: void UseCostFunctionGradientOff() { this->SetUseCostFunctionGradient( false ); }; bool GetUseCostFunctionGradient() const; + /** Return Cached Values. These method have the advantage of not triggering a + * recomputation of the metric value, but it has the disadvantage of returning + * a value that may not be the one corresponding to the current parameters. For + * GUI update purposes, this method is a good option, for mathematical + * validation you should rather call GetValue(). */ + itkGetConstReferenceMacro(CachedValue, MeasureType); + itkGetConstReferenceMacro(CachedDerivative, DerivativeType); + itkGetConstReferenceMacro(CachedCurrentPosition, ParametersType); + protected: MultipleValuedNonLinearVnlOptimizer(); virtual ~MultipleValuedNonLinearVnlOptimizer(); + void PrintSelf(std::ostream& os, Indent indent) const; + typedef MultipleValuedVnlCostFunctionAdaptor CostFunctionAdaptorType; void SetCostFunctionAdaptor( CostFunctionAdaptorType * adaptor ); @@ -81,12 +93,28 @@ protected: * correctness in vnl cost_functions and optimizers */ CostFunctionAdaptorType * GetNonConstCostFunctionAdaptor( void ) const; + /** Command observer that will interact with the ITK-VNL cost-function + * adaptor in order to generate iteration events. This will allow to overcome + * the limitation of VNL optimizers not offering callbacks for every + * iteration */ + typedef ReceptorMemberCommand< Self > CommandType; + private: MultipleValuedNonLinearVnlOptimizer(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented + /** Callback function for the Command Observer */ + void IterationReport( const EventObject & event ); + CostFunctionAdaptorType * m_CostFunctionAdaptor; bool m_UseGradient; + + CommandType::Pointer m_Command; + + mutable ParametersType m_CachedCurrentPosition; + mutable MeasureType m_CachedValue; + mutable DerivativeType m_CachedDerivative; + }; } // end namespace itk diff --git a/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.cxx b/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.cxx index 9d682bc152..61d4c48df8 100644 --- a/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.cxx +++ b/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMultipleValuedVnlCostFunctionAdaptor.cxx,v $ Language: C++ - Date: $Date: 2004/08/15 12:26:38 $ - Version: $Revision: 1.10 $ + Date: $Date: 2006/05/12 12:58:27 $ + Version: $Revision: 1.12 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -29,6 +29,7 @@ MultipleValuedVnlCostFunctionAdaptor vnl_least_squares_function(spaceDimension,numberOfValues) { m_ScalesInitialized =false; + m_Reporter = Object::New(); } @@ -71,6 +72,11 @@ MultipleValuedVnlCostFunctionAdaptor measures = m_CostFunction->GetValue( parameters ); + // Notify observers. This is used for overcoming the limitaion of VNL + // optimizers of not providing callbacks per iteration. + m_CachedValue = measures; + m_CachedCurrentParameters = parameters; + this->ReportIteration( FunctionEvaluationIterationEvent() ); } @@ -114,7 +120,7 @@ MultipleValuedVnlCostFunctionAdaptor void MultipleValuedVnlCostFunctionAdaptor ::compute( const InternalParametersType & x, - InternalMeasureType * f, + InternalMeasureType * ff, InternalDerivativeType * g ) { // delegate the computation to the CostFunction @@ -132,11 +138,19 @@ MultipleValuedVnlCostFunctionAdaptor parameters.SetData(const_cast<double*>(x.data_block())); } - *f = static_cast<InternalMeasureType>( + *ff = static_cast<InternalMeasureType>( m_CostFunction->GetValue( parameters ) ); m_CostFunction->GetDerivative( parameters, externalGradient ); ConvertExternalToInternalGradient( externalGradient, *g ); + + // Notify observers. This is used for overcoming the limitaion of VNL + // optimizers of not providing callbacks per iteration. + // Note that m_CachedDerivative is already loaded in the GetDerivative() above. + m_CachedValue = *ff; + m_CachedCurrentParameters = parameters; + this->ReportIteration( FunctionAndGradientEvaluationIterationEvent() ); + } /** Convert external derviative measures into internal type */ @@ -196,6 +210,53 @@ MultipleValuedVnlCostFunctionAdaptor +/** This method reports iterations events. It is intended to + * help monitoring the progress of the optimization process. */ +void +MultipleValuedVnlCostFunctionAdaptor +::ReportIteration( const EventObject & event ) const +{ + this->m_Reporter->InvokeEvent( event ); +} + + + +/** Connects a Command/Observer to the internal reporter class. + * This is useful for reporting iteration event to potential observers. */ +unsigned long +MultipleValuedVnlCostFunctionAdaptor +::AddObserver(const EventObject & event, Command * command) const +{ + return m_Reporter->AddObserver( event, command ); +} + + +/** Return the cached value of the cost function */ +const MultipleValuedVnlCostFunctionAdaptor::MeasureType & +MultipleValuedVnlCostFunctionAdaptor +::GetCachedValue() const +{ + return m_CachedValue; +} + + +/** Return the cached value of the cost function derivative */ +const MultipleValuedVnlCostFunctionAdaptor::DerivativeType & +MultipleValuedVnlCostFunctionAdaptor +::GetCachedDerivative() const +{ + return m_CachedDerivative; +} + +/** Return the cached value of the parameters used for computing the function */ +const MultipleValuedVnlCostFunctionAdaptor::ParametersType & +MultipleValuedVnlCostFunctionAdaptor +::GetCachedCurrentParameters() const +{ + return m_CachedCurrentParameters; +} + + } // end namespace itk diff --git a/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.h b/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.h index 4556dfb4b5..2a6f2e4230 100644 --- a/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.h +++ b/Utilities/ITK/Code/Numerics/itkMultipleValuedVnlCostFunctionAdaptor.h @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkMultipleValuedVnlCostFunctionAdaptor.h,v $ Language: C++ - Date: $Date: 2004/03/14 17:43:02 $ - Version: $Revision: 1.5 $ + Date: $Date: 2006/05/12 12:58:27 $ + Version: $Revision: 1.6 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -105,12 +105,38 @@ public: /** Set current parameters scaling. */ void SetScales(const ScalesType & scales); + /** This AddObserver method allows to simulate that this class derives from + * an itkObject for the purpose of reporting iteration events. The goal of + * this method is to allow ITK-vnl optimizer adaptors to get iteration events + * despite the fact that VNL does not provide callbacks. */ + unsigned long AddObserver(const EventObject & event, Command *) const; + + /** Return the value of the last evaluation to the value of the cost function. + * Note that this method DOES NOT triggers a computation of the function or + * the derivatives, it only returns previous values. Therefore the values here + * are only valid after you invoke the f() or gradf() methods. */ + const MeasureType & GetCachedValue() const; + const DerivativeType & GetCachedDerivative() const; + const ParametersType & GetCachedCurrentParameters() const; + +protected: + + /** This method is intended to be called by the derived classes in order to + * notify of an iteration event to any Command/Observers */ + void ReportIteration( const EventObject & event ) const; + + private: MultipleValuedCostFunction::Pointer m_CostFunction; + bool m_ScalesInitialized; ScalesType m_Scales; + Object::Pointer m_Reporter; + mutable MeasureType m_CachedValue; + mutable DerivativeType m_CachedDerivative; + mutable ParametersType m_CachedCurrentParameters; }; // end of Class CostFunction diff --git a/Utilities/ITK/Code/Numerics/itkOnePlusOneEvolutionaryOptimizer.cxx b/Utilities/ITK/Code/Numerics/itkOnePlusOneEvolutionaryOptimizer.cxx index d3aeb62715..ee3cc26025 100644 --- a/Utilities/ITK/Code/Numerics/itkOnePlusOneEvolutionaryOptimizer.cxx +++ b/Utilities/ITK/Code/Numerics/itkOnePlusOneEvolutionaryOptimizer.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkOnePlusOneEvolutionaryOptimizer.cxx,v $ Language: C++ - Date: $Date: 2005/03/07 03:39:58 $ - Version: $Revision: 1.32 $ + Date: $Date: 2006/03/19 04:37:20 $ + Version: $Revision: 1.33 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -32,7 +32,7 @@ OnePlusOneEvolutionaryOptimizer m_Initialized = false ; m_GrowthFactor = 1.05 ; - m_ShrinkFactor = pow(m_GrowthFactor, -0.25) ; + m_ShrinkFactor = vcl_pow(m_GrowthFactor, -0.25) ; m_InitialRadius = 1.01 ; m_MaximumIteration = 100 ; m_Stop = false ; @@ -69,7 +69,7 @@ OnePlusOneEvolutionaryOptimizer m_GrowthFactor = grow ; if (shrink == -1) - m_ShrinkFactor = pow(m_GrowthFactor, -0.25) ; + m_ShrinkFactor = vcl_pow(m_GrowthFactor, -0.25) ; else m_ShrinkFactor = shrink ; } diff --git a/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.cxx b/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.cxx index 95a9e35301..bc69ac9ac7 100644 --- a/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.cxx +++ b/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.cxx @@ -6,7 +6,6 @@ #include "itkEventObject.h" #include "itkExceptionObject.h" -#include "vnl/vnl_sample.h" #include "vnl/vnl_math.h" @@ -37,6 +36,7 @@ namespace itk m_A = m_MaximumNumberOfIterations / 10; m_Alpha = 0.602; m_Gamma = 0.101; + m_Generator = Statistics::MersenneTwisterRandomVariateGenerator::New(); } // end Constructor @@ -336,7 +336,9 @@ namespace itk for ( unsigned int j = 0; j < spaceDimension; j++ ) { /** Generate randomly -1 or 1. */ - m_Delta[ j ] = 2 * vnl_math_rnd( vnl_sample_uniform(0.0f,1.0f) ) - 1; + // m_Delta[ j ] = 2 * vnl_math_rnd( vnl_sample_uniform(0.0f,1.0f) ) - 1; + + m_Delta[ j ] = 2 * vnl_math_rnd ( this->m_Generator->GetUniformVariate (0.0f, 1.0f) ) - 1; /** * Take scales into account. The perturbation of a parameter that has a @@ -491,7 +493,7 @@ namespace itk this->ComputeGradient(initialPosition, m_Gradient); for ( unsigned int j = 0; j < spaceDimension; j++ ) { - averageAbsoluteGradient[j] += fabs(m_Gradient[j]); + averageAbsoluteGradient[j] += vcl_fabs(m_Gradient[j]); } } // end for ++n averageAbsoluteGradient /= static_cast<double>(numberOfGradientEstimates); diff --git a/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.h b/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.h index 9ee17c1d48..4a78354198 100644 --- a/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.h +++ b/Utilities/ITK/Code/Numerics/itkSPSAOptimizer.h @@ -2,6 +2,7 @@ #define __itkSPSAOptimizer_h #include "itkSingleValuedNonLinearOptimizer.h" +#include "itkMersenneTwisterRandomVariateGenerator.h" namespace itk @@ -186,6 +187,9 @@ namespace itk StopConditionType m_StopCondition; double m_StateOfConvergence; unsigned long m_CurrentIteration; + + /** Random number generator */ + Statistics::MersenneTwisterRandomVariateGenerator::Pointer m_Generator; /** Method to compute the learning rate at iteration k (a_k).*/ virtual double Compute_a( unsigned long k ) const; diff --git a/Utilities/ITK/Code/Numerics/itkSingleValuedNonLinearVnlOptimizer.cxx b/Utilities/ITK/Code/Numerics/itkSingleValuedNonLinearVnlOptimizer.cxx index fda071a951..88242f6d34 100644 --- a/Utilities/ITK/Code/Numerics/itkSingleValuedNonLinearVnlOptimizer.cxx +++ b/Utilities/ITK/Code/Numerics/itkSingleValuedNonLinearVnlOptimizer.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkSingleValuedNonLinearVnlOptimizer.cxx,v $ Language: C++ - Date: $Date: 2005/07/26 16:17:41 $ - Version: $Revision: 1.14 $ + Date: $Date: 2006/05/12 12:58:27 $ + Version: $Revision: 1.15 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -29,7 +29,8 @@ SingleValuedNonLinearVnlOptimizer m_CostFunctionAdaptor = 0; m_Maximize = false; m_Command = CommandType::New(); - m_Command->SetCallbackFunction( this, &SingleValuedNonLinearVnlOptimizer::IterationReport ); + m_Command->SetCallbackFunction( this, + &SingleValuedNonLinearVnlOptimizer::IterationReport ); m_CachedValue = 0; m_CachedCurrentPosition.Fill(0); m_CachedDerivative.Fill(0); diff --git a/Utilities/ITK/Code/Numerics/itkSingleValuedVnlCostFunctionAdaptor.cxx b/Utilities/ITK/Code/Numerics/itkSingleValuedVnlCostFunctionAdaptor.cxx index 22adb4c4f7..55237fd5e4 100644 --- a/Utilities/ITK/Code/Numerics/itkSingleValuedVnlCostFunctionAdaptor.cxx +++ b/Utilities/ITK/Code/Numerics/itkSingleValuedVnlCostFunctionAdaptor.cxx @@ -3,8 +3,8 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkSingleValuedVnlCostFunctionAdaptor.cxx,v $ Language: C++ - Date: $Date: 2005/03/30 22:26:05 $ - Version: $Revision: 1.18 $ + Date: $Date: 2006/05/12 12:58:27 $ + Version: $Revision: 1.19 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. @@ -211,8 +211,8 @@ SingleValuedVnlCostFunctionAdaptor return m_NegateCostFunction; } -/** Returns whether the cost function is going to be negated or not. - * This is useful for adapting optimizers that are only minimizers. */ +/** This method reports iterations events. It is intended to + * help monitoring the progress of the optimization process. */ void SingleValuedVnlCostFunctionAdaptor ::ReportIteration( const EventObject & event ) const @@ -259,7 +259,6 @@ SingleValuedVnlCostFunctionAdaptor - } // end namespace itk -- GitLab