Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

bootstrap

bootstrap

Bootstrap inference utilities with CPU/GPU support.

Attributes:

NameTypeDescription
FITTED_METHODS
SIMPLE_METHODS

Classes:

NameDescription
OnlineBootstrapStatsMemory-efficient online statistics aggregator for bootstrap samples.

Classes

OnlineBootstrapStats

OnlineBootstrapStats(shape: tuple[int, ...], save_samples: bool = False, percentiles: tuple[float, float] = (2.5, 97.5))

Memory-efficient online statistics aggregator for bootstrap samples.

Uses Welford’s algorithm for numerically stable online computation of mean and variance. Optionally stores all samples for exact percentile CIs.

Parameters:

NameTypeDescriptionDefault
shapetuple [ int , ...]Shape of each bootstrap sample.required
save_samplesboolIf True, store all samples for exact percentile confidence intervals. If False, use normal approximation (much more memory efficient). Defaults to False.False
percentilestuple [ float , float ]Percentiles for confidence intervals (e.g., (2.5, 97.5) for 95% CI). Defaults to (2.5, 97.5).(2.5, 97.5)

Attributes:

NameTypeDescription
M2
mean
n
percentiles
samples
save_samples
shape

Methods:

NameDescription
get_resultsCompute final bootstrap statistics.
updateUpdate statistics with a new bootstrap sample.

Examples:

>>> stats = OnlineBootstrapStats(shape=(100,), save_samples=False)
>>> for i in range(1000):
...     sample = np.random.randn(100)
...     stats.update(sample)
>>> results = stats.get_results()
>>> print(results.keys())
dict_keys(['mean', 'std', 'Z', 'p', 'ci_lower', 'ci_upper'])

Methods

get_results
get_results(tail: int | str = 2) -> dict[str, np.ndarray]

Compute final bootstrap statistics.

Parameters:

NameTypeDescriptionDefault
tailint | str2‘two’ (two-tailed, default) or 1

Returns:

TypeDescription
dict [ str , ndarray ]Dictionary containing:
dict [ str , ndarray ]- ‘mean’: Bootstrap mean
dict [ str , ndarray ]- ‘std’: Bootstrap standard deviation
dict [ str , ndarray ]- ‘Z’: Z-scores (mean/std)
dict [ str , ndarray ]- ‘p’: P-values (per tail)
dict [ str , ndarray ]- ‘ci_lower’: Lower confidence bound
dict [ str , ndarray ]- ‘ci_upper’: Upper confidence bound
dict [ str , ndarray ]- ‘samples’: All samples (only if save_samples=True)

Examples:

stats = OnlineBootstrapStats(shape=(100,), save_samples=False)
for _ in range(1000):
    stats.update(np.random.randn(100))
results = stats.get_results()
# results.keys() -> mean, std, Z, p, ci_lower, ci_upper
update
update(sample: np.ndarray) -> None

Update statistics with a new bootstrap sample.

Uses Welford’s algorithm for numerical stability.

Parameters:

NameTypeDescriptionDefault
samplendarrayNew bootstrap sample with shape matching self.shape.required

Methods