Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
12 namespace JFIT {}
13 namespace JPP { using namespace JFIT; }
14 
15 namespace 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  */
92  struct JMEstimatorNull :
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  */
189  EM_NULL = 3,
190  EM_TUKEY = 4,
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
data_type w[N+1][M+1]
Definition: JPolint.hh:778
Null M-estimator.
Definition: JMEstimator.hh:92
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:69
virtual double getPsi(const double z) const override
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:171
Interface for maximum likelihood estimator (M-estimator).
Definition: JMEstimator.hh:20
virtual double getPsi(const double z) const =0
Get derivative of maximum likelihood estimate.
JMEstimatorTukey(const double k)
Constructor.
Definition: JMEstimator.hh:113
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:82
virtual double getRho(const double z) const =0
Get maximum likelihood estimate.
Linear M-estimator.
Definition: JMEstimator.hh:78
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:55
virtual double getPsi(const double z) const override
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:132
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:68
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:56
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:96
Normal M-estimator.
Definition: JMEstimator.hh:52
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:95
virtual double getRho(const double z) const override
Get maximum likelihood estimate.
Definition: JMEstimator.hh:164
virtual ~JMEstimator()
Virtual destructor.
Definition: JMEstimator.hh:24
then set_variable DIR else fatal Wrong number of arguments fi for INPUT_FILE in ls rt $DIR stage * log
JMEstimatorNormalWithBackground(const double p)
Constructor.
Definition: JMEstimator.hh:160
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:81
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
Definition: JMEstimator.hh:203
data_type v[N+1][M+1]
Definition: JPolint.hh:777
double u[N+1]
Definition: JPolint.hh:776
Tukey&#39;s biweight M-estimator.
Definition: JMEstimator.hh:105
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable STRING $argv[2] set_array QUANTILES set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable MODULE `getModule -a $DETECTOR -L "$STRING 0"` source JAcousticsToolkit.sh typeset -A TRIPODS get_tripods $WORKDIR/tripod.txt TRIPODS XMEAN
Normal M-estimator with background.
Definition: JMEstimator.hh:152
Lorentzian M-estimator.
Definition: JMEstimator.hh:65
JMEstimator_t
Definition of the various M-Estimators available to use.
Definition: JMEstimator.hh:185
virtual double getRho(const double z) const override
Get maximum likelihood estimate.
Definition: JMEstimator.hh:117