5 #ifndef BPP_NUMERIC_FUNCTION_ABSTRACTOPTIMIZER_H 6 #define BPP_NUMERIC_FUNCTION_ABSTRACTOPTIMIZER_H 82 std::vector< std::shared_ptr<OptimizationListener>>
listeners_;
138 double step()
override;
156 void setFunction(std::shared_ptr<FunctionInterface>
function)
override 158 function_ =
function;
159 if (
function) stopCondition_->init();
170 throw NullPointerException(
"AbstractOptimizer::function() : no function associated to this optimizer.");
182 throw NullPointerException(
"AbstractOptimizer::function() : no function associated to this optimizer.");
194 if (!function_)
throw NullPointerException(
"AbstractOptimizer::getFunctionValue. No function associated to this optimizer.");
202 void setProfiler(std::shared_ptr<OutputStream> profiler)
override { profiler_ = profiler; }
210 stopCondition_ = stopCondition;
231 void setConstraintPolicy(
const std::string& constraintPolicy)
override { constraintPolicy_ = constraintPolicy; }
238 listeners_.push_back(listener);
288 virtual double doStep() = 0;
325 void profile(
const std::string& s);
393 defaultStopCondition_ = osc;
397 #endif // BPP_NUMERIC_FUNCTION_ABSTRACTOPTIMIZER_H bool isInitialized_
Check if the optimizer have been feeded with initial parameters values.
std::shared_ptr< const OptimizationStopCondition > getStopCondition() const override
Get the stop condition of the optimization algorithm.
void addOptimizationListener(std::shared_ptr< OptimizationListener > listener) override
Register a listener to this class.
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.
virtual ~AbstractOptimizer()
void updateParameters(bool yn) override
Tell if we shall update all parameters after one optimization step.
double optimize() override
Basic implementation.
virtual double getParameterValue(const std::string &name) const
Get the value of the parameter with name name.
std::shared_ptr< OptimizationStopCondition > getStopCondition() override
Get the stop condition of the optimization algorithm.
bool isInitialized() const override
void setVerbose(unsigned int v) override
Set the verbose level.
bool isToleranceReached() const override
Tell if the tolerance level is reached.
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 setConstraintPolicy(const std::string &constraintPolicy) override
Set the constraint policy for this optimizer.
This class is designed to facilitate the manipulation of parameters.
void setDefaultStopCondition_(std::shared_ptr< OptimizationStopCondition > osc)
ParameterList & getParameters_()
const ParameterList & getParameters() const override
unsigned int getNumberOfEvaluations() const override
Get the number of function evaluations performed since the call of the init function.
This is the function abstract class.
std::shared_ptr< OutputStream > getProfiler() const override
std::string getConstraintPolicy() const override
Get the constraint policy for this optimizer.
double getFunctionValue() const override
Get the current function value.
void ignoreConstraints()
Remove the constraints of all the arguments.
The parameter list object.
void setMessageHandler(std::shared_ptr< OutputStream > mh) override
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.
unsigned int getVerbose() const override
Get the verbose level.
void setProfiler(std::shared_ptr< OutputStream > profiler) override
Set the profiler for this optimizer.
void setFunction(std::shared_ptr< FunctionInterface > function) override
Set the function to optimize.
std::shared_ptr< OutputStream > messageHandler_
The message handler.
std::shared_ptr< FunctionInterface > getFunction_()
Parameter & getParameter_(size_t i)
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.
The base class exception for NULL pointer error. This exception may be thrown when an unexpected NULL...
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.
bool updateParameters() const override
Tell if we shall update all parameters after one optimization step.
This is the basal interface for all optimization methods.
unsigned int nbEvalMax_
The maximum number of function evaluations allowed.
std::vector< std::shared_ptr< OptimizationListener > > listeners_
std::shared_ptr< const OptimizationStopCondition > getDefaultStopCondition() const override
Get the default stop condition of the optimization algorithm.
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.
double getParameterValue(const std::string &name) const override
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::shared_ptr< OutputStream > getMessageHandler() const override
bool hasFunction() const override
Tell if a funciton is associatied to this optimizer.
std::shared_ptr< FunctionInterface > getFunction() override
Get the current function being optimized.
std::shared_ptr< const FunctionInterface > getFunction() const override
Get the current function being optimized.
void profile(double v)
Print to the profile if there is one.
void init(const ParameterList ¶ms) override
Basic implementation.
void setMaximumNumberOfEvaluations(unsigned int max) override
Set the maximum number of function evaluation to perform during optimization.
const std::string & getOptimizationProgressCharacter() const
std::shared_ptr< OptimizationStopCondition > getDefaultStopCondition() override
Get the default stop condition of the optimization algorithm.
void fireOptimizationStepPerformed(const OptimizationEvent &event)
Notify all listeners that an optimization step was performed.
bool isMaximumNumberOfEvaluationsReached() const override
Tell if the maximum number of function evaluations is reached.
void printMessage(const std::string &message)
Give a message to print to the message handler.
AbstractOptimizer(std::shared_ptr< FunctionInterface > function=nullptr)
void setStopCondition(std::shared_ptr< OptimizationStopCondition > stopCondition) override
Set the stop condition of the optimization algorithm.
ParameterList parameters_
The parameters that will be optimized.
void autoParameter()
Build a list of AutoParameter instead of Parameter.