freOnePlusOneEvolutionarySOOptimizer.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freOnePlusOneEvolutionarySOOptimizer.h,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 
00023 #include "freOnePlusOneEvolutionarySOOptimizer.h"
00024 #include "itkCommand.h"
00025 #include "itkEventObject.h"
00026 
00027 namespace FREE
00028 {
00029 
00030 OnePlusOneEvolutionarySOOptimizer
00031 ::OnePlusOneEvolutionarySOOptimizer()
00032 {
00033         m_ItkOptimizer = ItkOptimizerType::New();
00034         m_CostFunctionWrapper = ItkSingleValuedCostFunctionWrapper::New();
00035 
00036         this->SetMaximize(false);
00037         this->SetMaximumIteration(500);
00038         this->SetGrowthFactor(1.05);
00039         this->SetShrinkFactor(pow(1.05, -0.25));
00040         this->SetInitialRadius(1.01);
00041         this->SetEpsilon((double) 1.5e-4);
00042 
00043         m_IterationObserver = IterationObserver::New();
00044         m_IterationNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnOptIteration);
00045         m_IterationObserver->fnOnNotify = m_IterationNotificationEvent;
00046         m_ItkOptimizer->AddObserver(itk::IterationEvent(), m_IterationObserver);
00047 
00048         m_StartObserver = StartObserver::New();
00049         m_StartNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnOptStart);
00050         m_StartObserver->fnOnNotify = m_StartNotificationEvent;
00051         m_ItkOptimizer->AddObserver(itk::StartEvent(), m_StartObserver);
00052 
00053         m_EndObserver = EndObserver::New();
00054         m_EndNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnOptEnd);
00055         m_EndObserver->fnOnNotify = m_EndNotificationEvent;
00056         m_ItkOptimizer->AddObserver(itk::EndEvent(), m_EndObserver);
00057 }
00058 
00059 OnePlusOneEvolutionarySOOptimizer
00060 ::~OnePlusOneEvolutionarySOOptimizer()
00061 {
00062 }
00063 
00064 void
00065 OnePlusOneEvolutionarySOOptimizer::
00066 SetMaximize(bool maximize)
00067 {
00068         m_ItkOptimizer->SetMaximize(maximize);
00069         this->Modified();
00070 };
00071 
00072 void
00073 OnePlusOneEvolutionarySOOptimizer::
00074 SetMaximumIteration(unsigned int maximumIteration)
00075 {
00076         m_ItkOptimizer->SetMaximumIteration(maximumIteration);
00077         this->Modified();
00078 };
00079 
00080 const unsigned int&
00081 OnePlusOneEvolutionarySOOptimizer::
00082 GetMaximumIteration() const
00083 {
00084         return m_ItkOptimizer->GetMaximumIteration();
00085 };
00086 
00087 void
00088 OnePlusOneEvolutionarySOOptimizer::
00089 SetGrowthFactor(double growthFactor)
00090 {
00091         m_ItkOptimizer->SetGrowthFactor(growthFactor);
00092         this->Modified();
00093 };
00094 
00095 const double&
00096 OnePlusOneEvolutionarySOOptimizer::
00097 GetGrowthFactor() const
00098 {
00099         return m_ItkOptimizer->GetGrowthFactor();
00100 };
00101 
00102 void
00103 OnePlusOneEvolutionarySOOptimizer::
00104 SetShrinkFactor(double shrinkFactor)
00105 {
00106         m_ItkOptimizer->SetShrinkFactor(shrinkFactor);
00107         this->Modified();
00108 };
00109 
00110 const double&
00111 OnePlusOneEvolutionarySOOptimizer::
00112 GetShrinkFactor() const
00113 {
00114         return m_ItkOptimizer->GetShrinkFactor();
00115 };
00116 
00117 void
00118 OnePlusOneEvolutionarySOOptimizer::
00119 SetInitialRadius(double initialRadius)
00120 {
00121         m_ItkOptimizer->SetInitialRadius(initialRadius);
00122         this->Modified();
00123 };
00124 
00125 const double&
00126 OnePlusOneEvolutionarySOOptimizer::
00127 GetInitialRadius() const
00128 {
00129         return m_ItkOptimizer->GetInitialRadius();
00130 };
00131 
00132 void
00133 OnePlusOneEvolutionarySOOptimizer::
00134 SetEpsilon(double epsilon)
00135 {
00136         m_ItkOptimizer->SetEpsilon(epsilon);
00137         this->Modified();
00138 };
00139 
00140 const double&
00141 OnePlusOneEvolutionarySOOptimizer::
00142 GetEpsilon() const
00143 {
00144         return m_ItkOptimizer->GetEpsilon();
00145 };
00146 
00147 const double&
00148 OnePlusOneEvolutionarySOOptimizer::
00149 GetFrobeniusNorm() const
00150 {
00151         return m_ItkOptimizer->GetFrobeniusNorm();
00152 };
00153 
00154 void
00155 OnePlusOneEvolutionarySOOptimizer::
00156 SetCostFunction( CostFunctionType * costFunction )
00157 {
00158         Superclass::SetCostFunction(costFunction);
00159         m_CostFunctionWrapper->SetWrappedCostFunction(costFunction);
00160         m_ItkOptimizer->SetCostFunction(m_CostFunctionWrapper);
00161 };
00162 
00163 void
00164 OnePlusOneEvolutionarySOOptimizer::
00165 SetInitialPosition (const ParametersType &param)
00166 {
00167         Superclass::SetInitialPosition(param);
00168         m_ItkOptimizer->SetInitialPosition(param);
00169 };
00170 
00171 void
00172 OnePlusOneEvolutionarySOOptimizer::
00173 SetNormalVariateGenerator(NormalVariateGeneratorType* generator)
00174 {
00175         m_ItkOptimizer->SetNormalVariateGenerator(generator);
00176         this->Modified();
00177 };
00178 
00179 void
00180 OnePlusOneEvolutionarySOOptimizer::
00181 Initialize(double initialRadius, double grow, double shrink)
00182 {
00183         m_ItkOptimizer->Initialize(initialRadius, grow, shrink);
00184 };
00185 
00186 void
00187 OnePlusOneEvolutionarySOOptimizer
00188 ::PrintSelf(std::ostream& os, itk::Indent indent) const
00189 {
00190   Superclass::PrintSelf(os,indent);
00191 
00192   os << indent << "Maximum Iteration " << GetMaximumIteration() << std::endl;
00193   os << indent << "Epsilon           " << GetEpsilon()          << std::endl;
00194   os << indent << "Initial Radius    " << GetInitialRadius()    << std::endl;
00195   os << indent << "Growth Fractor    " << GetGrowthFactor()     << std::endl;
00196   os << indent << "Shrink Fractor    " << GetShrinkFactor()     << std::endl;
00197   os << indent << "Current Cost      " << this->m_ItkOptimizer->GetCurrentCost()     << std::endl;
00198         os << indent << "Current Iteration " << this->m_ItkOptimizer->GetCurrentIteration() << std::endl;
00199 }
00200 
00201 void
00202 OnePlusOneEvolutionarySOOptimizer
00203 ::StartOptimization( void )
00204 {
00205         this->m_ItkOptimizer->SetScales(this->GetScales());
00206         this->m_ItkOptimizer->StartOptimization();
00207 
00208         //for 1+1 optimizer the most recent individual is allways the fittest.
00209         //to achieve proper handling of optimizations with 0 generations
00210         //(thus no iteration events) the values are also set at the end of
00211         //the optimization process explicitly.
00212         this->m_CurrentValue = this->m_ItkOptimizer->GetCurrentCost();
00213         this->m_CurrentChildValue = this->m_CostFunction->GetCurrentValue();
00214         this->m_CurrentDecomposedValue = this->m_CostFunction->GetCurrentDecomposedValue();
00215         this->SetCurrentPosition(this->m_ItkOptimizer->GetCurrentPosition());
00216         this->m_CurrentChildPosition = this->m_CostFunction->GetCurrentParameters();
00217 
00218         m_BestValue = m_CurrentValue;
00219         m_BestPosition = this->m_ItkOptimizer->GetCurrentPosition();
00220 }
00221 
00222 void
00223 OnePlusOneEvolutionarySOOptimizer
00224 ::StopOptimization( void )
00225 {
00226         this->m_ItkOptimizer->StopOptimization();
00227 }
00228 
00229 bool
00230 OnePlusOneEvolutionarySOOptimizer
00231 ::IsStoppable() const
00232 {
00233   return true;
00234 };
00235 
00236 OnePlusOneEvolutionarySOOptimizer::ItkOptimizerType * 
00237 OnePlusOneEvolutionarySOOptimizer
00238 ::GetItkOptimizer()
00239 {
00240   return m_ItkOptimizer;
00241 }
00242 
00243 void
00244 OnePlusOneEvolutionarySOOptimizer::
00245 OnOptIteration(void* pSender, long threadID)
00246 {
00247         this->m_CurrentValue = this->m_ItkOptimizer->GetCurrentCost();
00248         this->m_CurrentChildValue = this->m_CostFunction->GetCurrentValue();
00249         this->m_CurrentDecomposedValue = this->m_CostFunction->GetCurrentDecomposedValue();
00250         this->SetCurrentPosition(this->m_ItkOptimizer->GetCurrentPosition());
00251         this->m_CurrentChildPosition = this->m_CostFunction->GetCurrentParameters();
00252 
00253         m_BestValue = m_CurrentValue;
00254         m_BestPosition = this->m_ItkOptimizer->GetCurrentPosition();
00255         
00256         //and pass the signal to the rest of the world
00257         this->InvokeEvent( itk::IterationEvent() );
00258 };
00259 
00260 void
00261 OnePlusOneEvolutionarySOOptimizer::
00262 OnOptStart(void* pSender, long threadID)
00263 {
00264         //just pass the signal to the rest of the world
00265         this->InvokeEvent( itk::StartEvent() );
00266 };
00267   
00268 void
00269 OnePlusOneEvolutionarySOOptimizer::
00270 OnOptEnd(void* pSender, long threadID)
00271 {
00272         //just pass the signal to the rest of the world
00273         this->InvokeEvent( itk::EndEvent() );
00274 };
00275 
00276 } // end namespace FREE
00277 
00278 

Generated at Sat Oct 13 16:51:34 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000