48 if (computeD1_ && variables_.size() > 0)
50 if (function1_) function1_->enableFirstOrderDerivatives(
false);
51 if (function2_) function2_->enableSecondOrderDerivatives(
false);
52 function_->setParameters(parameters);
53 f2_ = function_->getValue();
55 for (
unsigned int i = 0; i < variables_.size(); i++){
63 bool functionChanged =
false;
66 for (
unsigned int i = 0; i < variables_.size(); i++)
68 string var = variables_[i];
69 if (!parameters.hasParameter(var))
continue;
72 vector<string> vars(2);
83 functionChanged =
true;
85 double h = -(1. + std::abs(value)) * h_;
86 if (abs(h)<p[0].getPrecision())
87 h=h<0?-p[0].getPrecision():p[0].getPrecision();
88 double hf1(0), hf3(0);
95 p[0].setValue(value + h);
99 f1_ = function_->getValue();
128 p[0].setValue(value + h);
132 f3_ = function_->getValue();
156 der1_[i] = (f1_ - f3_) / (hf1-hf3);
157 der2_[i] = ((f1_ - f2_)/hf1 - (f3_ - f2_)/hf3)*2/(hf1-hf3);
166 string lastVar1, lastVar2;
167 for (
unsigned int i = 0; i < variables_.size(); i++)
169 string var1 = variables_[i];
170 if (!parameters.hasParameter(var1))
continue;
171 for (
unsigned int j = 0; j < variables_.size(); j++)
175 crossDer2_(i, j) = der2_[i];
178 string var2 = variables_[j];
179 if (!parameters.hasParameter(var2))
continue;
181 vector<string> vars(2);
186 if (lastVar1 != var1 && lastVar1 != var2) vars.push_back(lastVar1);
187 if (lastVar2 != var1 && lastVar2 != var2) vars.push_back(lastVar2);
192 double value2 = function_->getParameterValue(var2);
193 double h1 = (1. + std::abs(value1)) * h_;
194 double h2 = (1. + std::abs(value2)) * h_;
199 p[0].setValue(value1 - h1);
200 p[1].setValue(value2 - h2);
202 vector<size_t> tmp(2);
206 f11_ = function_->getValue();
208 p[1].setValue(value2 + h2);
210 f12_ = function_->getValue();
212 p[0].setValue(value1 + h1);
214 f22_ = function_->getValue();
216 p[1].setValue(value2 - h2);
218 f21_ = function_->getValue();
220 crossDer2_(i, j) = ((f22_ - f21_) - (f12_ - f11_)) / (4 * h1 * h2);
224 throw Exception(
"ThreePointsNumericalDerivative::setParameters. Could not compute cross derivatives at limit.");
234 if (function1_) function1_->enableFirstOrderDerivatives(computeD1_);
235 if (function2_) function2_->enableSecondOrderDerivatives(computeD2_);
237 function_->setParameters(parameters.subList(lastVar));
242 if (function1_) function1_->enableFirstOrderDerivatives(computeD1_);
243 if (function2_) function2_->enableSecondOrderDerivatives(computeD2_);
244 function_->setParameters(parameters);
246 f2_ = function_->getValue();