https://mooseframework.inl.gov
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
NormalSampler Class Reference

These tests are meant to use the bootstrap calculators and test against analytical confidence intervals. More...

Public Member Functions

 NormalSampler (Real mean, Real std, unsigned int seed)
 
Real sample () const
 
std::vector< Realsample (std::size_t n) const
 
Real meanConfidence (Real level, std::size_t n) const
 
Real stdConfidence (Real level, std::size_t n) const
 

Static Private Member Functions

static Real computeZ (Real level)
 

Private Attributes

const Real _mean
 
const Real _std
 
MooseRandom _generator
 

Detailed Description

These tests are meant to use the bootstrap calculators and test against analytical confidence intervals.

The tolerance for the tests is pretty loose (50%), but at least it shows that the bootstrapping is in the ballpark (as it is meant to).

The analytical confidence intervals are based on sampling a normal distribution, this distributiong has nice properties so the confidence interval for mean and standard deviation are analytical.

Definition at line 36 of file TestBootstrapCalculators.C.

Constructor & Destructor Documentation

◆ NormalSampler()

NormalSampler::NormalSampler ( Real  mean,
Real  std,
unsigned int  seed 
)
inline

Definition at line 39 of file TestBootstrapCalculators.C.

39  : _mean(mean), _std(std)
40  {
41  _generator.seed(seed);
42  }
void seed(std::size_t i, unsigned int seed)

Member Function Documentation

◆ computeZ()

static Real NormalSampler::computeZ ( Real  level)
inlinestaticprivate

Definition at line 70 of file TestBootstrapCalculators.C.

71  {
72  const Real alpha = level < 0.5 ? level : 1. - level;
73  const Real z = -Normal::quantile(alpha / 2., 0, 1);
74  return level < 0.5 ? -z : z;
75  }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string alpha
Definition: NS.h:134
virtual Real quantile(const Real &p) const override
Definition: Normal.C:80

◆ meanConfidence()

Real NormalSampler::meanConfidence ( Real  level,
std::size_t  n 
) const
inline

Definition at line 53 of file TestBootstrapCalculators.C.

Referenced by TEST().

54  {
55  const Real z = computeZ(level);
56  const Real mean_std = _std / std::sqrt(n);
57  return z * mean_std;
58  }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static Real computeZ(Real level)

◆ sample() [1/2]

Real NormalSampler::sample ( ) const
inline

Definition at line 44 of file TestBootstrapCalculators.C.

Referenced by TEST().

44 { return _generator.randNormal(_mean, _std); }
Real randNormal(std::size_t i, Real mean, Real sigma)

◆ sample() [2/2]

std::vector<Real> NormalSampler::sample ( std::size_t  n) const
inline

Definition at line 45 of file TestBootstrapCalculators.C.

46  {
47  std::vector<Real> data(n);
48  std::for_each(
49  data.begin(), data.end(), [&](Real & v) { v = _generator.randNormal(_mean, _std); });
50  return data;
51  }
Real randNormal(std::size_t i, Real mean, Real sigma)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84

◆ stdConfidence()

Real NormalSampler::stdConfidence ( Real  level,
std::size_t  n 
) const
inline

Definition at line 60 of file TestBootstrapCalculators.C.

Referenced by TEST().

61  {
62  const Real z = computeZ(level);
63  const Real nr = n;
64  const Real gg = std::exp(std::lgamma(nr / 2.) - std::lgamma((nr - 1.) / 2.));
65  const Real std_std = _std * std::sqrt(1.0 - 2. / (nr - 1.) * gg * gg);
66  return z * std_std;
67  }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static Real computeZ(Real level)

Member Data Documentation

◆ _generator

MooseRandom NormalSampler::_generator
private

Definition at line 79 of file TestBootstrapCalculators.C.

◆ _mean

const Real NormalSampler::_mean
private

Definition at line 77 of file TestBootstrapCalculators.C.

◆ _std

const Real NormalSampler::_std
private

Definition at line 78 of file TestBootstrapCalculators.C.


The documentation for this class was generated from the following file: