Skip to content

Base classes

Problem

Abstract class for optimization problems.

Subclasses implement eval to compute the fitness of a population and sample to draw a solution from the search space. sample is commonly used to obtain the example solution required by the algorithm constructors.

num_dims property

num_dims: int

Number of search dimensions, i.e. the total size of a solution.

init

init(key: Array) -> State

Initialize the problem state.

Parameters:

  • key (Array) –

    PRNG key.

Returns:

  • State –

    The initial problem state.

eval

eval(key: Array, solutions: Population, state: State) -> tuple[Fitness, State, Metrics]

Evaluate a population of solutions.

Parameters:

  • key (Array) –

    PRNG key.

  • solutions (Population) –

    Population to evaluate, a PyTree with a leading population axis on every leaf.

  • state (State) –

    Current problem state.

Returns:

  • tuple[Fitness, State, Metrics] –

    A tuple (fitness, state, info) with one fitness value per population member, the updated problem state and a dictionary of additional information.

sample

sample(key: Array) -> Solution

Sample a solution from the search space.

Parameters:

  • key (Array) –

    PRNG key.

Returns:

  • Solution –

    A single solution PyTree.

MetaProblem

Bases: Problem

Abstract class for meta-optimization problems.

Unlike Problem, init and eval take an additional params argument that selects the problem instance. Use sample_params to draw an instance.

sample_params

sample_params(key: Array) -> Params

Sample the parameters of a problem instance.

Parameters:

  • key (Array) –

    PRNG key.

Returns:

  • Params –

    Parameters identifying one problem instance.

init

init(key: Array, params: Params) -> State

Initialize the problem state for a problem instance.

Parameters:

  • key (Array) –

    PRNG key.

  • params (Params) –

    Parameters of the problem instance.

Returns:

  • State –

    The initial problem state.

eval

eval(key: Array, solutions: Population, state: State, params: Params) -> tuple[Fitness, State, Metrics]

Evaluate a population of solutions on a problem instance.

Parameters:

  • key (Array) –

    PRNG key.

  • solutions (Population) –

    Population to evaluate, a PyTree with a leading population axis on every leaf.

  • state (State) –

    Current problem state.

  • params (Params) –

    Parameters of the problem instance.

Returns:

  • tuple[Fitness, State, Metrics] –

    A tuple (fitness, state, info) with one fitness value per population member, the updated problem state and a dictionary of additional information.