CMP++: Uncertainty Quantification & Bayesian Calibration
Loading...
Searching...
No Matches
cmp::statistics::Bootstrap Class Reference

Bootstrap resampling index generator. More...

#include <statistics.h>

Public Member Functions

 Bootstrap (size_t n_obs, size_t n_obs_resample, bool with_replacement=true, unsigned int random_state=42)
 Constructor for the Bootstrap resampler.
 
Eigen::VectorXs operator() ()
 Executes the bootstrap sampling process.
 

Private Attributes

size_t nObs_
 Original number of observations \( N \).
 
size_t nObsResample_
 Target number of observations to resample \( M \).
 
unsigned int rngState_
 Seed for the random number generator.
 
std::default_random_engine rng_
 Random number engine.
 
std::uniform_int_distribution< size_t > dist_
 Uniform integer distribution for sampling with replacement.
 
Eigen::VectorXs indices_
 Internal array storing the base indices for sampling.
 
bool withReplacement_
 Flag indicating whether to sample with replacement.
 

Detailed Description

Bootstrap resampling index generator.

Mathematical Formulation

Draws a random sample \(\mathcal{D}^*\) of size \(M\) from a dataset \(\mathcal{D}\) of size \(N\).

  • If with replacement:

    \[ P(x_i^* = x_j) = \frac{1}{N} \quad \forall i \in \{1,\dots,M\}, \ j \in \{1,\dots,N\} \]

  • If without replacement:

    \[ P(x_i^* = x_j) = \frac{1}{N - i + 1} \]

    subject to all selections being distinct.
  • ### Implementation Algorithm
  1. If withReplacement_ is true, generates \(M\) random integers uniformly distributed in the range \([0, N-1]\).
  2. If false, shuffles the index array using std::shuffle and extracts the first \(M\) elements.

Constructor & Destructor Documentation

◆ Bootstrap()

cmp::statistics::Bootstrap::Bootstrap ( size_t  n_obs,
size_t  n_obs_resample,
bool  with_replacement = true,
unsigned int  random_state = 42 
)
inline

Constructor for the Bootstrap resampler.

Parameters
n_obsTotal number of original observations \( N \).
n_obs_resampleNumber of samples to draw \( M \).
with_replacementBoolean flag indicating whether duplicates are allowed.
random_stateSeed for the random number generator.
Exceptions
std::invalid_argumentif invalid sizes are provided.

Member Function Documentation

◆ operator()()

Eigen::VectorXs cmp::statistics::Bootstrap::operator() ( )
inline

Executes the bootstrap sampling process.

Returns
A vector containing the \( M \) randomly sampled indices.

Member Data Documentation

◆ dist_

std::uniform_int_distribution<size_t> cmp::statistics::Bootstrap::dist_
private

Uniform integer distribution for sampling with replacement.

◆ indices_

Eigen::VectorXs cmp::statistics::Bootstrap::indices_
private

Internal array storing the base indices for sampling.

◆ nObs_

size_t cmp::statistics::Bootstrap::nObs_
private

Original number of observations \( N \).

◆ nObsResample_

size_t cmp::statistics::Bootstrap::nObsResample_
private

Target number of observations to resample \( M \).

◆ rng_

std::default_random_engine cmp::statistics::Bootstrap::rng_
private

Random number engine.

◆ rngState_

unsigned int cmp::statistics::Bootstrap::rngState_
private

Seed for the random number generator.

◆ withReplacement_

bool cmp::statistics::Bootstrap::withReplacement_
private

Flag indicating whether to sample with replacement.


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