42 #include "../../Text/TextTools.h"
43 #include "../NumTools.h"
65 if (params.
size() != 1)
66 throw Exception(
"NewtonOneDimension::init(). This optimizer only deals with one parameter.");
67 _param = params[0].getName();
82 if (secondOrderDerivative <= 0)
87 movement = -firstOrderDerivative / secondOrderDerivative;
90 movement = firstOrderDerivative / secondOrderDerivative;
91 if (std::isnan(movement))
96 newPoint[0].setValue(
getParameters()[0].getValue() - movement);
100 unsigned int count = 0;
109 printMessage(
"!!! Felsenstein-Churchill correction applied too much time. Stopping here. Convergence probably not reached.");
115 movement = movement / 2;
116 newPoint[0].setValue(
getParameters()[0].getValue() - movement);
Partial implementation of the Optimizer interface.
void printMessage(const std::string &message)
Give a message to print to the message handler.
OptimizationStopCondition * getDefaultStopCondition()
Get the default stop condition of the optimization algorithm.
unsigned int nbEvalMax_
The maximum number of function evaluations allowed.
const ParameterList & getParameters() const
void setStopCondition(const OptimizationStopCondition &stopCondition)
Set the stop condition of the optimization algorithm.
ParameterList & getParameters_()
OptimizationStopCondition * getStopCondition()
Get the stop condition of the optimization algorithm.
double currentValue_
The current value of the function.
bool tolIsReached_
Tell if the tolerance level has been reached.
void setDefaultStopCondition_(OptimizationStopCondition *osc)
virtual double getFirstOrderDerivative(const std::string &variable) const =0
Get the derivative of the function at the current point.
This is the abstract class for second order derivable functions.
virtual double getSecondOrderDerivative(const std::string &variable) const =0
Get the second order derivative of the function at the current point.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Stop condition on function value.
virtual void setParameters(const ParameterList ¶meters)=0
Set the point where the function must be computed.
virtual double f(const ParameterList ¶meters)
Get the value of the function according to a given set of parameters.
double doStep()
This function is called by the step() method and contains all calculations.
void doInit(const ParameterList ¶ms)
This function is called by the init() method and contains all calculations.
NewtonOneDimension(DerivableSecondOrder *function=0)
unsigned int _maxCorrection
const DerivableSecondOrder * getFunction() const
Get the current function being optimized.
virtual void init()=0
Initialize the condition.
The parameter list object.
virtual const ParameterList & getParameters() const =0
Get all parameters available.
std::string toString(T t)
General template method to convert to a string.
std::size_t count(const std::string &s, const std::string &pattern)
Count the occurences of a given pattern in a string.