48 if (computeD1_ && variables_.size() > 0)
51 function1_->enableFirstOrderDerivatives(
false);
53 function2_->enableSecondOrderDerivatives(
false);
54 function_->setParameters(parameters);
55 f2_ = function_->getValue();
58 for (
size_t i = 0; i < variables_.size(); ++i)
67 bool functionChanged =
false;
70 for (
size_t i = 0; i < variables_.size(); ++i)
72 string var = variables_[i];
73 if (!parameters.hasParameter(var))
77 vector<string> vars(2);
88 functionChanged =
true;
90 double h = -(1. + std::abs(value)) * h_;
91 if (abs(h) < p[0].getPrecision())
92 h = h < 0 ? -p[0].getPrecision() : p[0].getPrecision();
93 double hf1(0), hf3(0);
94 unsigned int nbtry = 0;
101 p[0].setValue(value + h);
105 f1_ = function_->getValue();
135 p[0].setValue(value + h);
139 f3_ = function_->getValue();
164 der1_[i] = (f1_ - f3_) / (hf1 - hf3);
165 der2_[i] = ((f1_ - f2_) / hf1 - (f3_ - f2_) / hf3) * 2 / (hf1 - hf3);
172 string lastVar1, lastVar2;
173 for (
unsigned int i = 0; i < variables_.size(); i++)
175 string var1 = variables_[i];
176 if (!parameters.hasParameter(var1))
178 for (
unsigned int j = 0; j < variables_.size(); j++)
182 crossDer2_(i, j) = der2_[i];
185 string var2 = variables_[j];
186 if (!parameters.hasParameter(var2))
189 vector<string> vars(2);
194 if (lastVar1 != var1 && lastVar1 != var2)
195 vars.push_back(lastVar1);
196 if (lastVar2 != var1 && lastVar2 != var2)
197 vars.push_back(lastVar2);
202 double value2 = function_->getParameterValue(var2);
203 double h1 = (1. + std::abs(value1)) * h_;
204 double h2 = (1. + std::abs(value2)) * h_;
209 p[0].setValue(value1 - h1);
210 p[1].setValue(value2 - h2);
212 vector<size_t> tmp(2);
216 f11_ = function_->getValue();
218 p[1].setValue(value2 + h2);
220 f12_ = function_->getValue();
222 p[0].setValue(value1 + h1);
224 f22_ = function_->getValue();
226 p[1].setValue(value2 - h2);
228 f21_ = function_->getValue();
230 crossDer2_(i, j) = ((f22_ - f21_) - (f12_ - f11_)) / (4 * h1 * h2);
234 throw Exception(
"ThreePointsNumericalDerivative::setParameters. Could not compute cross derivatives at limit.");
245 function1_->enableFirstOrderDerivatives(computeD1_);
247 function2_->enableSecondOrderDerivatives(computeD2_);
249 function_->setParameters(parameters.subList(lastVar));
255 function1_->enableFirstOrderDerivatives(computeD1_);
257 function2_->enableSecondOrderDerivatives(computeD2_);
258 function_->setParameters(parameters);
260 f2_ = function_->getValue();
Exception thrown when a parameter is not found, for instance in a ParameterList.
virtual ParameterList subList(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 parameters)
Compute derivatives.
This class allows to perform a correspondence analysis.
The parameter list object.
virtual void setParameters(const ParameterList ¶ms)
Update the parameters from params.
Exception thrown when a value do not match a given constraint.