00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "freOnePlusOneEvolutionaryOptimizerController.h"
00023 #include "freExceptions.h"
00024
00025 namespace FREE
00026 {
00027
00031
00032
00033 OnePlusOneEvolutionaryOptimizerController::
00034 OnePlusOneEvolutionaryOptimizerController()
00035 {
00036
00037 this->UpdateControllerID(ControllerID::OnePlusOneEvolutionaryOptimizerController);
00038 this->m_Description = "Optimizes by a 1+1-evolutionary approach.";
00039 };
00040
00041 void
00042 OnePlusOneEvolutionaryOptimizerController::
00043 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00044 const SessionComponentCache* pComponentCache,
00045 bool bRegardOldSetup) const
00046 {
00047 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00048
00049
00050 profile.Parameters().AddParameter("GrowthFactor",CtrlProfile::Parameter::PVTDouble,"Growth factor for the search radius.",1,"0.01",-1,true);
00051 profile.Parameters().AddParameter("ShrinkFactor",CtrlProfile::Parameter::PVTDouble,"Shrink factor for the search radius.",1,"0.01",-1,true);
00052 profile.Parameters().AddParameter("InitialRadius",CtrlProfile::Parameter::PVTDouble,"Search radius in parameter space.",1,"1.0",-1,true);
00053 profile.Parameters().AddParameter("Epsilon",CtrlProfile::Parameter::PVTDouble,"Treshold of the vrobenius_norm for stopping optimization before hitting the maximum iterations.",1,"0.0001",-1,true);
00054 profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"100",-1,true);
00055
00056
00057 profile.SubComponents().AddSubComponent("VariateGenerator",1,"Normal Variate Generator");
00058
00059
00060 CtrlProfile::ProfileOption* pOption;
00061
00062 pOption = profile.Requirements().AddRequirement("VariateGenerator")->AddProfileOption();
00063 pOption->Inheritance().AddAncestor("VariateGeneratorBase");
00064 pOption->CheckForInheritance();
00065 };
00066
00067 GenericComponentType*
00068 OnePlusOneEvolutionaryOptimizerController::
00069 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00070 SessionComponentCache* pMainComponentCache) const
00071 {
00072 if (compID == "VariateGenerator") throwCtrlExceptionMacro("","1+1 evolutionary optimizer hasa no getter function for variate generator. Use session to retrieve component.");
00073 return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00074 };
00075
00076 void
00077 OnePlusOneEvolutionaryOptimizerController::
00078 SetSubComponentCasted(GenericComponentType* pSubComponent,
00079 ComponentType* pMainComponent,
00080 const ComponentID compID,
00081 SessionComponentCache* pMainComponentCache) const
00082 {
00083 if (compID == "VariateGenerator") pMainComponent->SetNormalVariateGenerator(dynamic_cast<itk::OnePlusOneEvolutionaryOptimizer::NormalVariateGeneratorType*>(pSubComponent));
00084 else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00085 };
00086
00087 void
00088 OnePlusOneEvolutionaryOptimizerController::
00089 ActualizeMainComponent(ComponentType* pMainComponent,
00090 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00091 const unsigned int& iActLevel) const
00092 {
00093 double dGrowthFactor;
00094 double dShrinkFactor;
00095 double dInitialRadius;
00096 double dEpsilon;
00097 int iNrOfIterations;
00098
00099 try
00100 {
00101 SessionAccessor::GetParameterValue(pComponentCache,"GrowthFactor",dGrowthFactor,0,iActLevel,true);
00102 SessionAccessor::GetParameterValue(pComponentCache,"ShrinkFactor",dShrinkFactor,0,iActLevel,true);
00103 SessionAccessor::GetParameterValue(pComponentCache,"InitialRadius",dInitialRadius,0,iActLevel,true);
00104 SessionAccessor::GetParameterValue(pComponentCache,"Epsilon",dEpsilon,0,iActLevel,true);
00105 SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations,0,iActLevel,true);
00106 }
00107 catchAllNPassMacro("Error while retrieving parameter values.");
00108
00109 ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00110 pMainComponent->SetScales(scales);
00111
00112 pMainComponent->SetMaximumIteration(iNrOfIterations);
00113 pMainComponent->SetEpsilon(dEpsilon);
00114 pMainComponent->Initialize (dInitialRadius, dGrowthFactor, dShrinkFactor);
00115
00116 Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00117 if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00118 bool bMinimize;
00119 smpDirection->GetParameterValue(bMinimize);
00120 pMainComponent->SetMaximize( !bMinimize);
00121 };
00122
00123 void
00124 OnePlusOneEvolutionaryOptimizerController::
00125 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00126 ComponentType* pMainComponent,
00127 SessionComponentCache* pMainComponentCache,
00128 SessionInfo* pSessionInfo,
00129 StatisticDictionary& rDictionary) const
00130 {
00131 Superclass::SetStatisticEntryMainComponent(rStatisticEntry,pMainComponent,pMainComponentCache,pSessionInfo,rDictionary);
00132
00133 std::string sName = "OptimizerValue";
00134 std::string sIDPath = pMainComponentCache->GetIDPath();
00135 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath, sName);
00136
00137 if (!pEntry)
00138 {
00139 pEntry = rDictionary.AddValueDefinition(sName,sIDPath,"Value of the Optimizer");
00140 }
00141
00142 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetValue()),pEntry->GetRefID());
00143 };
00144
00145 OnePlusOneEvolutionaryOptimizerController::MeasuresType
00146 OnePlusOneEvolutionaryOptimizerController::
00147 GetCurrentValue(ComponentType* pOptimizer) const
00148 {
00149 MeasuresType values(1);
00150 values.Fill(pOptimizer->GetValue());
00151 return values;
00152 };
00153
00154 }