1 #ifndef __JFIT__JGANDALF__
2 #define __JFIT__JGANDALF__
21 namespace JPP {
using namespace JFIT; }
44 template<
class JModel_t>
46 public JMessage< JGandalf<JModel_t> >
79 const JModel_t __model) :
90 operator double()
const
121 template<
class JFunction_t,
class T1,
class T2>
123 T1 __begin1, T1 __end1,
124 T2 __begin2, T2 __end2)
137 double chi2_old = numeric_limits<double>::max();
151 if (
chi2 < chi2_old) {
155 if (fabs(chi2_old -
chi2) <
EPSILON*fabs(chi2_old)) {
180 DEBUG(
"Hesse matrix:" << endl);
186 for (
int i = 0; i != N; ++i) {
192 h[i] = 1.0 / sqrt(
H(i,i));
198 for (
int i = 0; i != N; ++i) {
199 for (
int j = 0; j != i; ++j) {
200 H(j,i) *=
h[i] *
h[j];
205 for (
int i = 0; i != N; ++i) {
214 ERROR(
"JGandalf: " << error.
what() << endl);
219 for (
int i = 0; i != N; ++i) {
223 for (
int j = 0; j != N; ++j) {
248 template<
class JFunction_t,
class T>
249 double operator()(
const JFunction_t& fit, T __begin, T __end)
251 return (*
this)(fit, __begin, __end, __end, __end);
291 template<
class JFunction_t,
class T>
292 inline void evaluate(
const JFunction_t& fit, T __begin, T __end)
294 for (T hit = __begin; hit != __end; ++hit) {
296 const result_type& result = fit(value, *hit);
301 for (
unsigned int i = 0; i != parameters.size(); ++i) {
302 for (
unsigned int j = i; j != parameters.size(); ++j) {
303 H(i,j) += result.gradient.*parameters[i] * result.gradient.*parameters[j];
319 template<
class JModel_t>
326 template<
class JModel_t>
333 template<
class JModel_t>
340 template<
class JModel_t>
347 template<
class JModel_t>
354 template<
class JModel_t>
361 template<
class JModel_t>
static int debug
debug level (default is off).
static double EPSILON
maximal distance to minimum
static double PIVOT
minimal value diagonal element of matrix
Auxiliary data structure for floating point format specification.
std::vector< parameter_type > parameters
static double LAMBDA_MIN
minimal value control parameter
static double LAMBDA_DOWN
multiplication factor control parameter
void resize(const size_t size)
Resize matrix.
double operator()(const JFunction_t &fit, T __begin, T __end)
Multi-dimensional fit of one data set.
I/O formatting auxiliaries.
JMatrixND & reset()
Set matrix to the null matrix.
void evaluate(const JFunction_t &fit, T __begin, T __end)
Evaluate fit for given data set.
JModel_t gradient
d(chi2)/d(...)
double chi2
chi2 of data point
General purpose messaging.
static double LAMBDA_UP
multiplication factor control parameter
Fit method based on the Levenberg-Marquardt method.
Data structure for return value of fit function.
double operator()(const JFunction_t &fit, T1 __begin1, T1 __end1, T2 __begin2, T2 __end2)
Multi-dimensional fit of two data sets.
result_type(const double __chi2, const JModel_t __model)
Constructor.
static int MAXIMUM_ITERATIONS
maximal number of iterations
static double LAMBDA_MAX
maximal value control parameter
virtual const char * what() const
Get error message.
result_type()
Default constructor.
Auxiliary data structure for floating point format specification.
void invert()
Invert matrix.
JModel_t::parameter_type parameter_type
Data type of fit parameter.
#define DEBUG(A)
Message macros.
Auxiliary class for handling debug parameter within a class.
JGandalf()
Default constructor.