Jpp
JRegressor.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JREGRESSOR__
2 #define __JFIT__JREGRESSOR__
3 
4 #include "Jeep/JMessage.hh"
5 
6 
7 /**
8  * \file
9  * General purpose data regression method.
10  * \author mdejong
11  */
12 namespace JFIT {}
13 namespace JPP { using namespace JFIT; }
14 
15 namespace JFIT {
16 
17  using JEEP::JMessage;
18 
19 
20  /**
21  * Abstract minimiser.
22  * This "minimiser" can be used to determine the chi2 of the data for a given model value.
23  */
24  template<class JModel_t>
26  public JMessage< JAbstractMinimiser<JModel_t> >
27  {
28  typedef double result_type;
29 
30  /**
31  * Default constructor.
32  */
34  {}
35 
36 
37  /**
38  * Get chi2.
39  *
40  * \param fit fit function
41  * \param __begin begin of data
42  * \param __end end of data
43  * \return chi2
44  */
45  template<class JFunction_t, class T>
46  result_type operator()(const JFunction_t& fit, T __begin, T __end)
47  {
48  double chi2 = 0.0;
49 
50  for (T i = __begin; i != __end; ++i) {
51  chi2 += fit(value, *i);
52  }
53 
54  return chi2;
55  }
56 
57  JModel_t value; //!< model value
58  };
59 
60 
61  /**
62  * Template definition of a data regressor of given model.
63  *
64  * The first template argument refers to the model that should be fitted to the data and
65  * the second to the type of minimiser.
66  */
67  template<class JModel_t, template<class> class JMinimiser_t = JAbstractMinimiser>
68  struct JRegressor;
69 
70 
71  /**
72  * Abstract class for global fit method.
73  */
74  template<class JModel_t, template<class> class JMinimiser_t = JAbstractMinimiser>
76  public JMinimiser_t<JModel_t>
77  {
78  typedef JMinimiser_t<JModel_t> minimiser_type;
81 
82 
83  /**
84  * Global fit.
85  *
86  * \param value start value
87  * \param __begin begin of data set
88  * \param __end end of data set
89  * \return chi2
90  */
91  template<class T>
92  result_type operator()(const JModel_t& value, T __begin, T __end)
93  {
94  static_cast<minimiser_type&>(*this).value = value;
95 
96  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin, __end);
97  }
98 
99 
100  /**
101  * Global fit.
102  *
103  * \param value start value
104  * \param __begin1 begin of first data set
105  * \param __end1 end of first data set
106  * \param __begin2 begin of second data set
107  * \param __end2 end of second data set
108  * \return chi2
109  */
110  template<class T1, class T2>
111  result_type operator()(const JModel_t& value,
112  T1 __begin1, T1 __end1,
113  T2 __begin2, T2 __end2)
114  {
115  static_cast<minimiser_type&>(*this).value = value;
116 
117  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin1, __end1, __begin2, __end2);
118  }
119  };
120 }
121 
122 #endif
JFIT::JAbstractMinimiser::operator()
result_type operator()(const JFunction_t &fit, T __begin, T __end)
Get chi2.
Definition: JRegressor.hh:46
JFIT::JAbstractRegressor::operator()
result_type operator()(const JModel_t &value, T __begin, T __end)
Global fit.
Definition: JRegressor.hh:92
JFIT::JAbstractRegressor::regressor_type
JRegressor< JModel_t, JMinimiser_t > regressor_type
Definition: JRegressor.hh:79
JFIT::JAbstractMinimiser::JAbstractMinimiser
JAbstractMinimiser()
Default constructor.
Definition: JRegressor.hh:33
JFIT::JAbstractRegressor
Abstract class for global fit method.
Definition: JRegressor.hh:75
JFIT
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
JMessage.hh
JFIT::JAbstractRegressor::operator()
result_type operator()(const JModel_t &value, T1 __begin1, T1 __end1, T2 __begin2, T2 __end2)
Global fit.
Definition: JRegressor.hh:111
JFIT::JAbstractRegressor::result_type
minimiser_type::result_type result_type
Definition: JRegressor.hh:80
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JFIT::JAbstractMinimiser::value
JModel_t value
model value
Definition: JRegressor.hh:57
JFIT::JAbstractRegressor::minimiser_type
JMinimiser_t< JModel_t > minimiser_type
Definition: JRegressor.hh:78
JFIT::JRegressor
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
JFIT::JAbstractMinimiser::result_type
double result_type
Definition: JRegressor.hh:28
JFIT::JSimplex< JPoint4D >::result_type
double result_type
Definition: JSimplex.hh:47
JEEP::JMessage
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:44
JFIT::JAbstractMinimiser
Abstract minimiser.
Definition: JRegressor.hh:25