Ensemble Bootstrap#
bootstrap
#
| CLASS | DESCRIPTION |
|---|---|
BootstrapSpectral |
Bootstrap reduction for spectral methods. |
Attributes#
Classes#
BootstrapSpectral(estimator: ModelType, n_estimators: int = 10, sample_fraction: float = 1.0, reduce: str = 'mean', fit_manager: FitManager | None = None)
#
Bases: Ensemble
Bootstrap reduction for spectral methods.
Fits multiple spectral estimators on bootstrap samples of the data, providing uncertainty quantification. Useful for assessing reliability of spectral features and identifying stable components.
| PARAMETER | DESCRIPTION |
|---|---|
estimator
|
Base spectral estimator to bootstrap.
TYPE:
|
n_estimators
|
Number of bootstrap samples/estimators to clone.
TYPE:
|
sample_fraction
|
Fraction of data to sample for each bootstrap (0, 1]. Value of 1.0 means sample same size as original data (with replacement).
TYPE:
|
reduce
|
How to aggregate bootstrap predictions:
TYPE:
|
fit_manager
|
Manager for unified training of both Estimator and Parametric models. Required for using Parametric (PyTorch Lightning) models in bootstrap ensemble. See FitManager for configuration options.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
estimators |
Dictionary of fitted bootstrap estimators.
TYPE:
|
Examples:
Bootstrap ensemble for diffusion map:
>>> from spectre.decomposition import DiffusionMap
>>> from spectre.kernel import GaussianKernel
>>> from spectre.pairwise_distance import PairwiseDistanceEuclidean
>>> from spectre.ensemble import BootstrapSpectral
>>>
>>> base_dm = DiffusionMap(
... kernel_fn=GaussianKernel(bw_method="median"),
... distance_fn=PairwiseDistanceEuclidean(),
... out_features=5,
... )
>>>
>>> bootstrap = BootstrapSpectral(
... estimator=base_dm,
... n_estimators=50,
... sample_fraction=1.0,
... )
Analyze uncertainty in embeddings:
>>> X_emb, X_lower, X_upper = bootstrap.predict_with_uncertainty(X)
>>> # Identify samples with high uncertainty (wide confidence intervals)
>>> uncertainty = X_upper - X_lower
>>> uncertain_samples = uncertainty.mean(dim=1) > uncertainty.mean() * 2
>>> print(f"Uncertain samples: {uncertain_samples.sum().item()}")
| METHOD | DESCRIPTION |
|---|---|
fit |
Fit bootstrap estimators on bootstrap samples. |
predict |
Reduce predictions from bootstrap estimators. |
predict_with_uncertainty |
Return predictions with uncertainty estimates. |
score |
Average score across bootstrap estimators. |
Source code in spectre/ensemble/bootstrap.py
Functions#
fit(X: torch.Tensor, weights: torch.Tensor | None = None, target: torch.Tensor | None = None) -> BootstrapSpectral
#
Fit bootstrap estimators on bootstrap samples.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training data of shape (n_samples, in_features).
TYPE:
|
weights
|
Sample weights.
TYPE:
|
target
|
Target values for supervised methods.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BootstrapSpectral
|
Returns self for method chaining. |
Source code in spectre/ensemble/bootstrap.py
predict(X: torch.Tensor) -> torch.Tensor
#
Reduce predictions from bootstrap estimators.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Input data of shape (n_samples, in_features).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Reduced prediction of shape (n_samples, out_features). |
Source code in spectre/ensemble/bootstrap.py
predict_with_uncertainty(X: torch.Tensor, confidence_level: float = 0.95) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]
#
Return predictions with uncertainty estimates.
Computes mean prediction and confidence intervals across bootstrap estimators to quantify uncertainty.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Input data of shape (n_samples, in_features).
TYPE:
|
confidence_level
|
Confidence level for uncertainty intervals (e.g., 0.95 for 95% CI).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of torch.Tensor
|
A tuple containing:
|
Source code in spectre/ensemble/bootstrap.py
score(X: torch.Tensor, weights: torch.Tensor | None = None, target: torch.Tensor | None = None) -> float
#
Average score across bootstrap estimators.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Input data.
TYPE:
|
weights
|
Sample weights.
TYPE:
|
target
|
Target values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Mean score across estimators. |