Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JLegendreEstimator.hh
Go to the documentation of this file.
1#ifndef __JFIT__JLEGENDREESTIMATOR__
2#define __JFIT__JLEGENDREESTIMATOR__
3
4#include "JMath/JLegendre.hh"
5#include "JMath/JZero.hh"
6#include "JMath/JMatrixNS.hh"
7#include "JFit/JEstimator.hh"
8
9
10/**
11 * \file
12 * Linear fit of JMATH::JLegendre.
13 * \author mdejong
14 */
15namespace JFIT {}
16namespace JPP { using namespace JFIT; }
17
18namespace JFIT {
19
20 using JMATH::JLegendre;
21
22 /**
23 * Linear fit of Legendre polynomial.
24 */
25 template<class JOrdinate_t, size_t N>
26 class JEstimator< JLegendre<JOrdinate_t, N> > :
27 public JLegendre<JOrdinate_t, N>
28 {
29 public:
30 typedef JOrdinate_t ordinate_type;
31
32
33 /**
34 * Constructor.
35 *
36 * The template argument <tt>T</tt> refers to an iterator of a data structure which should have the following member methods:
37 * - double %getX(); //
38 * - ordinate_type %getY(); //
39 * where <tt>ordinate_type</tt> refers to the first template atgument of class JLegendre.
40 *
41 * \param __begin begin of data
42 * \param __end end of data
43 */
44 template<class T>
45 JEstimator(T __begin, T __end)
46 {
47 using namespace std;
48 using namespace JPP;
49
50 if (distance(__begin, __end) >= NUMBER_OF_PARAMETERS) {
51
52 vector<ordinate_type> Y(NUMBER_OF_PARAMETERS, getZero<ordinate_type>());
53 vector<double> h(NUMBER_OF_PARAMETERS, getZero<double>());
54
55 V.resize(NUMBER_OF_PARAMETERS);
56 V.reset();
57
58 T i = __begin;
59
60 this->xmin = i->getX(); advance(i, distance(__begin, __end) - 1);
61 this->xmax = i->getX();
62
63 for (i = __begin; i != __end; ++i) {
64
65 const double z = this->getX(i->getX());
66
67 for (size_t n = 0; n <= N; ++n) {
68 h[n] = legendre(n, z);
69 }
70
71 for (size_t row = 0; row <= N; ++row) {
72
73 V(row, row) += h[row] * h[row];
74 Y[row] += h[row] * i->getY();
75
76 for (size_t col = 0; col != row; ++col) {
77 V(row, col) += h[row] * h[col];
78 }
79 }
80 }
81
82 for (size_t row = 0; row <= N; ++row) {
83 for (size_t col = 0; col != row; ++col) {
84 V(col, row) = V(row, col);
85 }
86 }
87
88 V.invert();
89
90 for (size_t row = 0; row <= N; ++row) {
91
92 (*this)[row] = zero;
93
94 for (size_t col = 0; col <= N; ++col) {
95 (*this)[row] += V(row, col) * Y[col];
96 }
97 }
98
99 } else {
100 throw JValueOutOfRange("JEstimator<JLegendre>::JEstimator(): Not enough data points.");
101 }
102 }
103
104
105 static const int NUMBER_OF_PARAMETERS = N + 1; //!< number of parameters of fit
106 JMATH::JMatrixNS V; //!< co-variance matrix of fit parameters
107 };
108}
109
110#endif
Linear fit methods.
Definition of zero value for any class.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JMATH::JMatrixNS V
co-variance matrix of fit parameters
Template definition of linear fit.
Definition JEstimator.hh:25
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for linear and iterative data regression.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template definition for function evaluation of Legendre polynome.
Definition JLegendre.hh:269
N x N symmetric matrix.
Definition JMatrixNS.hh:30