46 #include "../../App/ApplicationTools.h" 63 optDesc_(desc), optParameters_(desc->getNumberOfOptimizers()),
64 nbParameters_(desc->getNumberOfOptimizers()), n_(n),
65 precisionStep_(-1.), stepCount_(0), initialValue_(-1.)
79 optParameters_(opt.optParameters_),
80 nbParameters_(opt.nbParameters_),
82 precisionStep_(opt.precisionStep_),
83 stepCount_(opt.stepCount_),
84 initialValue_(opt.initialValue_)
116 optParameters_.resize(optDesc_->getNumberOfOptimizers());
117 for (
unsigned int i = 0; i < optDesc_->getNumberOfOptimizers(); i++)
119 optParameters_[i].reset();
120 for (
size_t j = 0; j < optDesc_->getParameterNames(i).size(); j++)
122 string pname = optDesc_->getParameterNames(i)[j];
123 if (parameters.hasParameter(pname))
125 optParameters_[i].addParameter(parameters.getParameter(pname));
128 nbParameters_[i] = optParameters_[i].size();
132 for (
unsigned int i = 0; i < optDesc_->getNumberOfOptimizers(); i++)
134 if (nbParameters_[i] > 0)
136 Optimizer * opt = optDesc_->getOptimizer(i);
141 opt->
setVerbose(getVerbose() > 0 ? getVerbose() - 1 : 0);
146 getParameters_().matchParametersValues(getFunction()->getParameters());
148 getFunction()->setParameters(getParameters());
149 initialValue_ = getFunction()->getValue();
153 precisionStep_ = (log10(getStopCondition()->getTolerance()) - log10(initialValue_)) / n_;
179 dynamic_cast<DerivableFirstOrder*>(
getFunction())->enableFirstOrderDerivatives(
true);
181 dynamic_cast<DerivableSecondOrder*>(
getFunction())->enableSecondOrderDerivatives(
true);
191 else throw Exception(
"MetaOptimizer::step. Unknown iteration type specified.");
194 dynamic_cast<DerivableFirstOrder*>(
getFunction())->enableFirstOrderDerivatives(
false);
196 dynamic_cast<DerivableSecondOrder*>(
getFunction())->enableSecondOrderDerivatives(
false);
virtual void setMessageHandler(OutputStream *mh)=0
Set the message handler for this optimizer.
AbstractOptimizer & operator=(const AbstractOptimizer &opt)
virtual OutputStream & flush()=0
OptimizationStopCondition * getStopCondition()
Get the stop condition of the optimization algorithm.
unsigned int getVerbose() const
Get the verbose level.
virtual const ParameterList & getParameters() const =0
This class allows to perform a correspondence analysis.
virtual bool matchParametersValues(const ParameterList ¶ms, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
This is the function abstract class.
virtual double optimize()=0
Perform as many optimization steps untill the stop condition is met.
ParameterList & getParameters_()
Stop condition on function value.
virtual void setTolerance(double tolerance)=0
Set the tolerance parameter.
The parameter list object.
bool tolIsReached_
Tell if the tolerance level has been reached.
void setOptimizationProgressCharacter(const std::string &c)
Set the character to be displayed during optimization.
void setDefaultStopCondition_(OptimizationStopCondition *osc)
const Function * getFunction() const
Get the current function being optimized.
const ParameterList & getParameters() const
virtual double step()=0
Perform an optimization step.
virtual unsigned int getNumberOfEvaluations() const =0
Get the number of function evaluations performed since the call of the init function.
virtual OutputStream & endLine()=0
virtual void setVerbose(unsigned int v)=0
Set the verbose level.
unsigned int nbEval_
The current number of function evaluations achieved.
Partial implementation of the Optimizer interface.
void setStopCondition(const OptimizationStopCondition &stopCondition)
Set the stop condition of the optimization algorithm.
virtual double getTolerance() const =0
Get the tolerance parameter.
virtual void setProfiler(OutputStream *profiler)=0
Set the profiler for this optimizer.
This is the basal interface for all optimization methods.
virtual void init(const ParameterList ¶ms)=0
Set the initial values of the parameters.
OptimizationStopCondition * getDefaultStopCondition()
Get the default stop condition of the optimization algorithm.
virtual double getValue() const =0
Get the value of the function at the current point.
virtual void setConstraintPolicy(const std::string &constraintPolicy)=0
Set the constraint policy for this optimizer.
virtual OptimizationStopCondition * getStopCondition()=0
Get the stop condition of the optimization algorithm.