StatErrEst.h

Go to the documentation of this file.
00001 #ifndef CMTERREST_H_
00002 #define CMTERREST_H_
00003 #include <boost/function.hpp>
00004 #include <vector>
00005 
00006 namespace gplib
00007   {
00008 
00009     /** \addtogroup statistics Statistical methods */
00010     /* @{ */
00011 
00012     //! This class is used as a base for stochastic error estimation
00013     /*!  This base class is used for stochastic error estimation with Bootstrap, Jacknife or
00014      * similar methods. It takes a template parameter, the type of the function object
00015      * that generates individual samples for the analysis. The only requirement is, that
00016      * operator() returns a value that is convertible to a double.
00017      */
00018     template<class SampleGenerator>
00019     class StatErrEst
00020       {
00021     private:
00022       //! We store the sample generator in a private variable
00023       SampleGenerator Generator;
00024       //! Make the desired number of samples using the Generator function object
00025       void MakeSamples()
00026         {
00027           Samples.reserve(nrealizations);
00028           std::generate_n(back_inserter(Samples), nrealizations, Generator);
00029         }
00030       //! This is the only virtual function, it is overwritten by the derived class to implement the error calculation method
00031       virtual void CalcErrors_Imp(double &m, double &v) = 0;
00032     protected:
00033       //! How many samples are requested
00034       int nrealizations;
00035       //! the vector that holds the generated samples
00036       std::vector<double> Samples;
00037     public:
00038       //! public access function to generated samples
00039       std::vector<double> &GetSamples()
00040         {
00041           return Samples;
00042         }
00043       //! The main function, calculates the error, by generating samples and calling the derived function
00044       void CalcErrors(double &m, double &v)
00045         {
00046           MakeSamples();
00047           CalcErrors_Imp(m, v);
00048         }
00049       //! The constructor takes two parameters, the desired number of samples and the function object to generate them
00050       StatErrEst(const int nsamples, SampleGenerator TheGenerator) :
00051         Generator(TheGenerator), nrealizations(nsamples)
00052         {
00053         }
00054       ;
00055       virtual ~StatErrEst()
00056         {
00057         }
00058       ;
00059       };
00060   /* @} */
00061   }
00062 #endif /*CMTERREST_H_*/

Generated on Tue May 4 16:52:15 2010 for GPLIB++ by  doxygen 1.5.8