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>
76 double chi2_old =
evaluate(fit, __begin, __end);
78 const int N =
step.size();
92 DEBUG(
"old: " <<
FIXED(12,5) << chi2_old << endl);
96 for (
int i = 0; i !=
N; ++i) {
100 chi2[i] = (*this)(fit, __begin, __end,
step[i]);
108 const double chi2_new = (*this)(fit, __begin, __end,
wall);
110 DEBUG(
"new: " <<
FIXED(12,5) << chi2_new << endl);
113 if (fabs(chi2_old - chi2_new) <
EPSILON*fabs(chi2_old)) {
123 const double fe =
evaluate(fit, __begin, __end);
128 for (
int i =
N-1; i != 0; --i) {
129 chi2[i] = chi2[i-1] - chi2[i];
132 chi2[0] = chi2_old - chi2[0];
137 for (
int i = 0; i !=
N; ++i) {
143 const double fn = chi2_new;
144 const double f0 = chi2_old;
145 const double ff = f0 - fn - df;
149 if (fe < f0 && 2.0*(f0 - 2.0*fn + fe)*ff*ff < (f0-fe)*(f0-fe)*df) {
151 for (
int i = 0; i !=
N - 1; ++i) {
177 template<
class JFunction_t,
class T>
186 double chi2_old =
evaluate(fit, __begin, __end);
194 const double chi2_new =
evaluate(fit, __begin, __end);
196 DEBUG(
"step: " << setw(3) << i <<
' ' <<
FIXED(12,5) << chi2_old <<
' ' <<
FIXED(12,5) << chi2_new <<
' ' <<
FIXED(5,2) << lambda << endl);
198 if (fabs(chi2_old - chi2_new) <
EPSILON*fabs(chi2_old)) {
200 if (chi2_new > chi2_old) {
214 if (chi2_new < chi2_old) {
230 lambda = factor * lambda;
252 template<
class JFunction_t,
class T>
253 inline double evaluate(
const JFunction_t& fit,
T __begin,
T __end)
const
257 for (
T hit = __begin; hit != __end; ++hit) {
258 chi2 += fit(
value, *hit);
273 template<
class JModel_t>
280 template<
class JModel_t>
static int debug
debug level (default is off).
double operator()(const JFunction_t &fit, T __begin, T __end, const JModel_t &step)
1D fit.
Auxiliary data structure for floating point format specification.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
General purpose messaging.
double operator()(const JFunction_t &fit, T __begin, T __end)
Multi-dimensional fit.
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++...
JSimplex()
Default constructor.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
double evaluate(const JFunction_t &fit, T __begin, T __end) const
Evaluate chi2 for given data set.
static int MAXIMUM_ITERATIONS
maximal number of iterations
static double EPSILON
maximal distance to minimum
then usage $script[input file[working directory[option]]] nWhere option can be N
Auxiliary class for handling debug parameter within a class.
std::vector< JModel_t > step