Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JMEstimator.hh
Go to the documentation of this file.
1#ifndef __JFIT__JMESTIMATOR__
2#define __JFIT__JMESTIMATOR__
3
4#include <cmath>
5
6
7/**
8 * \file
9 * Maximum likelihood estimator (M-estimators).
10 * \author mdejong
11 */
12namespace JFIT {}
13namespace JPP { using namespace JFIT; }
14
15namespace JFIT {
16
17 /**
18 * Interface for maximum likelihood estimator (M-estimator).
19 */
20 struct JMEstimator {
21 /**
22 * Virtual destructor.
23 */
24 virtual ~JMEstimator()
25 {}
26
27
28 /**
29 * Get maximum likelihood estimate.
30 *
31 * \param z deviation
32 * \return likelihood
33 */
34 virtual double getRho(const double z) const = 0;
35
36
37 /**
38 * Get derivative of maximum likelihood estimate.
39 *
40 * \param z deviation
41 * \return derivative
42 */
43 virtual double getPsi(const double z) const = 0;
44 };
45
46
47 /**
48 * Normal M-estimator.
49 *
50 * This estimator is based on a Gaussian PDF and produces the standard chi2.
51 */
53 public JMEstimator
54 {
55 virtual double getRho(const double z) const { return 0.5*z*z; }
56 virtual double getPsi(const double z) const { return z; }
57 };
58
59
60 /**
61 * Lorentzian M-estimator.
62 *
63 * This estimator prouces a logarithmic dependence for large deviations.
64 */
66 public JMEstimator
67 {
68 virtual double getRho(const double z) const { return log (1.0 + 0.5*z*z); }
69 virtual double getPsi(const double z) const { return z / (1.0 + 0.5*z*z); }
70 };
71
72
73 /**
74 * Linear M-estimator.
75 *
76 * This estimator produces a linear dependence for large deviations.
77 */
79 public JMEstimator
80 {
81 virtual double getRho(const double z) const { return sqrt(1.0 + 0.5*z*z) - 1.0; }
82 virtual double getPsi(const double z) const { return 0.5 * z / sqrt(1.0 + 0.5*z*z); }
83 };
84
85
86 /**
87 * Null M-estimator.
88 *
89 * This is not an estimator at all, but an object that just returns whatever it is given.\n
90 * It is introduced so that the user can directly access the likelihood calculated by JRegressor<JEnergy>.
91 */
93 public JMEstimator
94 {
95 virtual double getRho(const double z) const { return z; }
96 virtual double getPsi(const double z) const { return 1.0; }
97 };
98
99
100 /**
101 * Tukey's biweight M-estimator.
102 *
103 * This estimator produces a redescending dependence for large deviations.
104 */
106 public JMEstimator
107 {
108 /**
109 * Constructor.
110 *
111 * \param k standard deviation
112 */
113 JMEstimatorTukey(const double k) :
114 k(k)
115 {}
116
117 virtual double getRho(const double z) const override
118 {
119 const double w = 0.5 * k*k / 3.0;
120
121 if (fabs(z) < k) {
122
123 const double u = z/k;
124 const double v = 1.0 - u*u;
125
126 return w * (1.0 - v*v*v);
127 }
128
129 return w;
130 }
131
132 virtual double getPsi(const double z) const override
133 {
134 if (fabs(z) < k) {
135
136 const double u = z/k;
137 const double v = 1.0 - u*u;
138
139 return z * v*v;
140 }
141
142 return 0.0;
143 }
144
145 double k;
146 };
147
148
149 /**
150 * Normal M-estimator with background.
151 */
153 public JMEstimator
154 {
155 /**
156 * Constructor.
157 *
158 * \param p background probability
159 */
161 p(p)
162 {}
163
164 virtual double getRho(const double z) const override
165 {
166 const double w = exp(-0.5*z*z);
167
168 return -log(w + p);
169 }
170
171 virtual double getPsi(const double z) const override
172 {
173 const double w = exp(-0.5*z*z);
174
175 return z * w / (w + p);
176 }
177
178 double p;
179 };
180
181
182 /**
183 * Definition of the various M-Estimators available to use.
184 */
186 EM_NORMAL = 0,
187 EM_LORENTZIAN = 1,
188 EM_LINEAR = 2,
189 EM_NULL = 3,
192 };
193
194
195 /**
196 * Get M-Estimator.
197 *
198 * Note that for M-estimators with an additional parameter, defaults are used.
199 *
200 * \param type type
201 * \return pointer to newly created M-Estimator (may be NULL)
202 */
203 inline JMEstimator* getMEstimator(const int type)
204 {
205 switch (type) {
206
207 case EM_NORMAL:
208 return new JMEstimatorNormal();
209
210 case EM_LORENTZIAN:
211 return new JMEstimatorLorentzian();
212
213 case EM_LINEAR:
214 return new JMEstimatorLinear();
215
216 case EM_NULL:
217 return new JMEstimatorNull();
218
219 case EM_TUKEY:
220 return new JMEstimatorTukey(5.0);
221
223 return new JMEstimatorNormalWithBackground(1.0e-5);
224
225 default:
226 return NULL;
227 }
228 }
229}
230
231#endif
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
JMEstimator_t
Definition of the various M-Estimators available to use.
@ EM_LORENTZIAN
@ EM_NORMALWITHBACKGROUND
@ EM_NORMAL
@ EM_LINEAR
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Linear M-estimator.
virtual double getRho(const double z) const
Get maximum likelihood estimate.
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Lorentzian M-estimator.
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Normal M-estimator with background.
virtual double getRho(const double z) const override
Get maximum likelihood estimate.
virtual double getPsi(const double z) const override
Get derivative of maximum likelihood estimate.
JMEstimatorNormalWithBackground(const double p)
Constructor.
Normal M-estimator.
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Null M-estimator.
virtual double getRho(const double z) const
Get maximum likelihood estimate.
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Tukey's biweight M-estimator.
virtual double getRho(const double z) const override
Get maximum likelihood estimate.
virtual double getPsi(const double z) const override
Get derivative of maximum likelihood estimate.
JMEstimatorTukey(const double k)
Constructor.
Interface for maximum likelihood estimator (M-estimator).
virtual double getRho(const double z) const =0
Get maximum likelihood estimate.
virtual double getPsi(const double z) const =0
Get derivative of maximum likelihood estimate.
virtual ~JMEstimator()
Virtual destructor.