00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "frePowellSOOptimizerController.h"
00024 #include "freExceptions.h"
00025
00026 namespace FREE
00027 {
00028
00032
00033
00034
00035 DefineParameterMacro(PowellSOOptimizerController,MaximumLineIteration,"MaximumLineIteration","Maximum number of line search iterations.");
00036 DefineParameterMacro(PowellSOOptimizerController,StepLength,"StepLength","StepLength for the (scaled) spacing of the sampling of parameter space while bracketing the extremum");
00037 DefineParameterMacro(PowellSOOptimizerController,StepTolerance,"StepTolerance","Once the local extreme is known to be within this distance of the current parameter values, optimization terminates.");
00038 DefineParameterMacro(PowellSOOptimizerController,ValueTolerance,"ValueTolerance","Once this current cost function value is known to be within this tolerance of the cost function value at the local extreme, optimization terminates.");
00039
00040 PowellSOOptimizerController::
00041 PowellSOOptimizerController()
00042 {
00043
00044 this->UpdateControllerID(ControllerID::PowellSOOptimizerController);
00045 this->m_Description = "Optimizes registration setups by Powell optimizer approach using Brent line search.";
00046 };
00047
00048 void
00049 PowellSOOptimizerController::
00050 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00051 const SessionComponentCache* pComponentCache,
00052 bool bRegardOldSetup) const
00053 {
00054 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00055
00056
00057 profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"100");
00058 profile.Parameters().AddParameter(cParam_MaximumLineIteration,Parameter::PVTInteger,cParamDsc_MaximumLineIteration,1,"100");
00059 profile.Parameters().AddParameter(cParam_StepLength,Parameter::PVTDouble,cParamDsc_StepLength,1,"1.0");
00060 profile.Parameters().AddParameter(cParam_StepTolerance,Parameter::PVTDouble,cParamDsc_StepTolerance,1,"0.00001");
00061 profile.Parameters().AddParameter(cParam_ValueTolerance,Parameter::PVTDouble,cParamDsc_ValueTolerance,1,"0.00001");
00062 };
00063
00064 long
00065 PowellSOOptimizerController::
00066 GetMaxIterationCount(const SessionComponentCache* pComponentCache, unsigned int iResolutionLevel) const
00067 {
00068 if (!pComponentCache) throwCtrlExceptionMacro("","Passed pComponentCache is NULL.");
00069 if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cache has no setup assigned.");
00070
00071 long lResult = 1;
00072 try
00073 {
00074 SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lResult);
00075 }
00076 catchAllNPassMacro("Unknown error while retrieving max interation count.")
00077
00078 return lResult;
00079 };
00080
00081 void
00082 PowellSOOptimizerController::
00083 ActualizeMainComponent(ComponentType* pMainComponent,
00084 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00085 const unsigned int& iActLevel) const
00086 {
00087 Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00088 pSessionInfo, iActLevel);
00089
00090 double dValueTolerance;
00091 double dStepTolerance;
00092 double dStepLength;
00093 int iNrOfIterations;
00094 int iLineIteration;
00095
00096 try
00097 {
00098 SessionAccessor::GetParameterValue(pComponentCache,cParam_MaximumLineIteration,iLineIteration);
00099 SessionAccessor::GetParameterValue(pComponentCache,cParam_StepLength,dStepLength);
00100 SessionAccessor::GetParameterValue(pComponentCache,cParam_StepTolerance,dStepTolerance);
00101 SessionAccessor::GetParameterValue(pComponentCache,cParam_ValueTolerance,dValueTolerance);
00102 SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations);
00103 }
00104 catchAllNPassMacro("Error while retrieving parameter values.");
00105
00106 pMainComponent->SetMaximumIteration(iNrOfIterations);
00107 pMainComponent->SetMaximumLineIteration(iLineIteration);
00108 pMainComponent->SetStepLength(dStepLength);
00109 pMainComponent->SetStepTolerance(dStepTolerance);
00110 pMainComponent->SetValueTolerance(dValueTolerance);
00111
00112
00113 Parameter::Pointer param = SessionAccessor::GetParameterByIDPath(pComponentCache,cIDPParent+IDPath(cComp_MainMetric+std::string("/@")+std::string(cParam_MetricMinimize)));
00114 bool bMin = true;
00115 if (param.IsNotNull())
00116 {
00117 param->GetParameterValue(bMin);
00118 }
00119 pMainComponent->SetMaximize(!bMin);
00120 };
00121
00122 void
00123 PowellSOOptimizerController::
00124 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00125 ComponentType* pMainComponent,
00126 SessionComponentCache* pMainComponentCache,
00127 SessionInfo* pSessionInfo,
00128 StatisticDictionary& rDictionary) const
00129 {
00130 ParameterArrayType parameters = pMainComponent->GetCurrentPosition();
00131
00132 std::string sName = "Position #";
00133 std::string sIDPath = pMainComponentCache->GetIDPath();
00134 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00135
00136 if (!pEntry)
00137 {
00138 std::string sCommment = "Optimizer current position. Meaning depends on chosen transformation";
00139 pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00140 for (unsigned int i = 1; i<parameters.Size(); i++)
00141 {
00142 rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00143 }
00144
00145 rDictionary.AddValueDefinition(sIDPath,"GlobalIterationID", "Nr / ID of the global search.");
00146 rDictionary.AddValueDefinition(sIDPath,"LineIterationID", "Nr / ID of the line search iteration.");
00147 rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Composed value of the current optimizer position");
00148 }
00149
00150 for (unsigned int i = 0; i<parameters.Size(); i++)
00151 {
00152 rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00153 }
00154
00155 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetItkOptimizer()->GetCurrentIteration()),pEntry->GetRefID()+parameters.Size());
00156 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetItkOptimizer()->GetCurrentLineIteration()),pEntry->GetRefID()+parameters.Size()+1);
00157 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentValue()),pEntry->GetRefID()+parameters.Size()+2);
00158 };
00159
00160 }