freESAdaptiveScaleMutation.txx

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: freESAdaptiveScaleMutation.txx,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 #ifndef _freESAdaptiveScaleMutation_txx
00023 #define _freESAdaptiveScaleMutation_txx
00024 
00025 #include "freESAdaptiveScaleMutation.h"
00026 
00027 namespace FREE
00028 {
00029 namespace ES
00030 {
00031 
00032 template <class TIndividual>
00033 AdaptiveScaleMutation<TIndividual>
00034 ::AdaptiveScaleMutation()
00035 {
00036 }
00037 
00038 template <class TIndividual>
00039 double
00040 AdaptiveScaleMutation<TIndividual>
00041 ::MutateValue(const double& value)
00042 {
00043     double mutatedValue = value;
00044     mutatedValue += ((this->m_RandomGenerator->GetVariate())*(this->m_MutateValueVariance))/this->m_MutateValueScale;
00045     return mutatedValue;
00046 };
00047 
00048 template <class TIndividual>
00049 void
00050 AdaptiveScaleMutation<TIndividual>
00051 ::MutateObjectivParameters(IndividualType* pIndividual, PopulationType* pPopulation) const
00052 {
00053   if (!pIndividual) throwExceptionMacro("Error. Passed individual is Null.");
00054 
00055   //get the strategic parameters
00056   typename IndividualType::StrategicParametersType::SelectedParametersType parameters =
00057     pIndividual->StrategicParameters().GetStrategicParameters(this->GetNameOfClass());
00058 
00059   if (parameters.size()!=pIndividual->ObjectiveParameters().size()) throwExceptionMacro("Error. Number of objective parameters and related strategic parameters are not equal. Ensure that strategic parameters are properly registered. Objective count:" << pIndividual->ObjectiveParameters().size() <<"; strategic count: "<< parameters.size());
00060   if (parameters.size()!=this->m_GeneralObjectiveScales.size()) throwExceptionMacro("Error. Number of objective parameters and global scales are not equal. Ensure that scales have been set properly. Objective count:" << pIndividual->ObjectiveParameters().size() <<"; objective scales count: "<< this->m_GeneralObjectiveScales.size());
00061 
00062   //mutate all parameters
00063   for (unsigned long index = 0; index<pIndividual->ObjectiveParameters().size(); index++)
00064   {
00065     const typename IndividualType::StrategicParameterValueType variance = (parameters[index])->GetValue();
00066     const double variate = this->m_RandomGenerator->GetVariate();
00067     typename IndividualType::ObjectiveParameterType mutatedParameter = (pIndividual->ObjectiveParameters())[index];
00068 
00069     double scaling = 1.0;
00070 
00071     //calculate the scaling
00072     if (variate<0.0)
00073     {
00074       scaling = 1/(1-(variate * variance * (this->m_GeneralObjectiveScales[index])));
00075     }
00076     else
00077     {
00078       scaling = 1+(variate * variance * (this->m_GeneralObjectiveScales[index]));
00079     }
00080 
00081     //mutate parameter
00082     mutatedParameter *= scaling;
00083     
00084     //set new value;
00085     (pIndividual->ObjectiveParameters())[index] = mutatedParameter;
00086   }
00087 };
00088 
00089 
00090 } // end of namespace ES
00091 } // end of namespace FREE
00092 
00093 #endif

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