Jpp
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  * Null M-estimator.
49  *
50  * This is not an estimator at all, but an object that just returns whatever it is given.
51  * It was introduced so that the user can directly access the likelihood calculated by JRegressor<JEnergy>.
52  */
53  struct JMEstimatorNull :
54  public JMEstimator
55  {
56  virtual double getRho(const double z) const { return z; }
57  virtual double getPsi(const double z) const { return 1.0; }
58  };
59 
60 
61  /**
62  * Normal M-estimator.
63  *
64  * This estimator is based on a Gaussian PDF and produces the standard chi2.
65  */
67  public JMEstimator
68  {
69  virtual double getRho(const double z) const { return 0.5*z*z; }
70  virtual double getPsi(const double z) const { return z; }
71  };
72 
73 
74  /**
75  * Lorentzian M-estimator.
76  *
77  * This estimator prouces a logarithmic dependence for large deviations.
78  */
80  public JMEstimator
81  {
82  virtual double getRho(const double z) const { return log (1.0 + 0.5*z*z); }
83  virtual double getPsi(const double z) const { return z / (1.0 + 0.5*z*z); }
84  };
85 
86 
87  /**
88  * Linear M-estimator.
89  *
90  * This estimator produces a linear dependence for large deviations.
91  */
93  public JMEstimator
94  {
95  virtual double getRho(const double z) const { return sqrt(1.0 + 0.5*z*z) - 1.0; }
96  virtual double getPsi(const double z) const { return 0.5 * z / sqrt(1.0 + 0.5*z*z); }
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
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
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 #endif
JFIT::JMEstimatorLorentzian
Lorentzian M-estimator.
Definition: JMEstimator.hh:79
JFIT::JMEstimatorLinear::getPsi
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:96
JFIT::JMEstimatorTukey::JMEstimatorTukey
JMEstimatorTukey(const double __k)
Constructor.
Definition: JMEstimator.hh:113
JFIT::JMEstimatorLinear::getRho
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:95
JTOOLS::w
data_type w[N+1][M+1]
Definition: JPolint.hh:708
JFIT
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
JFIT::JMEstimatorNull::getPsi
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:57
JFIT::JMEstimator::getRho
virtual double getRho(const double z) const =0
Get maximum likelihood estimate.
JTOOLS::u
double u[N+1]
Definition: JPolint.hh:706
JFIT::JMEstimatorNormal::getPsi
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:70
JFIT::JMEstimatorLinear
Linear M-estimator.
Definition: JMEstimator.hh:92
JFIT::JMEstimatorNull::getRho
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:56
JFIT::JMEstimator::getPsi
virtual double getPsi(const double z) const =0
Get derivative of maximum likelihood estimate.
JFIT::JMEstimatorLorentzian::getRho
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:82
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JFIT::JMEstimatorNull
Null M-estimator.
Definition: JMEstimator.hh:53
JFIT::JMEstimator::~JMEstimator
virtual ~JMEstimator()
Virtual destructor.
Definition: JMEstimator.hh:24
JFIT::JMEstimatorTukey::getRho
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:117
JFIT::JMEstimatorTukey::getPsi
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:132
JFIT::JMEstimatorTukey::k
double k
Definition: JMEstimator.hh:145
JFIT::JMEstimatorNormal
Normal M-estimator.
Definition: JMEstimator.hh:66
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
JFIT::JMEstimatorLorentzian::getPsi
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:83
JFIT::JMEstimatorTukey
Tukey's biweight M-estimator.
Definition: JMEstimator.hh:105
JFIT::JMEstimatorNormal::getRho
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:69
JFIT::JMEstimator
Interface for maximum likelihood estimator (M-estimator).
Definition: JMEstimator.hh:20