https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | 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)
 

Private Attributes

const std::string _name
 

Detailed Description

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

Definition at line 99 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}
unsigned int count
StochasticTools::Calculator< InType, OutType > & _calc
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
T pow(T x, int e)
uint8_t processor_id_type

◆ 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}
const std::vector< double > x
const double v
std::array< Real, 2 > values
virtual Real quantile(const Real &y) const=0
virtual Real cdf(const Real &x) const=0
OutType acceleration(const InType &, const bool)
std::vector< OutType > computeBootstrapEstimates(const InType &, const bool)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ 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 158 of file BootstrapCalculators.h.

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

◆ name()

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

Definition at line 62 of file BootstrapCalculators.h.

62{ return _name; }

Member Data Documentation

◆ _calc

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

Definition at line 78 of file BootstrapCalculators.h.

◆ _levels

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

Definition at line 69 of file BootstrapCalculators.h.

◆ _name

template<typename InType , typename OutType >
const std::string StochasticTools::BootstrapCalculator< InType, OutType >::_name
privateinherited

◆ _replicates

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

Definition at line 72 of file BootstrapCalculators.h.

◆ _seed

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

Definition at line 75 of file BootstrapCalculators.h.


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