Jpp  17.0.0
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  * 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 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  * Definition of the various M-Estimators available to use.
151  */
157  };
158 
159 
160  /**
161  * Get M-Estimator.
162  *
163  * \param type type
164  * \return pointer to newly created M-Estimator (maybe NULL)
165  */
166  inline JMEstimator* getMEstimator(const int type)
167  {
168  switch (type) {
169 
170  case EM_NORMAL:
171  return new JMEstimatorNormal();
172 
173  case EM_LORENTZIAN:
174  return new JMEstimatorLorentzian();
175 
176  case EM_LINEAR:
177  return new JMEstimatorLinear();
178 
179  case EM_NULL:
180  return new JMEstimatorNull();
181 
182  default:
183  return NULL;
184  }
185  }
186 }
187 
188 #endif
then cat $TRIPOD_INITIAL<< EOF1 256877.5 4743716.7-2438.42 256815.5 4743395.0-2435.53 257096.2 4743636.0-2439.5EOFfiJEditDetector-a $DETECTOR_INITIAL-s"-1 addz -6.9"-o $DETECTOReval`JPrintDetector-a $DETECTOR-O SUMMARY`for STRING in ${STRINGS[*]};do set_variable MODULE`getModule-a $DETECTOR-L"$STRING 0"`JEditDetector-a $DETECTOR-M"$MODULE setz -2.9"-o $DETECTORdonecp-p $TRIPOD_INITIAL $TRIPODJAcoustics.sh $DETECTOR_IDcat > acoustics_trigger_parameters txt<< EOFQ=0.0;TMax_s=0.020;numberOfHits=90;EOFJAcousticsEventBuilder.sh $DETECTOR $RUNS[*]INPUT_FILES=(`ls KM3NeT_ ${(l:8::0::0:) DETECTOR_ID}_0 *${^RUNS}_event.root`) cd $WORKDIRif[!$HOMEDIR-ef $WORKDIR];then cp-p $HOMEDIR/$DETECTOR $WORKDIR cp-p $HOMEDIR/$TRIPOD $WORKDIR cp-p $HOMEDIR/${^INPUT_FILES}$WORKDIR cp-p $HOMEDIR/{acoustics_fit_parameters, acoustics_trigger_parameters, disable, hydrophone, mechanics, sound_velocity, tripod, waveform}.txt $WORKDIRfisource $JPP_DIR/examples/JAcoustics/acoustics-fit-toolkit.shtimer_startinitialise stage_1B > &stage log
data_type w[N+1][M+1]
Definition: JPolint.hh:757
Null M-estimator.
Definition: JMEstimator.hh:53
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:83
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:96
virtual double getRho(const double z) const =0
Get maximum likelihood estimate.
Linear M-estimator.
Definition: JMEstimator.hh:92
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:69
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:82
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:70
virtual double getPsi(const double z) const
Get derivative of maximum likelihood estimate.
Definition: JMEstimator.hh:57
Normal M-estimator.
Definition: JMEstimator.hh:66
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:56
virtual ~JMEstimator()
Virtual destructor.
Definition: JMEstimator.hh:24
virtual double getRho(const double z) const
Get maximum likelihood estimate.
Definition: JMEstimator.hh:95
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
Definition: JMEstimator.hh:166
data_type v[N+1][M+1]
Definition: JPolint.hh:756
double u[N+1]
Definition: JPolint.hh:755
Tukey&#39;s biweight M-estimator.
Definition: JMEstimator.hh:105
Lorentzian M-estimator.
Definition: JMEstimator.hh:79
JMEstimator_t
Definition of the various M-Estimators available to use.
Definition: JMEstimator.hh:152
virtual double getRho(const double z) const override
Get maximum likelihood estimate.
Definition: JMEstimator.hh:117