Bootstrap resampling index generator.
More...
#include <statistics.h>
|
| | 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.
|
| |
|
| 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.
|
| |
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
- If
withReplacement_ is true, generates \(M\) random integers uniformly distributed in the range \([0, N-1]\).
- If false, shuffles the index array using
std::shuffle and extracts the first \(M\) elements.
◆ 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_obs | Total number of original observations \( N \). |
| n_obs_resample | Number of samples to draw \( M \). |
| with_replacement | Boolean flag indicating whether duplicates are allowed. |
| random_state | Seed for the random number generator. |
- Exceptions
-
| std::invalid_argument | if invalid sizes are provided. |
◆ operator()()
Executes the bootstrap sampling process.
- Returns
- A vector containing the \( M \) randomly sampled indices.
◆ dist_
| std::uniform_int_distribution<size_t> cmp::statistics::Bootstrap::dist_ |
|
private |
Uniform integer distribution for sampling with replacement.
◆ indices_
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 |
◆ 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: