5 #include "../../Text/TextTools.h" 6 #include "../NumTools.h" 28 if (params.
size() != 1)
29 throw Exception(
"NewtonOneDimension::init(). This optimizer only deals with one parameter.");
30 _param = params[0].getName();
45 if (secondOrderDerivative <= 0)
50 movement = -firstOrderDerivative / secondOrderDerivative;
53 movement = firstOrderDerivative / secondOrderDerivative;
54 if (std::isnan(movement))
59 newPoint[0].setValue(
getParameters()[0].getValue() - movement);
63 unsigned int count = 0;
72 printMessage(
"!!! Felsenstein-Churchill correction applied too much time. Stopping here. Convergence probably not reached.");
78 movement = movement / 2;
79 newPoint[0].setValue(
getParameters()[0].getValue() - movement);
void doInit(const ParameterList ¶ms)
This function is called by the init() method and contains all calculations.
std::shared_ptr< OptimizationStopCondition > getStopCondition() override
Get the stop condition of the optimization algorithm.
std::size_t count(const std::string &s, const std::string &pattern)
Count the occurences of a given pattern in a string.
void setDefaultStopCondition_(std::shared_ptr< OptimizationStopCondition > osc)
ParameterList & getParameters_()
const ParameterList & getParameters() const override
The parameter list object.
bool tolIsReached_
Tell if the tolerance level has been reached.
virtual double getFirstOrderDerivative(const std::string &variable) const =0
Get the derivative of the function at the current point.
virtual double getSecondOrderDerivative(const std::string &variable) const =0
Get the second order derivative of the function at the current point.
NewtonOneDimension(std::shared_ptr< SecondOrderDerivable > function=nullptr)
const SecondOrderDerivable & secondOrderDerivableFunction() const
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
double doStep()
This function is called by the step() method and contains all calculations.
unsigned int nbEvalMax_
The maximum number of function evaluations allowed.
Partial implementation of the Optimizer interface.
double currentValue_
The current value of the function.
std::string toString(T t)
General template method to convert to a string.
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.
const FirstOrderDerivable & firstOrderDerivableFunction() const
void printMessage(const std::string &message)
Give a message to print to the message handler.
void setStopCondition(std::shared_ptr< OptimizationStopCondition > stopCondition) override
Set the stop condition of the optimization algorithm.
unsigned int _maxCorrection