00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "freESCMAMutationController.h"
00023 #include "freExceptions.h"
00024
00025 #include "freESParentSelectorControllerBase.h"
00026 #include "freESRecombinatorControllerBase.h"
00027
00028 namespace FREE
00029 {
00030
00034
00035
00036
00037
00038 DefineParameterMacro(ESCMAMutationController,Sigma,"Sigma","Basic step length/variance for the mutation of the objective parameters.");
00039 DefineParameterMacro(ESCMAMutationController,Mu_eff,"Mu_eff","The variance effective selection mass. If the centroid is computed by calculating the mean, Mu_eff equals Mu.");
00040 DefineParameterMacro(ESCMAMutationController,Mu_cov,"Mu_cov","Weight between rank-one matrix update and rank-mu update. 0: only use rank-mu update\n1: only use rank-one update");
00041 DefineParameterMacro(ESCMAMutationController,C_c,"C_c","Learning rate for rank-one update");
00042 DefineParameterMacro(ESCMAMutationController,C_cov,"C_cov", "Learing rate for the covariance matrix update");
00043 DefineParameterMacro(ESCMAMutationController,C_sigma,"C_sigma","Learning rate for the cumulation for the step size control.");
00044 DefineParameterMacro(ESCMAMutationController,D_sigma,"D_sigma","Damping rate for the calculation.");
00045 DefineParameterMacro(ESCMAMutationController,InitializeControlValues,"InitializeControlValues","Initializes the control values Mu_eff, Mu_cov, C_c, C_cov, C_sigma and D_sigma, by using InitialMu and InitialObjectivCount.\n0:Don't initialize\n1:Initialize for homogeneous mean (requires InitialObjectivCount)\n2:Initialize for weighted mean (by Hansen)(requires InitialObjectivCount and InitialMu)");
00046 DefineParameterMacro(ESCMAMutationController,InitialMu,"InitialMu","Number of individuals used for centroid estimation. This value is only used for default initialization of the control values. The real Mu will be determined by the number of selected points for centroid estimation.");
00047 DefineParameterMacro(ESCMAMutationController,InitialObjectiveCount,"InitialObjectiveCount","Values needed to initialize the mutation. The value is the number of objective parameters.");
00048 DefineParameterMacro(ESCMAMutationController,InitialSeed,"InitialSeed", "Seed for the variate gernerator.");
00049 DefineParameterMacro(ESCMAMutationController,UseInitialSeed,"UseInitialSeed","Use the initial seed for initializing the variate gernerator for the mutation; otherwise use actual time to initialize.");
00050
00051 ESCMAMutationController::
00052 ESCMAMutationController()
00053 {
00054
00055 this->UpdateControllerID(ControllerID::ESCMAMutationController);
00056 this->m_Description = "A CMA ES mutations.";
00057 };
00058
00059 void
00060 ESCMAMutationController::
00061 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00062 const SessionComponentCache* pComponentCache,
00063 bool bRegardOldSetup) const
00064 {
00065 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00066
00067
00068 profile.Parameters().AddParameter(cParam_Sigma,CtrlProfile::Parameter::PVTDouble,cParamDsc_Sigma,1,"1.0",-1,true);
00069 profile.Parameters().AddParameter(cParam_Mu_eff,CtrlProfile::Parameter::PVTDouble,cParamDsc_Mu_eff,1,"2.0",-1,true);
00070 profile.Parameters().AddParameter(cParam_Mu_cov,CtrlProfile::Parameter::PVTDouble,cParamDsc_Mu_cov,1,"0.9",-1,true);
00071 profile.Parameters().AddParameter(cParam_C_c,CtrlProfile::Parameter::PVTDouble,cParamDsc_C_c,1,"0.8",-1,true);
00072 profile.Parameters().AddParameter(cParam_C_cov,CtrlProfile::Parameter::PVTDouble,cParamDsc_C_cov,1,"0.333",-1,true);
00073 profile.Parameters().AddParameter(cParam_C_sigma,CtrlProfile::Parameter::PVTDouble,cParamDsc_C_sigma,1,"0.666",-1,true);
00074 profile.Parameters().AddParameter(cParam_D_sigma,CtrlProfile::Parameter::PVTDouble,cParamDsc_D_sigma,1,"1.0",-1,true);
00075 profile.Parameters().AddParameter(cParam_InitializeControlValues,CtrlProfile::Parameter::PVTULong,cParamDsc_InitializeControlValues,1,"1");
00076 profile.Parameters().AddParameter(cParam_InitialObjectiveCount,CtrlProfile::Parameter::PVTULong,cParamDsc_InitialObjectiveCount,1,"1");
00077 profile.Parameters().AddParameter(cParam_InitialMu,CtrlProfile::Parameter::PVTULong,cParamDsc_InitialMu,1,"2");
00078 profile.Parameters().AddParameter(cParam_InitialSeed,CtrlProfile::Parameter::PVTInteger,cParamDsc_InitialSeed,1,"21021978");
00079 profile.Parameters().AddParameter(cParam_UseInitialSeed,CtrlProfile::Parameter::PVTBool,cParamDsc_UseInitialSeed,1,"false");
00080
00081
00082 profile.SubComponents().AddSubComponent("SearchPointSelector",1,csUndefinedController,"Selection of individuals used for centroid estimation.");
00083 profile.SubComponents().AddSubComponent("CentroidCombinator",1,csUndefinedController,"Computes the centroid out of the selected individuals.");
00084
00085
00086 CtrlProfile::ProfileOption* pOption;
00087
00088 pOption = profile.Requirements().AddRequirement("SearchPointSelector")->AddProfileOption();
00089 pOption->Inheritance().AddAncestor(ControllerID::ESParentSelectorControllerBase);
00090 pOption->CheckForInheritance();
00091
00092 pOption = profile.Requirements().AddRequirement("CentroidCombinator")->AddProfileOption();
00093 pOption->Inheritance().AddAncestor(ControllerID::ESRecombinatorControllerBase);
00094 pOption->CheckForInheritance();
00095 };
00096
00097 GenericComponentType*
00098 ESCMAMutationController::
00099 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00100 SessionComponentCache* pMainComponentCache) const
00101 {
00102 if (compID == "SearchPointSelector") return pMainComponent->GetSearchPointSelector();
00103 if (compID == "CentroidCombinator") return pMainComponent->GetCentroidCombinator();
00104 return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00105 };
00106
00107 void
00108 ESCMAMutationController::
00109 SetSubComponentCasted(GenericComponentType* pSubComponent,
00110 ComponentType* pMainComponent,
00111 const ComponentID compID,
00112 SessionComponentCache* pMainComponentCache) const
00113 {
00114 if (compID == "SearchPointSelector") pMainComponent->SetSearchPointSelector(dynamic_cast<ComponentType::SearchPointSelectorType*>(pSubComponent));
00115 if (compID == "CentroidCombinator") pMainComponent->SetCentroidCombinator(dynamic_cast<ComponentType::CentroidCombinatorType*>(pSubComponent));
00116 else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00117 };
00118
00119 void
00120 ESCMAMutationController::
00121 ActualizeMainComponent(ComponentType* pMainComponent,
00122 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00123 const unsigned int& iActLevel) const
00124 {
00125 Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00126 pSessionInfo, iActLevel);
00127
00128 int iSeed;
00129 bool bUseSeed;
00130
00131 double dSigma;
00132 long lMu;
00133 double dMu_eff;
00134 double dMu_cov;
00135 double dC_c;
00136 double dC_cov;
00137 double dC_sigma;
00138 double dD_sigma;
00139
00140 long lInitialObjectiveCount;
00141 long lInitializeControlValues;
00142
00143 try
00144 {
00145 SessionAccessor::GetParameterValue(pComponentCache,cParam_InitialSeed,iSeed,0,iActLevel,true);
00146 SessionAccessor::GetParameterValue(pComponentCache,cParam_UseInitialSeed,bUseSeed,0,iActLevel,true);
00147 SessionAccessor::GetParameterValue(pComponentCache,cParam_Sigma,dSigma,0,iActLevel,true);
00148 SessionAccessor::GetParameterValue(pComponentCache,cParam_Mu_eff,dMu_eff,0,iActLevel,true);
00149 SessionAccessor::GetParameterValue(pComponentCache,cParam_Mu_cov,dMu_cov,0,iActLevel,true);
00150 SessionAccessor::GetParameterValue(pComponentCache,cParam_C_c,dC_c,0,iActLevel,true);
00151 SessionAccessor::GetParameterValue(pComponentCache,cParam_C_cov,dC_cov,0,iActLevel,true);
00152 SessionAccessor::GetParameterValue(pComponentCache,cParam_C_sigma,dC_sigma,0,iActLevel,true);
00153 SessionAccessor::GetParameterValue(pComponentCache,cParam_D_sigma,dD_sigma,0,iActLevel,true);
00154 SessionAccessor::GetParameterValue(pComponentCache,cParam_InitializeControlValues,lInitializeControlValues,0,iActLevel,true);
00155 SessionAccessor::GetParameterValue(pComponentCache,cParam_InitialObjectiveCount,lInitialObjectiveCount,0,iActLevel,true);
00156 SessionAccessor::GetParameterValue(pComponentCache,cParam_InitialMu,lMu,0,iActLevel,true);
00157 }
00158 catchAllNPassMacro("Error while retrieving parameter values.");
00159
00160 if (bUseSeed)
00161 {
00162 pMainComponent->GetRandomGenerator().Initialize(iSeed);
00163 }
00164 else
00165 {
00166 pMainComponent->GetRandomGenerator().Initialize((int)clock());
00167 }
00168
00169 pMainComponent->SetSigma(dSigma);
00170 pMainComponent->SetMu_eff(dMu_eff);
00171 pMainComponent->SetMu_cov(dMu_cov);
00172 pMainComponent->SetC_c(dC_c);
00173 pMainComponent->SetC_cov(dC_cov);
00174 pMainComponent->SetC_sigma(dC_sigma);
00175 pMainComponent->SetD_sigma(dD_sigma);
00176
00177 if (lInitializeControlValues==1)
00178 {
00179 pMainComponent->InitializeControlValues_Mean(lInitialObjectiveCount);
00180 }
00181 else if (lInitializeControlValues==2)
00182 {
00183 pMainComponent->InitializeControlValues_Hansen(lMu,lInitialObjectiveCount);
00184 }
00185 };
00186
00187 void
00188 ESCMAMutationController::
00189 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00190 ComponentType* pMainComponent,
00191 SessionComponentCache* pMainComponentCache,
00192 SessionInfo* pSessionInfo,
00193 StatisticDictionary& rDictionary) const
00194 {
00195 std::string sName = "Population strategic prameters";
00196 std::string sIDPath = pMainComponentCache->GetIDPath();
00197 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath, sName);
00198
00199 if (!pEntry)
00200 {
00201 pEntry = rDictionary.AddValueDefinition(sIDPath,sName,"List of strategic parameters of the population.");
00202 }
00203
00204 std::string sParam = "";
00205
00206 for (ComponentType::MatrixType::const_iterator pos = pMainComponent->GetCurMatrix().begin(); pos != pMainComponent->GetCurMatrix().end(); ++pos)
00207 {
00208 sParam += Convert::ToStr(*pos) + "; ";
00209 }
00210
00211
00212 for (ComponentType::VectorType::const_iterator pos = pMainComponent->GetCurCentroid().begin(); pos != pMainComponent->GetCurCentroid().end(); ++pos)
00213 {
00214 sParam += Convert::ToStr(*pos) + "; ";
00215 }
00216
00217
00218 for (ComponentType::VectorType::const_iterator pos = pMainComponent->GetCurMatrixPath().begin(); pos != pMainComponent->GetCurMatrixPath().end(); ++pos)
00219 {
00220 sParam += Convert::ToStr(*pos) + "; ";
00221 }
00222
00223
00224 for (ComponentType::VectorType::const_iterator pos = pMainComponent->GetCurStepPath().begin(); pos != pMainComponent->GetCurStepPath().end(); ++pos)
00225 {
00226 sParam += Convert::ToStr(*pos) + "; ";
00227 }
00228
00229
00230 sParam += Convert::ToStr(pMainComponent->GetCurStepLength());
00231
00232 rStatisticEntry.AddValue(sParam,pEntry->GetRefID());;
00233 };
00234
00235 }