5 #include "../../Text/TextTools.h" 6 #include "../NumConstants.h" 7 #include "../NumTools.h" 37 a(0),
b(0),
d(0),
e(0),
etemp(0),
fu(0),
fv(0),
fw(0),
fx(0),
p(0),
q(0),
r(0),
tol1(0),
tol2(0),
53 if (params.
size() != 1)
54 throw Exception(
"BrentOneDimension::init(). This optimizer only deals with one parameter.");
79 a = (bracket.
a.
x < bracket.
c.
x ? bracket.
a.
x : bracket.
c.
x);
80 b = (bracket.
a.
x > bracket.
c.
x ? bracket.
a.
x : bracket.
c.
x);
90 x =
w =
v = bracket.
b.
x;
173 else if (
fu <=
fv ||
v ==
x ||
v ==
w)
190 throw Exception(
"BrentOneDimension::optimize. Initial interval not set: call the 'setInitialInterval' method first!");
double optimize() override
Basic implementation.
std::shared_ptr< OptimizationStopCondition > getStopCondition() override
Get the stop condition of the optimization algorithm.
void setDefaultStopCondition_(std::shared_ptr< OptimizationStopCondition > osc)
const ParameterList & getParameters() const override
static double GOLDEN_RATIO_C()
The parameter list object.
bool isInitialIntervalSet_
virtual void setValue(double value)
Set the value of this parameter.
unsigned int getVerbose() const override
Get the verbose level.
BrentOneDimension(std::shared_ptr< FunctionInterface > function=nullptr)
const OptimizerInterface * optimizer_
Parameter & getParameter_(size_t i)
bool isToleranceReached() const
Tell if the we reached the desired tolerance with a given new set of estimates.
double getCurrentTolerance() const
Get the current tolerance.
double optimize()
Initialize optimizer.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Brent's optimization for one parameter.
double callCount_
Count the number of times the isToleranceReached() function has been called.
Partial implementation of the Optimizer interface.
double currentValue_
The current value of the function.
void doInit(const ParameterList ¶ms)
This function is called by the init() method and contains all calculations.
const FunctionInterface & function() const override
Get the current function being optimized.
double doStep()
This function is called by the step() method and contains all calculations.
void setInitialInterval(double inf, double sup)
Set intial search interval.
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.
void setMaximumNumberOfEvaluations(unsigned int max) override
Set the maximum number of function evaluation to perform during optimization.
std::shared_ptr< OptimizationStopCondition > getDefaultStopCondition() override
Get the default stop condition of the optimization algorithm.
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.