Neural Ensemble Search (NAS)
Algorithms for searching diverse and high-performing architectures.
Random Search
bensemble.search.nes.RandomSearcher
RandomSearcher(
space: SearchSpace,
pool_size: int = 50,
ensemble_size: int = 5,
train_fn: Optional[Callable[[Module], None]] = None,
device: Optional[device] = None,
criterion: Optional[
Callable[[list[Module], DataLoader, device], float]
] = None,
)
NES with Random Search (NES-RS, Algorithm 2 in Zaidi et al. NeurIPS 2021).
Builds a pool of pool_size independently trained models with randomly sampled architectures, then applies greedy forward ensemble selection to pick the final ensemble of ensemble_size members.
Source code in bensemble/search/nes.py
search
Run NES-RS and return the selected ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val_loader | DataLoader | Validation loader used for ensemble selection. | required |
val_loader_shift | Optional[DataLoader] | If provided, used instead of | None |
Returns:
| Type | Description |
|---|---|
Ensemble | Ensemble of |
Source code in bensemble/search/nes.py
Evolutionary Search
bensemble.search.nes.EvolutionarySearcher
EvolutionarySearcher(
space: SearchSpace,
pool_size: int = 50,
ensemble_size: int = 5,
population_size: int = 10,
num_parent_candidates: int = 3,
train_fn: Optional[Callable[[Module], None]] = None,
device: Optional[device] = None,
criterion: Optional[
Callable[[list[Module], DataLoader, device], float]
] = None,
)
NES with Regularized Evolution (NES-RE, Algorithm 1 in Zaidi et al. NeurIPS 2021).
Evolves a population of architectures using ensemble-aware parent selection (ForwardSelect on the population) and single-step mutation. The full history of trained models forms the pool from which the final ensemble is selected.
Source code in bensemble/search/nes.py
search
Run NES-RE and return the selected ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val_loader | DataLoader | Validation loader used for parent selection and final ensemble selection. | required |
val_loader_shift | Optional[DataLoader] | If provided, used instead of | None |
Returns:
| Type | Description |
|---|---|
Ensemble | Ensemble of |
Source code in bensemble/search/nes.py
Bayesian Sampling (SVGD)
bensemble.search.bayesian.NESBayesianSampler
NESBayesianSampler(
space: SearchSpace,
train_fn: Callable[[Module], None],
pool_size: int = 50,
ensemble_size: int = 5,
temperature: float = 1.0,
diversity_weight: float = 0.5,
svgd_steps: int = 20,
svgd_lr: float = 0.1,
device: Optional[device] = None,
criterion: Optional[
Callable[[list[Module], DataLoader, device], float]
] = None,
)
Neural Ensemble Search via Bayesian Sampling (NESBS, Shu et al., UAI 2022). This implementation follows the paper's practical recipe: 1) build a candidate model pool from a search space; 2) estimate a posterior over candidates from validation losses; 3) select a diverse final ensemble either by: - weighted Monte Carlo sampling, or - an SVGD-inspired iterative refinement with diversity regularization.
Source code in bensemble/search/bayesian.py
sample_mc
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val_loader | DataLoader | Used to evaluate the posterior. | required |
Returns:
| Name | Type | Description |
|---|---|---|
Ensemble | Ensemble | The final ensemble wrapped in bensemble's core abstraction. |
Source code in bensemble/search/bayesian.py
sample_svgd
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val_loader | DataLoader | Used to evaluate the architecture's loss/posterior. | required |
Returns:
| Name | Type | Description |
|---|---|---|
Ensemble | Ensemble | The final ensemble wrapped in bensemble's core abstraction. |