1 #ifndef __JFIT__JGANDALF__
2 #define __JFIT__JGANDALF__
24 namespace JPP {
using namespace JFIT; }
31 namespace JFIT_LOCAL {
35 template<
class U>
static auto parameter_type(U*) -> decltype(std::declval<typename U::parameter_type>());
36 template<
typename>
static auto parameter_type(...) -> std::false_type;
39 static const bool has_parameter_type = !std::is_same<std::false_type, decltype(parameter_type<T> (0))>::value;
42 template<class T, bool has_parameter_type = JTypedef<T>::has_parameter_type>
55 template<
class JModel_t>
56 inline void model(JModel_t& value)
83 template<
class JModel_t>
85 public JMessage< JGandalf<JModel_t> >
118 const JModel_t&
model) :
129 operator double()
const
159 template<
class JFunction_t,
class T,
class ...Args>
175 previous.result.chi2 = numeric_limits<double>::max();
177 current.result.chi2 = numeric_limits<double>::max();
192 update(fit, __begin, __end, args...);
211 update(fit, __begin, __end, args...);
216 catch (
const exception&
error) {
220 for (
size_t i = 0;
i !=
N; ++
i) {
249 update(fit, __begin, __end, args...);
252 DEBUG(
"Hesse matrix:" << endl <<
V << endl);
256 for (
size_t i = 0;
i !=
N; ++
i) {
262 h[
i] = 1.0 / sqrt(
V(
i,
i));
267 for (
size_t row = 0; row !=
N; ++row) {
268 for (
size_t col = 0; col != row; ++col) {
269 V(row,col) *=
h[row] *
h[col];
270 V(col,row) =
V(row,col);
274 for (
size_t i = 0;
i !=
N; ++
i) {
280 for (
size_t col = 0; col !=
N; ++col) {
287 catch (
const exception&
error) {
289 ERROR(
"JGandalf: " << error.what() << endl <<
V << endl);
296 for (
size_t row = 0; row !=
N; ++row) {
318 update(fit, __begin, __end, args...);
323 catch (
const exception&
error) {
327 for (
size_t i = 0;
i !=
N; ++
i) {
373 template<
class JFunction_t,
class T,
class ...Args>
374 inline void update(
const JFunction_t& fit, T __begin, T __end, Args ...
args)
376 for (T
i = __begin;
i != __end; ++
i) {
380 current.result.chi2 += result.chi2;
381 current.result.gradient += result.gradient;
383 for (
size_t row = 0; row !=
parameters.size(); ++row) {
384 for (
size_t col = row; col !=
parameters.size(); ++col) {
399 template<
class JFunction_t>
400 inline void update(
const JFunction_t& fit)
402 for (
size_t row = 0; row !=
parameters.size(); ++row) {
403 for (
size_t col = 0; col != row; ++col) {
404 V(row,col) =
V(col,row);
417 static inline double get(
const JModel_t&
model,
double JModel_t::*parameter)
419 return model.*parameter;
430 static inline double&
get(JModel_t&
model,
double JModel_t::*parameter)
432 return model.*parameter;
443 static inline double get(
const JModel_t&
model,
const size_t index)
456 static inline double&
get(JModel_t&
model,
const size_t index)
469 static inline double get(
const JModel_t&
model,
const int index)
482 static inline double&
get(JModel_t&
model,
const int index)
504 template<
class JModel_t>
511 template<
class JModel_t>
518 template<
class JModel_t>
525 template<
class JModel_t>
532 template<
class JModel_t>
539 template<
class JModel_t>
546 template<
class JModel_t>
T::parameter_type parameter_type
static int debug
debug level (default is off).
double lambda
control parameter
static double EPSILON
maximal distance to minimum
JFIT_LOCAL::JTypedef_t< JModel_t >::parameter_type parameter_type
Data type of fit parameter.
static double PIVOT
minimal value diagonal element of Hesse matrix
JMATH::JMatrixNS V
Hesse matrix.
static const JZero zero
Function object to assign zero value.
JMatrixND & reset()
Set matrix to the null matrix.
Auxiliary data structure for floating point format specification.
std::vector< parameter_type > parameters
fit parameters
void resize(const size_t size)
Resize matrix.
static double LAMBDA_MIN
minimal value control parameter
static double LAMBDA_DOWN
multiplication factor control parameter
Definition of zero value for any class.
void reset()
Reset current parameters.
void update(const JFunction_t &fit)
Termination method to update current parameters.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JModel_t gradient
partial derivatives of chi2
result_type operator()(const JFunction_t &fit, T __begin, T __end, Args...args)
Multi-dimensional fit of multiple data sets.
void update(const JFunction_t &fit, T __begin, T __end, Args...args)
Recursive method to update current parameters.
struct JFIT::JGandalf::@10 current
static auto parameter_type(U *) -> decltype(std::declval< typename U::parameter_type >())
General purpose messaging.
static double LAMBDA_UP
multiplication factor control parameter
void invert()
Invert matrix according LDU decomposition.
Fit method based on the Levenberg-Marquardt method.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Data structure for return value of fit function.
void solve(JVectorND_t &u)
Get solution of equation A x = b.
static const bool has_parameter_type
result_type(const double chi2, const JModel_t &model)
Constructor.
static int MAXIMUM_ITERATIONS
maximal number of iterations
int numberOfIterations
number of iterations
static double LAMBDA_MAX
maximal value control parameter
result_type()
Default constructor.
struct JFIT::JGandalf::@11 previous
double T::* parameter_type
#define DEBUG(A)
Message macros.
Auxiliary class for handling debug parameter within a class.
JGandalf()
Default constructor.