GPLIB++
Jacknife.h
Go to the documentation of this file.
1 #ifndef CJACKNIFE_H_
2 #define CJACKNIFE_H_
3 #include <numeric>
4 #include "StatErrEst.h"
5 #include "statutils.h"
6 
7 namespace gplib
8  {
9 
10  /** \addtogroup statistics Statistical methods */
11  /* @{ */
12 
13  //! Implements the Jacknifing method of error estimation
14  /*! This class implements the Jacknifing mehtod for error estimation,
15  * at this point the implementation is purely geared towards simple mean
16  * and variance calculation and not easily extensible, should be changed in
17  * the future
18  */
19  template<class SampleGenerator>
20  class Jacknife: public StatErrEst<SampleGenerator>
21  {
22  private:
23  //! The implementation of the Jacknife
24  virtual void CalcErrors_Imp(double &m, double &v);
25  public:
26  //! The constructor just passes all its arguments to the base class
27  Jacknife(const int nrea, SampleGenerator TheGenerator) :
28  StatErrEst<SampleGenerator>(nrea, TheGenerator)
29  {
30  }
31  virtual ~Jacknife()
32  {
33  }
34  };
35  /* @} */
36 
37  //! The implementation of the Jacknife, has to be in the header file, as it is a template class
38  template<class SampleGenerator>
39  void Jacknife<SampleGenerator>::CalcErrors_Imp(double &m, double &v)
40  {
41  m = Mean(this->Samples.begin(), this->Samples.end()); //Calculate the mean
42  if (this->nrealizations < 2) // check for values, that can cause overflow of variance calculation
43  {
44  v = 0;
45  return;
46  }
47  v = Variance(this->Samples.begin(), this->Samples.end(), m); //calculate the variance with the given mean
48  }
49  }
50 #endif /*CJACKNIFE_H_*/
This class is used as a base for stochastic error estimation.
Definition: StatErrEst.h:19
std::iterator_traits< InputIterator >::value_type Mean(InputIterator begin, InputIterator end)
Calculate the mean for a given range.
Definition: statutils.h:21
virtual ~Jacknife()
Definition: Jacknife.h:31
Implements the Jacknifing method of error estimation.
Definition: Jacknife.h:20
Jacknife(const int nrea, SampleGenerator TheGenerator)
The constructor just passes all its arguments to the base class.
Definition: Jacknife.h:27
std::iterator_traits< InputIterator >::value_type Variance(InputIterator begin, InputIterator end, typename std::iterator_traits< InputIterator >::value_type mv)
Calculate the Variance and give the mean as a third input parameter.
Definition: statutils.h:30