5 #include "../../App/ApplicationTools.h" 6 #include "../../Text/TextTools.h" 7 #include "../AutoParameter.h" 19 AbstractOptimizer::AbstractOptimizer(std::shared_ptr<FunctionInterface>
function) :
25 stopCondition_(0), defaultStopCondition_(0),
26 verbose_(true), isInitialized_(false), startTime_(), listeners_(),
27 updateParameters_(false), stepChar_(
"*"),
28 nbEvalMax_(1000000), nbEval_(0),
29 currentValue_(0), tolIsReached_(false)
128 throw Exception(
"AbstractOptimizer::init. Optimizer currently has no function.");
186 throw Exception(
"AbstractOptimizer::optimize. Optimizer not initialized: call the 'init' method first!");
248 size_t ndim = params.
size();
251 for (
size_t j = 0; j < ndim; j++)
299 listener->optimizationInitializationPerformed(event);
309 listener->optimizationStepPerformed(event);
319 if (listener->listenerModifiesParameters())
bool isInitialized_
Check if the optimizer have been feeded with initial parameters values.
static std::string CONSTRAINTS_IGNORE
AbstractOptimizer & operator=(const AbstractOptimizer &opt)
double step() override
Basic implementation.
virtual void doInit(const ParameterList ¶ms)=0
This function is called by the init() method and contains all calculations.
double optimize() override
Basic implementation.
virtual bool matchParametersValues(const ParameterList ¶ms, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
void profileln(double v)
Print to the profile if there is one and end line.
std::shared_ptr< FunctionInterface > function_
The function to optimize.
void ignoreConstraints()
Remove the constraints of all the arguments.
The parameter list object.
bool tolIsReached_
Tell if the tolerance level has been reached.
virtual void setMessageHandler(std::shared_ptr< OutputStream > mh)
Set the message handler for this AutoParameter.
std::shared_ptr< OutputStream > messageHandler_
The message handler.
std::shared_ptr< OptimizationStopCondition > stopCondition_
The stoping condition to use while optimizing.
bool listenerModifiesParameters() const
unsigned int verbose_
State of the verbose mode: > 0 = enabled.
virtual void setParameter(size_t index, const Parameter ¶m)
Change given parameter.
void printPoint(const ParameterList ¶ms, double value)
Print parameters and corresponding function evaluation to profiler.
std::shared_ptr< OutputStream > profiler_
The profiler.
An event object which indicates that an optimization event occured.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
static std::string CONSTRAINTS_AUTO
unsigned int nbEvalMax_
The maximum number of function evaluations allowed.
std::vector< std::shared_ptr< OptimizationListener > > listeners_
unsigned int nbEval_
The current number of function evaluations achieved.
Partial implementation of the Optimizer interface.
void fireOptimizationInitializationPerformed(const OptimizationEvent &event)
Notify all listeners that optimizer initialization was performed.
double currentValue_
The current value of the function.
std::string constraintPolicy_
The constraint policy.
std::shared_ptr< OptimizationStopCondition > defaultStopCondition_
The default stoping condition to use while optimizing.
virtual double doStep()=0
This function is called by the step() method and contains all calculations.
std::string toString(T t)
General template method to convert to a string.
void profile(double v)
Print to the profile if there is one.
void init(const ParameterList ¶ms) override
Basic implementation.
void fireOptimizationStepPerformed(const OptimizationEvent &event)
Notify all listeners that an optimization step was performed.
void printMessage(const std::string &message)
Give a message to print to the message handler.
AbstractOptimizer(std::shared_ptr< FunctionInterface > function=nullptr)
ParameterList parameters_
The parameters that will be optimized.
void autoParameter()
Build a list of AutoParameter instead of Parameter.