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

#include <BootstrapCalculators.h>

Inheritance diagram for StochasticTools::Percentile< 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
 

Detailed Description

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

Definition at line 87 of file BootstrapCalculators.h.

Member Function Documentation

◆ compute()

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

Implements StochasticTools::BootstrapCalculator< InType, OutType >.

Definition at line 25 of file BootstrapCalculators.C.

26 {
27  // Bootstrap estimates
28  const std::vector<OutType> values = this->computeBootstrapEstimates(data, is_distributed);
29 
30  // Extract percentiles
31  std::vector<OutType> output;
32  if (this->processor_id() == 0)
33  for (const Real & level : this->_levels)
34  {
35  long unsigned int index = std::lrint(level * (this->_replicates - 1));
36  output.push_back(values[index]);
37  }
38 
39  return output;
40 }
processor_id_type processor_id() const
std::vector< OutType > computeBootstrapEstimates(const InType &, const bool)

◆ 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: