43 #include "../NumTools.h" 44 #include "../NumConstants.h" 72 parameters[0].setValue(bracket.
a.
x); bracket.
a.
f =
function->f(parameters);
74 parameters[0].setValue(bracket.
b.
x); bracket.
b.
f =
function->f(parameters);
75 if (bracket.
b.
f > bracket.
a.
f)
79 NumTools::swap<double>(bracket.
a.
x, bracket.
b.
x);
80 NumTools::swap<double>(bracket.
a.
f, bracket.
b.
f);
85 parameters[0].setValue(bracket.
c.
x); bracket.
c.
f =
function->f(parameters);
88 while (bracket.
b.
f > bracket.
c.
f)
92 double r = (bracket.
b.
x - bracket.
a.
x) * (bracket.
b.
f - bracket.
c.
f);
93 double q = (bracket.
b.
x - bracket.
c.
x) * (bracket.
b.
f - bracket.
a.
f);
95 double xu = bracket.
b.
x - ((bracket.
b.
x - bracket.
c.
x) * q - (bracket.
b.
x - bracket.
a.
x) * r) /
97 double xulim = (bracket.
b.
x) + GLIMIT * (bracket.
c.
x - bracket.
b.
x);
102 if ((bracket.
b.
x - xu) * (xu - bracket.
c.
x) > 0.0)
104 parameters[0].setValue(xu); fu =
function->f(parameters);
105 if (fu < bracket.
c.
f)
107 bracket.
setA(bracket.
b.
x, bracket.
b.
f);
108 bracket.
setB(xu, fu);
111 else if (fu > bracket.
b.
f)
113 bracket.
setC(xu, fu);
119 parameters[0].setValue(xu); fu =
function->f(parameters);
121 else if ((bracket.
c.
x - xu) * (xu - xulim) > 0.0)
124 parameters[0].setValue(xu); fu =
function->f(parameters);
125 if (fu < bracket.
c.
f)
128 parameters[0].setValue(xu);
129 NumTools::shift<double>(bracket.
b.
f, bracket.
c.
f, fu,
function->f(parameters));
132 else if ((xu - xulim) * (xulim - bracket.
c.
x) >= 0.0)
136 parameters[0].setValue(xu); fu =
function->f(parameters);
142 parameters[0].setValue(xu); fu =
function->f(parameters);
145 NumTools::shift<double>(bracket.
a.
x, bracket.
b.
x, bracket.
c.
x, xu);
146 NumTools::shift<double>(bracket.
a.
f, bracket.
b.
f, bracket.
c.
f, fu);
156 std::vector<double>& xi,
160 unsigned int verbose)
168 f1dim.
init(parameters, xi);
179 bod.
init(singleParameter);
185 for (
size_t j = 0; j < parameters.
size(); j++)
188 parameters[j].setValue(parameters[j].getValue() + xi[j]);
197 std::vector<double>& xi,
198 std::vector<double>& gradient,
201 unsigned int verbose)
203 size_t size = xi.size();
207 f1dim.
init(parameters, xi);
210 for (
size_t i = 0; i < size; i++)
212 slope += xi[i] * gradient[i];
218 double x, temp, test = 0;
219 for (
size_t i = 0; i < size; ++i)
221 x = abs(parameters[i].getValue());
240 nbod.
init(singleParameter);
246 for (
unsigned int j = 0; j < parameters.
size(); j++)
249 parameters[j].setValue(parameters[j].getValue() + xi[j]);
void setConstraintPolicy(const std::string &constraintPolicy)
void init(const ParameterList &p, const std::vector< double > &xi)
unsigned int getNumberOfEvaluations() const
Get the number of function evaluations performed since the call of the init function.
OptimizationStopCondition * getStopCondition()
Get the stop condition of the optimization algorithm.
This class allows to perform a correspondence analysis.
double optimize()
Basic implementation.
static std::string CONSTRAINTS_KEEP
This is the function abstract class.
static double GOLDEN_RATIO_PHI()
This class is designed to facilitate the manipulation of parameters.
void setMessageHandler(OutputStream *messenger)
static double VERY_TINY()
void setB(double xb, double fb)
void setA(double xa, double fa)
void setC(double xc, double fc)
virtual void setTolerance(double tolerance)=0
Set the tolerance parameter.
The parameter list object.
void setOptimizationProgressCharacter(const std::string &c)
Set the character to be displayed during optimization.
Newton's backtrack nearly optimization for one parameter.
double optimize()
Initialize optimizer.
virtual void addParameter(const Parameter ¶m)
Add a new parameter at the end of the list.
void setProfiler(OutputStream *profiler)
Set the profiler for this optimizer.
Brent's optimization for one parameter.
void setVerbose(unsigned int v)
Set the verbose level.
static std::string CONSTRAINTS_AUTO
const ParameterList & getParameters() const
Get all parameters available.
void set(double x, double f)
void setConstraintPolicy(const std::string &constraintPolicy)
Set the constraint policy for this optimizer.
void setMessageHandler(OutputStream *mh)
Set the message handler for this optimizer.
void setInitialInterval(double inf, double sup)
Set intial search interval.
void init(const ParameterList ¶ms)
Basic implementation.