42 #include "../NumTools.h" 43 #include "../NumConstants.h" 44 #include "../../Text/TextTools.h" 71 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),
87 if (params.size() != 1)
88 throw Exception(
"BrentOneDimension::init(). This optimizer only deals with one parameter.");
94 printMessage(
"Initial bracketing:");
104 a = (bracket.
a.
x < bracket.
c.
x ? bracket.
a.
x : bracket.
c.
x);
105 b = (bracket.
a.
x > bracket.
c.
x ? bracket.
a.
x : bracket.
c.
x);
107 fw = fv = fx = getFunction()->f(getParameters());
108 if (fx < bracket.
b.
f)
111 x = w = v = bracket.
b.
x = getParameters()[0].getValue();
115 x = w = v = bracket.
b.
x;
116 getParameter_(0).setValue(x);
117 fw = fv = fx = getFunction()->f(getParameters());
175 if (
u >=
x)
a =
x;
else b =
x;
181 if (
u <
x)
a =
u;
else b =
u;
189 else if (
fu <=
fv ||
v ==
x ||
v ==
w)
206 throw Exception(
"BrentOneDimension::optimize. Initial interval not set: call the 'setInitialInterval' method first!");
virtual double f(const ParameterList ¶meters)
Get the value of the function according to a given set of parameters.
OptimizationStopCondition * getStopCondition()
Get the stop condition of the optimization algorithm.
This class allows to perform a correspondence analysis.
double optimize()
Basic implementation.
This is the function abstract class.
static double GOLDEN_RATIO_C()
void setMaximumNumberOfEvaluations(unsigned int max)
Set the maximum number of function evaluation to perform during optimization.
static std::string toString(T t)
General template method to convert to a string.
The parameter list object.
bool isInitialIntervalSet_
virtual void setValue(double value)
Set the value of this parameter.
void setDefaultStopCondition_(OptimizationStopCondition *osc)
Parameter & getParameter_(size_t i)
const Function * getFunction() const
Get the current function being optimized.
const ParameterList & getParameters() const
bool isToleranceReached() const
Tell if the we reached the desired tolerance with a given new set of estimates.
friend class BODStopCondition
double getCurrentTolerance() const
Get the current tolerance.
double optimize()
Initialize optimizer.
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.
void setStopCondition(const OptimizationStopCondition &stopCondition)
Set the stop condition of the optimization algorithm.
double doStep()
This function is called by the step() method and contains all calculations.
virtual double getTolerance() const =0
Get the tolerance parameter.
void setInitialInterval(double inf, double sup)
Set intial search interval.
OptimizationStopCondition * getDefaultStopCondition()
Get the default stop condition of the optimization algorithm.
BrentOneDimension(Function *function=0)
const Optimizer * optimizer_