12 if (computeD1_ && variables_.size() > 0)
15 function1_->enableFirstOrderDerivatives(
false);
17 function2_->enableSecondOrderDerivatives(
false);
18 function_->setParameters(parameters);
19 f2_ = function_->getValue();
22 for (
size_t i = 0; i < variables_.size(); ++i)
31 bool functionChanged =
false;
34 for (
size_t i = 0; i < variables_.size(); ++i)
36 string var = variables_[i];
41 vector<string> vars(2);
52 functionChanged =
true;
54 double h = -(1. + std::abs(value)) * h_;
55 if (abs(h) < p[0].getPrecision())
56 h = h < 0 ? -p[0].getPrecision() : p[0].getPrecision();
57 double hf1(0), hf3(0);
58 unsigned int nbtry = 0;
65 p[0].setValue(value + h);
69 f1_ = function_->getValue();
99 p[0].setValue(value + h);
103 f3_ = function_->getValue();
128 der1_[i] = (f1_ - f3_) / (hf1 - hf3);
129 der2_[i] = ((f1_ - f2_) / hf1 - (f3_ - f2_) / hf3) * 2 / (hf1 - hf3);
136 string lastVar1, lastVar2;
137 for (
unsigned int i = 0; i < variables_.size(); i++)
139 string var1 = variables_[i];
142 for (
unsigned int j = 0; j < variables_.size(); j++)
146 crossDer2_(i, j) = der2_[i];
149 string var2 = variables_[j];
153 vector<string> vars(2);
158 if (lastVar1 != var1 && lastVar1 != var2)
159 vars.push_back(lastVar1);
160 if (lastVar2 != var1 && lastVar2 != var2)
161 vars.push_back(lastVar2);
166 double value2 = function_->getParameterValue(var2);
167 double h1 = (1. + std::abs(value1)) * h_;
168 double h2 = (1. + std::abs(value2)) * h_;
173 p[0].setValue(value1 - h1);
174 p[1].setValue(value2 - h2);
176 vector<size_t> tmp(2);
180 f11_ = function_->getValue();
182 p[1].setValue(value2 + h2);
184 f12_ = function_->getValue();
186 p[0].setValue(value1 + h1);
188 f22_ = function_->getValue();
190 p[1].setValue(value2 - h2);
192 f21_ = function_->getValue();
194 crossDer2_(i, j) = ((f22_ - f21_) - (f12_ - f11_)) / (4 * h1 * h2);
198 throw Exception(
"ThreePointsNumericalDerivative::setParameters. Could not compute cross derivatives at limit.");
209 function1_->enableFirstOrderDerivatives(computeD1_);
211 function2_->enableSecondOrderDerivatives(computeD2_);
219 function1_->enableFirstOrderDerivatives(computeD1_);
221 function2_->enableSecondOrderDerivatives(computeD2_);
222 function_->setParameters(parameters);
224 f2_ = function_->getValue();
virtual ParameterList createSubList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
virtual double getParameterValue(const std::string &name) const
Get the value of the parameter with name name.
void updateDerivatives(const ParameterList ¶meters) override
Compute derivatives.
The parameter list object.
virtual bool hasParameter(const std::string &name) const
virtual void setParameters(const ParameterList ¶ms)
Update the parameters from params.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Exception thrown when a value do not match a given constraint.