8 #include "../../App/ApplicationTools.h" 21 std::shared_ptr<FunctionInterface>
function,
22 std::unique_ptr<MetaOptimizerInfos> desc,
25 optDesc_(
std::move(desc)), optParameters_(optDesc_->getNumberOfOptimizers()),
26 nbParameters_(optDesc_->getNumberOfOptimizers()), n_(n),
27 precisionStep_(-1.), stepCount_(0), initialValue_(-1.)
74 for (
unsigned int i = 0; i <
optDesc_->getNumberOfOptimizers(); ++i)
77 for (
size_t j = 0; j <
optDesc_->getParameterNames(i).size(); ++j)
79 string pname =
optDesc_->getParameterNames(i)[j];
89 for (
unsigned int i = 0; i <
optDesc_->getNumberOfOptimizers(); ++i)
126 for (
unsigned int i = 0; i <
optDesc_->getNumberOfOptimizers(); ++i)
135 if (
optDesc_->requiresFirstOrderDerivatives(i))
136 dynamic_cast<FirstOrderDerivable&>(
function()).enableFirstOrderDerivatives(
true);
137 if (
optDesc_->requiresSecondOrderDerivatives(i))
138 dynamic_cast<SecondOrderDerivable&>(
function()).enableSecondOrderDerivatives(
true);
149 throw Exception(
"MetaOptimizer::step. Unknown iteration type specified.");
151 if (
optDesc_->requiresFirstOrderDerivatives(i))
152 dynamic_cast<FirstOrderDerivable&>(
function()).enableFirstOrderDerivatives(
false);
153 if (
optDesc_->requiresSecondOrderDerivatives(i))
154 dynamic_cast<SecondOrderDerivable&>(
function()).enableSecondOrderDerivatives(
false);
virtual void setConstraintPolicy(const std::string &constraintPolicy)=0
Set the constraint policy for this optimizer.
virtual void setVerbose(unsigned int v)=0
Set the verbose level.
AbstractOptimizer & operator=(const AbstractOptimizer &opt)
virtual const Parameter & parameter(const std::string &name) const
Get the parameter with name name.
virtual double optimize()=0
Perform as many optimization steps untill the stop condition is met.
virtual bool matchParametersValues(const ParameterList ¶ms, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
std::shared_ptr< OptimizationStopCondition > getStopCondition() override
Get the stop condition of the optimization algorithm.
virtual void updateParameters(bool yn)=0
Tell if we shall update all parameters after one optimization step.
void setDefaultStopCondition_(std::shared_ptr< OptimizationStopCondition > osc)
ParameterList & getParameters_()
const ParameterList & getParameters() const override
std::shared_ptr< OutputStream > getProfiler() const override
std::string getConstraintPolicy() const override
Get the constraint policy for this optimizer.
The parameter list object.
virtual unsigned int getNumberOfEvaluations() const =0
Get the number of function evaluations performed since the call of the init function.
virtual void setMessageHandler(std::shared_ptr< OutputStream > mh)=0
Set the message handler for this optimizer.
bool tolIsReached_
Tell if the tolerance level has been reached.
void setOptimizationProgressCharacter(const std::string &c)
Set the character to be displayed during optimization.
virtual double step()=0
Perform an optimization step.
unsigned int getVerbose() const override
Get the verbose level.
virtual bool hasParameter(const std::string &name) const
virtual void init(const ParameterList ¶ms)=0
Set the initial values of the parameters.
virtual void setProfiler(std::shared_ptr< OutputStream > profiler)=0
Set the profiler for this optimizer.
virtual const ParameterList & getParameters() const =0
bool updateParameters() const override
Tell if we shall update all parameters after one optimization step.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
This is the basal interface for all optimization methods.
unsigned int nbEval_
The current number of function evaluations achieved.
Partial implementation of the Optimizer interface.
std::shared_ptr< OutputStream > getMessageHandler() const override
std::shared_ptr< const FunctionInterface > getFunction() const override
Get the current function being optimized.
std::shared_ptr< OptimizationStopCondition > getDefaultStopCondition() override
Get the default stop condition of the optimization algorithm.
void setStopCondition(std::shared_ptr< OptimizationStopCondition > stopCondition) override
Set the stop condition of the optimization algorithm.
virtual std::shared_ptr< OptimizationStopCondition > getStopCondition()=0
Get the stop condition of the optimization algorithm.