GPLIB++
StatErrEst.h
Go to the documentation of this file.
1 #ifndef CMTERREST_H_
2 #define CMTERREST_H_
3 #include <boost/function.hpp>
4 #include <vector>
5 
6 namespace gplib
7  {
8 
9  /** \addtogroup statistics Statistical methods */
10  /* @{ */
11 
12  //! This class is used as a base for stochastic error estimation
13  /*! This base class is used for stochastic error estimation with Bootstrap, Jacknife or
14  * similar methods. It takes a template parameter, the type of the function object
15  * that generates individual samples for the analysis. The only requirement is, that
16  * operator() returns a value that is convertible to a double.
17  */
18  template<class SampleGenerator>
19  class StatErrEst
20  {
21  private:
22  //! We store the sample generator in a private variable
23  SampleGenerator Generator;
24  //! Make the desired number of samples using the Generator function object
25  void MakeSamples()
26  {
27  Samples.reserve(nrealizations);
28  std::generate_n(back_inserter(Samples), nrealizations, Generator);
29  }
30  //! This is the only virtual function, it is overwritten by the derived class to implement the error calculation method
31  virtual void CalcErrors_Imp(double &m, double &v) = 0;
32  protected:
33  //! How many samples are requested
35  //! the vector that holds the generated samples
36  std::vector<double> Samples;
37  public:
38  //! public access function to generated samples
39  std::vector<double> &GetSamples()
40  {
41  return Samples;
42  }
43  //! The main function, calculates the error, by generating samples and calling the derived function
44  void CalcErrors(double &m, double &v)
45  {
46  MakeSamples();
47  CalcErrors_Imp(m, v);
48  }
49  //! The constructor takes two parameters, the desired number of samples and the function object to generate them
50  StatErrEst(const int nsamples, SampleGenerator TheGenerator) :
51  Generator(TheGenerator), nrealizations(nsamples)
52  {
53  }
54  ;
55  virtual ~StatErrEst()
56  {
57  }
58  ;
59  };
60  /* @} */
61  }
62 #endif /*CMTERREST_H_*/
This class is used as a base for stochastic error estimation.
Definition: StatErrEst.h:19
std::vector< double > & GetSamples()
public access function to generated samples
Definition: StatErrEst.h:39
void CalcErrors(double &m, double &v)
The main function, calculates the error, by generating samples and calling the derived function...
Definition: StatErrEst.h:44
StatErrEst(const int nsamples, SampleGenerator TheGenerator)
The constructor takes two parameters, the desired number of samples and the function object to genera...
Definition: StatErrEst.h:50
virtual ~StatErrEst()
Definition: StatErrEst.h:55
std::vector< double > Samples
the vector that holds the generated samples
Definition: StatErrEst.h:36
int nrealizations
How many samples are requested.
Definition: StatErrEst.h:34