3 #include <boost/random/lagged_fibonacci.hpp>
4 #include <boost/random/variate_generator.hpp>
5 #include <boost/random/uniform_int.hpp>
22 template<
class SampleGenerator>
27 virtual void CalcErrors_Imp(
double &TheMean,
double &TheVar);
30 Bootstrap(
const int nrea, SampleGenerator TheGenerator) :
40 template<
class SampleGenerator>
41 void Bootstrap<SampleGenerator>::CalcErrors_Imp(
double &TheMean,
45 if (this->nrealizations < 2)
47 TheMean =
Mean(this->Samples.begin(), this->Samples.end());
51 std::vector<double> Pseudo;
52 Pseudo.reserve(this->nrealizations);
53 std::vector<double> BootSample(this->nrealizations);
54 boost::lagged_fibonacci607 generator(
55 static_cast<unsigned int> (std::time(0)));
56 boost::uniform_int<> int_dist(0, this->nrealizations - 1);
57 boost::variate_generator<boost::lagged_fibonacci607&,
58 boost::uniform_int<> > randomindex(generator, int_dist);
59 for (
int i = 0; i < this->nrealizations; ++i)
61 for (
int j = 0; j < this->nrealizations; j++)
63 BootSample.at(j) = this->Samples.at(randomindex());
65 Pseudo.push_back(
Variance(BootSample.begin(), BootSample.end()));
67 TheMean =
Mean(Pseudo.begin(), Pseudo.end());
68 TheVar =
Variance(Pseudo.begin(), Pseudo.end(), TheMean);
This class is used as a base for stochastic error estimation.
Implementation of the Bootstrap error estimation method.
std::iterator_traits< InputIterator >::value_type Mean(InputIterator begin, InputIterator end)
Calculate the mean for a given range.
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.
Bootstrap(const int nrea, SampleGenerator TheGenerator)
The constructor passes everything to the base.