1 #ifndef __JFIT__JSIMPLEX__
2 #define __JFIT__JSIMPLEX__
18 namespace JPP {
using namespace JFIT; }
41 template<
class JModel_t>
43 public JMessage< JSimplex<JModel_t> >
70 template<
class JFunction_t,
class T>
71 double operator()(
const JFunction_t& fit, T __begin, T __end)
76 double chi2_old =
evaluate(fit, __begin, __end);
78 const int N =
step.size();
88 DEBUG(
"old: " <<
FIXED(12,5) << chi2_old << endl);
90 const JModel_t p0(
value);
92 for (
int i = 0; i != N; ++i) {
96 chi2[i] = (*this)(fit, __begin, __end,
step[i]);
101 JModel_t wall =
value - p0;
103 const double chi2_new = (*this)(fit, __begin, __end, wall);
105 DEBUG(
"new: " <<
FIXED(12,5) << chi2_new << endl);
108 if (fabs(chi2_old - chi2_new) <
EPSILON*fabs(chi2_old)) {
118 const double fe =
evaluate(fit, __begin, __end);
123 for (
int i = N-1; i != 0; --i) {
124 chi2[i] = chi2[i-1] - chi2[i];
127 chi2[0] = chi2_old - chi2[0];
132 for (
int i = 0; i != N; ++i) {
138 const double fn = chi2_new;
139 const double f0 = chi2_old;
140 const double ff = f0 - fn - df;
144 if (fe < f0 && 2.0*(f0 - 2.0*fn + fe)*ff*ff < (f0-fe)*(f0-fe)*df) {
146 for (
int i = 0; i != N - 1; ++i) {
172 template<
class JFunction_t,
class T>
173 double operator()(
const JFunction_t& fit, T __begin, T __end,
const JModel_t&
step)
181 double chi2_old =
evaluate(fit, __begin, __end);
187 const double chi2_new =
evaluate(fit, __begin, __end);
189 DEBUG(
"step: " << setw(3) << i <<
' ' <<
FIXED(12,5) << chi2_old <<
' ' <<
FIXED(12,5) << chi2_new <<
' ' <<
FIXED(5,2) << lambda << endl);
191 if (fabs(chi2_old - chi2_new) <
EPSILON*fabs(chi2_old)) {
193 if (chi2_new > chi2_old) {
205 if (chi2_new < chi2_old) {
219 lambda = factor * lambda;
241 template<
class JFunction_t,
class T>
242 inline double evaluate(
const JFunction_t& fit, T __begin, T __end)
const
246 for (T hit = __begin; hit != __end; ++hit) {
247 chi2 += fit(
value, *hit);
258 template<
class JModel_t>
265 template<
class JModel_t>