49 if (computeD1_ && variables_.size() > 0)
52 function1_->enableFirstOrderDerivatives(
false);
54 function2_->enableSecondOrderDerivatives(
false);
55 function_->setParameters(parameters);
56 f2_ = function_->getValue();
59 for (
size_t i = 0; i < variables_.size(); ++i)
68 bool functionChanged =
false;
71 for (
size_t i = 0; i < variables_.size(); ++i)
73 string var = variables_[i];
78 vector<string> vars(2);
89 functionChanged =
true;
91 double h = -(1. + std::abs(value)) * h_;
92 if (abs(h) < p[0].getPrecision())
93 h = h < 0 ? -p[0].getPrecision() : p[0].getPrecision();
94 double hf1(0), hf3(0);
95 unsigned int nbtry = 0;
102 p[0].setValue(value + h);
106 f1_ = function_->getValue();
136 p[0].setValue(value + h);
140 f3_ = function_->getValue();
165 der1_[i] = (f1_ - f3_) / (hf1 - hf3);
166 der2_[i] = ((f1_ - f2_) / hf1 - (f3_ - f2_) / hf3) * 2 / (hf1 - hf3);
173 string lastVar1, lastVar2;
174 for (
unsigned int i = 0; i < variables_.size(); i++)
176 string var1 = variables_[i];
179 for (
unsigned int j = 0; j < variables_.size(); j++)
183 crossDer2_(i, j) = der2_[i];
186 string var2 = variables_[j];
190 vector<string> vars(2);
195 if (lastVar1 != var1 && lastVar1 != var2)
196 vars.push_back(lastVar1);
197 if (lastVar2 != var1 && lastVar2 != var2)
198 vars.push_back(lastVar2);
203 double value2 = function_->getParameterValue(var2);
204 double h1 = (1. + std::abs(value1)) * h_;
205 double h2 = (1. + std::abs(value2)) * h_;
210 p[0].setValue(value1 - h1);
211 p[1].setValue(value2 - h2);
213 vector<size_t> tmp(2);
217 f11_ = function_->getValue();
219 p[1].setValue(value2 + h2);
221 f12_ = function_->getValue();
223 p[0].setValue(value1 + h1);
225 f22_ = function_->getValue();
227 p[1].setValue(value2 - h2);
229 f21_ = function_->getValue();
231 crossDer2_(i, j) = ((f22_ - f21_) - (f12_ - f11_)) / (4 * h1 * h2);
235 throw Exception(
"ThreePointsNumericalDerivative::setParameters. Could not compute cross derivatives at limit.");
246 function1_->enableFirstOrderDerivatives(computeD1_);
248 function2_->enableSecondOrderDerivatives(computeD2_);
256 function1_->enableFirstOrderDerivatives(computeD1_);
258 function2_->enableSecondOrderDerivatives(computeD2_);
259 function_->setParameters(parameters);
261 f2_ = function_->getValue();
Exception thrown when a value do not match a given constraint.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
The parameter list object.
virtual bool hasParameter(const std::string &name) const
virtual void setParameters(const ParameterList ¶ms)
Update the parameters from params.
virtual double getParameterValue(const std::string &name) const
Get the value of the parameter with name name.
virtual ParameterList createSubList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
void updateDerivatives(const ParameterList parameters)
Compute derivatives.