https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
StochasticTools::BiasCorrectedAccelerated< InType, OutType > Class Template Reference

#include <BootstrapCalculators.h>

Inheritance diagram for StochasticTools::BiasCorrectedAccelerated< InType, OutType >:
[legend]

Public Member Functions

virtual std::vector< OutType > compute (const InType &, const bool) override
 
const std::string & name () const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Member Functions

std::vector< OutType > computeBootstrapEstimates (const InType &, const bool)
 

Protected Attributes

const std::vector< Real_levels
 
const unsigned int _replicates
 
const unsigned int _seed
 
StochasticTools::Calculator< InType, OutType > & _calc
 
const Parallel::Communicator & _communicator
 

Private Member Functions

OutType acceleration (const InType &, const bool)
 

Detailed Description

template<typename InType, typename OutType>
class StochasticTools::BiasCorrectedAccelerated< InType, OutType >

Definition at line 98 of file BootstrapCalculators.h.

Member Function Documentation

◆ acceleration()

template<typename InType , typename OutType >
OutType StochasticTools::BiasCorrectedAccelerated< InType, OutType >::acceleration ( const InType &  data,
const bool  is_distributed 
)
private

Definition at line 77 of file BootstrapCalculators.C.

79 {
80  const std::size_t local_size = data.size();
81  std::vector<std::size_t> local_sizes = {local_size};
82  if (is_distributed)
83  this->_communicator.allgather(local_sizes);
84  const std::size_t count = std::accumulate(local_sizes.begin(), local_sizes.end(), 0);
85  const processor_id_type rank = is_distributed ? this->processor_id() : 0;
86 
87  // Jackknife statistics
88  std::vector<OutType> theta_i(local_size);
89 
90  // Compute jackknife estimates, Ch. 11, Eq. 11.2, p. 141
91  for (processor_id_type r = 0; r < local_sizes.size(); ++r)
92  for (std::size_t i = 0; i < local_sizes[r]; ++i)
93  {
94  this->_calc.initializeCalculator();
95  for (std::size_t il = 0; il < local_size; ++il)
96  if (i != il || r != rank)
97  this->_calc.updateCalculator(data[il]);
98  this->_calc.finalizeCalculator(is_distributed);
99  if (r == rank)
100  theta_i[i] = this->_calc.getValue();
101  }
102 
103  // Compute jackknife sum, Ch. 11, Eq. 11.4, p. 141
104  OutType theta_dot = std::accumulate(theta_i.begin(), theta_i.end(), OutType());
105  if (is_distributed)
106  this->_communicator.sum(theta_dot);
107  theta_dot /= count;
108 
109  // Acceleration, Ch. 14, Eq. 14.15, p. 185
110  std::vector<OutType> num_den(2);
111  for (const auto & jk : theta_i)
112  {
113  num_den[0] += MathUtils::pow(theta_dot - jk, 3);
114  num_den[1] += MathUtils::pow(theta_dot - jk, 2);
115  }
116  if (is_distributed)
117  this->_communicator.sum(num_den);
118 
119  mooseAssert(num_den[1] != OutType(), "The acceleration denomenator must not be zero.");
120  return num_den[0] / (6 * std::pow(num_den[1], 3. / 2.));
121 }
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
const Parallel::Communicator & _communicator
uint8_t processor_id_type
T pow(T x, int e)
processor_id_type processor_id() const
StochasticTools::Calculator< InType, OutType > & _calc
MooseUnits pow(const MooseUnits &, int)

◆ compute()

template<typename InType , typename OutType >
std::vector< OutType > StochasticTools::BiasCorrectedAccelerated< InType, OutType >::compute ( const InType &  data,
const bool  is_distributed 
)
overridevirtual

Implements StochasticTools::BootstrapCalculator< InType, OutType >.

Definition at line 45 of file BootstrapCalculators.C.

46 {
47  // Bootstrap estimates
48  const std::vector<OutType> values = this->computeBootstrapEstimates(data, is_distributed);
49 
50  // Compute bias-correction, Efron and Tibshirani (2003), Eq. 14.14, p. 186
51  const OutType value = this->_calc.compute(data, is_distributed);
52  const Real count = std::count_if(
53  values.begin(),
54  values.end(),
55  [&value](Real v) { return v < value; }); // use Real for non-integer division below
56  const Real bias = NormalDistribution::quantile(count / this->_replicates, 0, 1);
57 
58  // Compute Acceleration, Efron and Tibshirani (2003), Eq. 14.15, p. 186
59  const OutType acc = data.empty() ? OutType() : acceleration(data, is_distributed);
60 
61  // Compute intervals, Efron and Tibshirani (2003), Eq. 14.10, p. 185
62  std::vector<OutType> output;
63  for (const Real & level : this->_levels)
64  {
65  const Real z = NormalDistribution::quantile(level, 0, 1);
66  const Real x = bias + (bias + (bias + z) / (1 - acc * (bias + z)));
67  const Real alpha = NormalDistribution::cdf(x, 0, 1);
68 
69  long unsigned int index = std::lrint(alpha * (this->_replicates - 1));
70  output.push_back(values[index]);
71  }
72  return output;
73 }
virtual Real cdf(const Real &x) const override
Definition: Normal.C:74
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< double > x
OutType acceleration(const InType &, const bool)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
static const std::string alpha
Definition: NS.h:134
std::vector< OutType > computeBootstrapEstimates(const InType &, const bool)
StochasticTools::Calculator< InType, OutType > & _calc
virtual Real quantile(const Real &p) const override
Definition: Normal.C:80

◆ computeBootstrapEstimates()

template<typename InType, typename OutType >
std::vector< OutType > StochasticTools::BootstrapCalculator< InType, OutType >::computeBootstrapEstimates ( const InType &  data,
const bool  is_distributed 
)
protectedinherited

Definition at line 157 of file BootstrapCalculators.h.

159 {
160  MooseRandom generator;
161  generator.seed(0, _seed);
162 
163  // Compute replicate statistics
164  std::vector<OutType> values(_replicates);
165  auto calc_update = [this](const typename InType::value_type & val)
166  { _calc.updateCalculator(val); };
167  for (std::size_t i = 0; i < _replicates; ++i)
168  {
169  _calc.initializeCalculator();
171  data, calc_update, generator, 0, is_distributed ? &this->_communicator : nullptr);
172  _calc.finalizeCalculator(is_distributed);
173  values[i] = _calc.getValue();
174  }
175  inplaceSort(values);
176  return values;
177 }
void seed(std::size_t i, unsigned int seed)
const Parallel::Communicator & _communicator
void resampleWithFunctor(const std::vector< T > &data, const ActionFunctor &functor, MooseRandom &generator, const std::size_t seed_index=0)
void inplaceSort(std::vector< T > &values)
StochasticTools::Calculator< InType, OutType > & _calc

◆ name()

template<typename InType, typename OutType>
const std::string& StochasticTools::BootstrapCalculator< InType, OutType >::name ( ) const
inlineinherited

Definition at line 61 of file BootstrapCalculators.h.

61 { return _name; }

Member Data Documentation

◆ _calc

template<typename InType, typename OutType>
StochasticTools::Calculator<InType, OutType>& StochasticTools::BootstrapCalculator< InType, OutType >::_calc
protectedinherited

Definition at line 77 of file BootstrapCalculators.h.

◆ _levels

template<typename InType, typename OutType>
const std::vector<Real> StochasticTools::BootstrapCalculator< InType, OutType >::_levels
protectedinherited

Definition at line 68 of file BootstrapCalculators.h.

◆ _replicates

template<typename InType, typename OutType>
const unsigned int StochasticTools::BootstrapCalculator< InType, OutType >::_replicates
protectedinherited

Definition at line 71 of file BootstrapCalculators.h.

◆ _seed

template<typename InType, typename OutType>
const unsigned int StochasticTools::BootstrapCalculator< InType, OutType >::_seed
protectedinherited

Definition at line 74 of file BootstrapCalculators.h.


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