Skip to content

Configuration

Configs validate their values when created, and can be loaded from a JSON or YAML file with from_file. Each config lists the settings it shares with every optimizer as well as its own.

OptimizerConfig pydantic-model

Bases: BaseModel

Settings shared by every optimizer.

Config:

  • extra: forbid
  • frozen: True
  • use_attribute_docstrings: True

Fields:

Validators:

  • _check_final_evaluations

population_size pydantic-field

population_size: int = 100

Individuals evaluated per generation.

generations pydantic-field

generations: int = 25

Generations to run, unless the run stops sooner.

max_evaluations pydantic-field

max_evaluations: int | None = None

Stop after this many evaluations, even partway through a generation.

maximize pydantic-field

maximize: bool = False

Maximize the objective instead of minimizing it.

threshold pydantic-field

threshold: float | None = None

Stop once the best fitness reaches this.

seed pydantic-field

seed: int | None = None

Fixes the random number generator, so runs can be repeated.

noise pydantic-field

noise: bool = False

The objective is noisy: evaluating the same point twice can give different values.

final_evaluations pydantic-field

final_evaluations: int = 0

With noise, evaluations kept back to re-evaluate the most promising points at the end, so the result is chosen, and its value reported, from averages rather than single lucky values.

min_finished pydantic-field

min_finished: float = 1.0

The share of each generation's evaluations that must finish before the next generation is bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background, and their results join the generation under way when they arrive. Results then depend on timing, so runs are no longer exactly repeatable.

reserved_evaluations property

reserved_evaluations: int

Evaluations kept back for the final re-evaluation: none without noise.

from_file classmethod

from_file(filepath: str | Path) -> Self

Create a config from a JSON or YAML file.

BayesianConfig pydantic-model

Bases: OptimizerConfig

Configuration for Bayesian optimization. Usually only the budget, max_evaluations, needs setting.

Each generation is a batch of candidates chosen together. When max_evaluations is set and generations isn't, generations defaults to the budget, so the run ends when the budget is spent.

Fields:

Validators:

  • _check_final_evaluations
  • _generations_from_budget

max_evaluations pydantic-field

max_evaluations: int | None = None

Stop after this many evaluations, even partway through a generation.

maximize pydantic-field

maximize: bool = False

Maximize the objective instead of minimizing it.

threshold pydantic-field

threshold: float | None = None

Stop once the best fitness reaches this.

seed pydantic-field

seed: int | None = None

Fixes the random number generator, so runs can be repeated.

noise pydantic-field

noise: bool = False

The objective is noisy: evaluating the same point twice can give different values.

final_evaluations pydantic-field

final_evaluations: int = 0

With noise, evaluations kept back to re-evaluate the most promising points at the end, so the result is chosen, and its value reported, from averages rather than single lucky values.

min_finished pydantic-field

min_finished: float = 1.0

The share of each generation's evaluations that must finish before the next generation is bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background, and their results join the generation under way when they arrive. Results then depend on timing, so runs are no longer exactly repeatable.

reserved_evaluations property

reserved_evaluations: int

Evaluations kept back for the final re-evaluation: none without noise.

population_size pydantic-field

population_size: int | None = None

Candidates per batch. None: 1, or the number of workers.

generations pydantic-field

generations: int = 100

Batches to run, unless the run stops sooner.

initial_samples pydantic-field

initial_samples: int | None = None

Spread-out candidates evaluated before the model is used. None: 2 × (variables + 1).

from_file classmethod

from_file(filepath: str | Path) -> Self

Create a config from a JSON or YAML file.

CMAESConfig pydantic-model

Bases: OptimizerConfig

Configuration for CMA-ES. The defaults suit most problems; usually only the budget needs setting.

Fields:

Validators:

  • _check_final_evaluations

max_evaluations pydantic-field

max_evaluations: int | None = None

Stop after this many evaluations, even partway through a generation.

maximize pydantic-field

maximize: bool = False

Maximize the objective instead of minimizing it.

threshold pydantic-field

threshold: float | None = None

Stop once the best fitness reaches this.

seed pydantic-field

seed: int | None = None

Fixes the random number generator, so runs can be repeated.

noise pydantic-field

noise: bool = False

The objective is noisy: evaluating the same point twice can give different values.

final_evaluations pydantic-field

final_evaluations: int = 0

With noise, evaluations kept back to re-evaluate the most promising points at the end, so the result is chosen, and its value reported, from averages rather than single lucky values.

min_finished pydantic-field

min_finished: float = 1.0

The share of each generation's evaluations that must finish before the next generation is bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background, and their results join the generation under way when they arrive. Results then depend on timing, so runs are no longer exactly repeatable.

reserved_evaluations property

reserved_evaluations: int

Evaluations kept back for the final re-evaluation: none without noise.

population_size pydantic-field

population_size: int | None = None

Candidates per generation. None: 4 + 3 ln(n) for n variables, or twice the workers if more.

generations pydantic-field

generations: int = 1000

An upper bound; max_evaluations is the usual way to set a budget.

initial_step pydantic-field

initial_step: float = 0.3

Starting step size, as a fraction of each range.

restarts pydantic-field

restarts: bool = True

Restart with double the population when a run converges or stalls (IPOP-CMA-ES).

from_file classmethod

from_file(filepath: str | Path) -> Self

Create a config from a JSON or YAML file.

GeneticOptimizerConfig pydantic-model

Bases: OptimizerConfig

Configuration for the genetic optimizer.

When max_evaluations is set, population_size and generations default to suit it: the population to about a twentieth of the budget, between 16 and 50, and generations to as many as the budget allows. Without a budget they default to 100 and 25.

Fields:

Validators:

  • _check_final_evaluations
  • _defaults_from_budget
  • _check_tournament_size

population_size pydantic-field

population_size: int = 100

Individuals evaluated per generation.

generations pydantic-field

generations: int = 25

Generations to run, unless the run stops sooner.

max_evaluations pydantic-field

max_evaluations: int | None = None

Stop after this many evaluations, even partway through a generation.

maximize pydantic-field

maximize: bool = False

Maximize the objective instead of minimizing it.

threshold pydantic-field

threshold: float | None = None

Stop once the best fitness reaches this.

seed pydantic-field

seed: int | None = None

Fixes the random number generator, so runs can be repeated.

noise pydantic-field

noise: bool = False

The objective is noisy: evaluating the same point twice can give different values.

final_evaluations pydantic-field

final_evaluations: int = 0

With noise, evaluations kept back to re-evaluate the most promising points at the end, so the result is chosen, and its value reported, from averages rather than single lucky values.

min_finished pydantic-field

min_finished: float = 1.0

The share of each generation's evaluations that must finish before the next generation is bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background, and their results join the generation under way when they arrive. Results then depend on timing, so runs are no longer exactly repeatable.

reserved_evaluations property

reserved_evaluations: int

Evaluations kept back for the final re-evaluation: none without noise.

mutation_rate pydantic-field

mutation_rate: float | None = None

Chance each gene of a child is mutated. None: 1 / the number of variables, at least 0.1; with noise, 0.1, which the benchmark's noisy problems favour at large budgets.

mutation_scale pydantic-field

mutation_scale: float = 0.1

Size of a range mutation, as a fraction of the range width: the starting size when mutation adapts, and the size throughout when it doesn't.

adaptive_mutation pydantic-field

adaptive_mutation: bool | None = None

Each individual carries its own mutation size, which its children inherit and vary, so selection tunes it as the run goes. None: on, except with noise, where it didn't help.

crossover_rate pydantic-field

crossover_rate: float = 0.8

Chance each gene of a child comes from its first parent.

blend_crossover pydantic-field

blend_crossover: bool = True

Draw each range value of a child from between its parents' values, widened by blend_alpha times their distance on each side, rather than copying one.

blend_alpha pydantic-field

blend_alpha: float = 0.1

How far beyond its parents' values a blended range value may fall, as a multiple of their distance.

elitism pydantic-field

elitism: bool = True

Carry the fittest individuals over to the next generation unchanged.

elitism_rate pydantic-field

elitism_rate: float = 0.1

Share of each generation carried over unchanged, at most all but one individual.

selection_method pydantic-field

selection_method: SelectionMethod = SelectionMethod.TOURNAMENT

How parents are chosen.

tournament_size pydantic-field

tournament_size: int = 4

Individuals drawn for each tournament; the fittest of them becomes a parent.

tournament_p pydantic-field

tournament_p: float = 1.0

Chance a tournament picks its best rather than its worst.

niche_share pydantic-field

niche_share: float | None = None

Share of children bred within niches of parents with the same choice parameter values, so each option keeps tuning its own numbers. Helps problems where the best choice is found late, on large budgets; costs on small ones. 0 turns niches off. None, the default, means 0.5 for a search space with conditions, where each branch is a niche, and 0 otherwise.

from_file classmethod

from_file(filepath: str | Path) -> Self

Create a config from a JSON or YAML file.

SelectionMethod

Bases: StrEnum

Selection methods for the genetic algorithm.

MultiObjectiveConfig pydantic-model

Bases: OptimizerConfig

Settings for optimizing several objectives together.

objectives names each objective and whether to minimize or maximize it, such as {"accuracy": "maximize", "cost": "minimize"}; the objective function returns a dict with exactly those keys. It takes the place of maximize, and threshold and final_evaluations don't apply.

Fields:

Validators:

  • _check_final_evaluations
  • _check_objectives

population_size pydantic-field

population_size: int = 100

Individuals evaluated per generation.

generations pydantic-field

generations: int = 25

Generations to run, unless the run stops sooner.

max_evaluations pydantic-field

max_evaluations: int | None = None

Stop after this many evaluations, even partway through a generation.

maximize pydantic-field

maximize: bool = False

Maximize the objective instead of minimizing it.

threshold pydantic-field

threshold: float | None = None

Stop once the best fitness reaches this.

seed pydantic-field

seed: int | None = None

Fixes the random number generator, so runs can be repeated.

noise pydantic-field

noise: bool = False

The objective is noisy: evaluating the same point twice can give different values.

final_evaluations pydantic-field

final_evaluations: int = 0

With noise, evaluations kept back to re-evaluate the most promising points at the end, so the result is chosen, and its value reported, from averages rather than single lucky values.

min_finished pydantic-field

min_finished: float = 1.0

The share of each generation's evaluations that must finish before the next generation is bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background, and their results join the generation under way when they arrive. Results then depend on timing, so runs are no longer exactly repeatable.

reserved_evaluations property

reserved_evaluations: int

Evaluations kept back for the final re-evaluation: none without noise.

objectives pydantic-field

objectives: dict[str, Direction]

Each objective's name, and whether to minimize or maximize it.

reference pydantic-field

reference: dict[str, float] | None = None

A point every objective must be better than to count toward hypervolume, by objective. None: the worst value of each objective in the first generation, a tenth of its range further out.

from_file classmethod

from_file(filepath: str | Path) -> Self

Create a config from a JSON or YAML file.

MultiObjectiveBayesianConfig pydantic-model

Bases: MultiObjectiveConfig

Configuration for multi-objective Bayesian optimization. Usually only the budget, max_evaluations, needs setting.

As with BayesianConfig, each generation is a batch of candidates chosen together, and with max_evaluations set, generations defaults to the budget.

Fields:

Validators:

  • _check_final_evaluations
  • _check_objectives
  • _generations_from_budget

max_evaluations pydantic-field

max_evaluations: int | None = None

Stop after this many evaluations, even partway through a generation.

maximize pydantic-field

maximize: bool = False

Maximize the objective instead of minimizing it.

threshold pydantic-field

threshold: float | None = None

Stop once the best fitness reaches this.

seed pydantic-field

seed: int | None = None

Fixes the random number generator, so runs can be repeated.

noise pydantic-field

noise: bool = False

The objective is noisy: evaluating the same point twice can give different values.

final_evaluations pydantic-field

final_evaluations: int = 0

With noise, evaluations kept back to re-evaluate the most promising points at the end, so the result is chosen, and its value reported, from averages rather than single lucky values.

min_finished pydantic-field

min_finished: float = 1.0

The share of each generation's evaluations that must finish before the next generation is bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background, and their results join the generation under way when they arrive. Results then depend on timing, so runs are no longer exactly repeatable.

reserved_evaluations property

reserved_evaluations: int

Evaluations kept back for the final re-evaluation: none without noise.

objectives pydantic-field

objectives: dict[str, Direction]

Each objective's name, and whether to minimize or maximize it.

reference pydantic-field

reference: dict[str, float] | None = None

A point every objective must be better than to count toward hypervolume, by objective. None: the worst value of each objective in the first generation, a tenth of its range further out.

population_size pydantic-field

population_size: int | None = None

Candidates per batch. None: 1, or the number of workers.

generations pydantic-field

generations: int = 100

Batches to run, unless the run stops sooner.

initial_samples pydantic-field

initial_samples: int | None = None

Spread-out candidates evaluated before the models are used. None: 2 × (variables + 1).

method pydantic-field

method: Literal['parego', 'models'] = 'parego'

How candidates are chosen. "parego": a random weighting of the scaled objectives per candidate, scored by one Gaussian process. "models": one Gaussian process per objective, with the weighting applied to their predictions.

from_file classmethod

from_file(filepath: str | Path) -> Self

Create a config from a JSON or YAML file.

NSGA2Config pydantic-model

Bases: MultiObjectiveConfig

Configuration for NSGA2, the multi-objective genetic optimizer.

Breeding works as in the genetic optimizer, with the same settings; selection and elitism are NSGA-II's own. With max_evaluations set, population_size and generations default as for the genetic optimizer.

Fields:

Validators:

  • _check_final_evaluations
  • _check_objectives
  • _defaults_from_budget

population_size pydantic-field

population_size: int = 100

Individuals evaluated per generation.

generations pydantic-field

generations: int = 25

Generations to run, unless the run stops sooner.

max_evaluations pydantic-field

max_evaluations: int | None = None

Stop after this many evaluations, even partway through a generation.

maximize pydantic-field

maximize: bool = False

Maximize the objective instead of minimizing it.

threshold pydantic-field

threshold: float | None = None

Stop once the best fitness reaches this.

seed pydantic-field

seed: int | None = None

Fixes the random number generator, so runs can be repeated.

noise pydantic-field

noise: bool = False

The objective is noisy: evaluating the same point twice can give different values.

final_evaluations pydantic-field

final_evaluations: int = 0

With noise, evaluations kept back to re-evaluate the most promising points at the end, so the result is chosen, and its value reported, from averages rather than single lucky values.

min_finished pydantic-field

min_finished: float = 1.0

The share of each generation's evaluations that must finish before the next generation is bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background, and their results join the generation under way when they arrive. Results then depend on timing, so runs are no longer exactly repeatable.

reserved_evaluations property

reserved_evaluations: int

Evaluations kept back for the final re-evaluation: none without noise.

objectives pydantic-field

objectives: dict[str, Direction]

Each objective's name, and whether to minimize or maximize it.

reference pydantic-field

reference: dict[str, float] | None = None

A point every objective must be better than to count toward hypervolume, by objective. None: the worst value of each objective in the first generation, a tenth of its range further out.

mutation_rate pydantic-field

mutation_rate: float | None = None

As in GeneticOptimizerConfig: chance each gene of a child is mutated.

mutation_scale pydantic-field

mutation_scale: float = 0.1

As in GeneticOptimizerConfig: size of a range mutation, as a fraction of the range width.

adaptive_mutation pydantic-field

adaptive_mutation: bool | None = None

As in GeneticOptimizerConfig: each individual carries its own mutation size.

crossover_rate pydantic-field

crossover_rate: float = 0.8

As in GeneticOptimizerConfig: chance each gene of a child comes from its first parent.

blend_crossover pydantic-field

blend_crossover: bool = True

As in GeneticOptimizerConfig: draw each range value of a child from between its parents' values.

blend_alpha pydantic-field

blend_alpha: float = 0.1

As in GeneticOptimizerConfig: how far beyond its parents' values a blended value may fall.

niche_share pydantic-field

niche_share: float | None = None

As in GeneticOptimizerConfig: share of children bred within niches of parents with the same choices.

from_file classmethod

from_file(filepath: str | Path) -> Self

Create a config from a JSON or YAML file.