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: Callable[[Module], None] | None = None, device: device | None = None, criterion: Callable[[list[Module], DataLoader, device], float] | None = 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 | DataLoader | None | 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: Callable[[Module], None] | None = None, device: device | None = None, criterion: Callable[[list[Module], DataLoader, device], float] | None = 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 | DataLoader | None | 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: device | None = None, criterion: Callable[[list[Module], DataLoader, device], float] | None = 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. |
Source code in bensemble/search/bayesian.py
Search Space
bensemble.search.space.SearchSpace
Bases: ABC
build abstractmethod
mutate abstractmethod
Return a new config that is a mutated copy of the given config. Must not modify the input config in place.
Member Selection
bensemble.search.selection
classification_nll_criterion
classification_nll_criterion(members: list[Module], val_loader: DataLoader, device: device) -> float
Evaluates classification Negative Log-Likelihood of an ensemble candidate set.
Predictions from all members are converted to softmax probabilities and averaged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
members | list[Module] | List of candidate neural network modules in eval mode. | required |
val_loader | DataLoader | DataLoader yielding validation (inputs, labels) batches. | required |
device | device | Device on which to run inference. | required |
Returns:
| Name | Type | Description |
|---|---|---|
float | float | Mean negative log-likelihood score over the validation set. |
Source code in bensemble/search/selection.py
forward_select
forward_select(pool: list[Module], val_loader: DataLoader, ensemble_size: int, device: device, criterion: Callable[[list[Module], DataLoader, device], float]) -> list[nn.Module]
Performs greedy forward stepwise ensemble selection without replacement.
Iteratively selects models from pool that minimize the metric returned by criterion on val_loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pool | list[Module] | Candidate neural network modules. | required |
val_loader | DataLoader | Validation DataLoader yielding (inputs, targets) batches. | required |
ensemble_size | int | Number of members to select. | required |
device | device | Device on which to execute evaluation. | required |
criterion | Callable[[list[Module], DataLoader, device], float] | Evaluation callable | required |
Returns:
| Type | Description |
|---|---|
list[Module] | list[nn.Module]: List of selected model instances of length |
Source code in bensemble/search/selection.py
regression_mse_criterion
Evaluates Mean Squared Error of an ensemble candidate set.
Predictions from all members are averaged directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
members | list[Module] | List of candidate neural network modules in eval mode. | required |
val_loader | DataLoader | DataLoader yielding validation (inputs, targets) batches. | required |
device | device | Device on which to run inference. | required |
Returns:
| Name | Type | Description |
|---|---|---|
float | float | Mean squared error score over the validation set. |