24 return NumTools::abs<double>(
33 return getCurrentTolerance() < tolerance_;
70 std::vector<double> movements(
n_);
73 for (
size_t i = 0; i <
n_; i++)
77 if (secondOrderDerivative == 0)
81 else if (secondOrderDerivative < 0)
86 movements[i] = -firstOrderDerivative / secondOrderDerivative;
89 movements[i] = firstOrderDerivative / secondOrderDerivative;
90 if (std::isnan(movements[i]))
97 newPoint[i].setValue(
getParameters()[i].getValue() - movements[i]);
99 movements[i] =
getParameters()[i].getValue() - newPoint[i].getValue();
104 unsigned int count = 0;
115 for (
size_t i = 0; i < movements.size(); i++)
117 movements[i] = movements[i] / 2;
118 newPoint[i].setValue(
getParameters()[i].getValue() - movements[i]);
124 printMessage(
"!!! Felsenstein-Churchill correction applied too many times.");
143 printMessage(
"!!! Conjugate gradient method failed to improve likelihood.");
152 printMessage(
"PseudoNewtonOptimizer::doStep. Value could not be ameliorated!");
const OptimizerInterface * optimizer_
std::shared_ptr< OptimizationStopCondition > getStopCondition() override
bool updateParameters() const override
void setProfiler(std::shared_ptr< OutputStream > profiler) override
std::shared_ptr< FunctionInterface > function_
void init(const ParameterList ¶ms) override
void printMessage(const std::string &message)
std::string getConstraintPolicy() const override
void setConstraintPolicy(const std::string &constraintPolicy) override
std::shared_ptr< OutputStream > getMessageHandler() const override
const FunctionInterface & function() const override
std::shared_ptr< OptimizationStopCondition > getDefaultStopCondition() override
void setMessageHandler(std::shared_ptr< OutputStream > mh) override
double getFunctionValue() const override
void setStopCondition(std::shared_ptr< OptimizationStopCondition > stopCondition) override
std::shared_ptr< OutputStream > getProfiler() const override
ParameterList & getParameters_()
void setDefaultStopCondition_(std::shared_ptr< OptimizationStopCondition > osc)
std::shared_ptr< const FunctionInterface > getFunction() const override
const ParameterList & getParameters() const override
double optimize() override
void setMaximumNumberOfEvaluations(unsigned int max) override
void setVerbose(unsigned int v) override
virtual double getFirstOrderDerivative(const std::string &variable) const=0
virtual void setParameters(const ParameterList ¶meters)=0
virtual std::vector< std::string > getParameterNames() const
bool isToleranceReached() const
double getCurrentTolerance() const
This Optimizer implements Newton's algorithm for finding a minimum of a function. This is in fact a m...
ParameterList previousPoint_
PseudoNewtonOptimizer(std::shared_ptr< SecondOrderDerivable > function)
std::vector< std::string > params_
const SecondOrderDerivable & secondOrderDerivableFunction() const
void doInit(const ParameterList ¶ms)
unsigned int maxCorrection_
virtual void enableSecondOrderDerivatives(bool yn)=0
virtual double getSecondOrderDerivative(const std::string &variable) const=0
std::string toString(T t)
std::size_t count(const std::string &s, const std::string &pattern)
Defines the basic types of data flow nodes.