optilab.metamodels package

Submodules

optilab.metamodels.approximate_ranking_metamodel module

Approximate ranking metamodel based on lmm-CMA-ES.

class ApproximateRankingMetamodel(population_size: int, mu: int, objective_function: ObjectiveFunction, surrogate_function: SurrogateObjectiveFunction, *, buffer_size: int | None = None)[source]

Bases: object

Approximate ranking metamodel based on lmm-CMA-ES

__init__(population_size: int, mu: int, objective_function: ObjectiveFunction, surrogate_function: SurrogateObjectiveFunction, *, buffer_size: int | None = None) None[source]

Class constructor.

Parameters:
  • population_size – The population size (lambda).

  • mu – The number of points compared in the ranking procedure (mu).

  • objective_function – The objective function that’s being optimized.

  • surrogate_function – Surrogate function used to estimate the optimized function.

  • buffer_size – Number of last evaluated samples to use for training the surrogate function. If None, all samples are used.

init_n() None[source]

Initializes n_init and n_step values based on the population size.

_update_n(num_iters: int) None[source]

Updates n_init and n_step values base on the number of algorithm iterations.

Parameters:

num_iters – The number of iterations done by the algorithm.

__call__(points: PointList) PointList[source]

Approximates the values of provided points with surrogate objective function.

Parameters:

points – List of points to evaluate.

Returns:

List of evaluated points.

train_surrogate() None[source]

Retrain the surrogate function with samples from the training set.

evaluate(xs: PointList) PointList[source]

Evaluate provided point with the objective function and append results to the training set and retrain the surrogate function on new training data.

Parameters:

xs – List of point to evaluate with the objective function.

Returns:

List of evaluated points.

get_log() PointList[source]

Get the list of points evaluated by the objective function.

Returns:

List of points evaluated by the objective function.

adapt(xs: PointList) None[source]

Perform another loop of the optimization on new data.

Parameters:

xs – Solution candidates generated by the optimizer.

Raises:

ValueError – When number of provided points mismatches the expected input size.

optilab.metamodels.iepolation_surrogate module

Inter-extra-polation surrogate metamodel. It uses different surrogate functions for interpolation and extrapolation.

class IEPolationSurrogate(interpolation_surrogate: SurrogateObjectiveFunction, extrapolation_surrogate: SurrogateObjectiveFunction, train_set: PointList | None = None)[source]

Bases: SurrogateObjectiveFunction

Inter-extra-polation surrogate metamodel. It uses different surrogate functions for interpolation and extrapolation.

__init__(interpolation_surrogate: SurrogateObjectiveFunction, extrapolation_surrogate: SurrogateObjectiveFunction, train_set: PointList | None = None) None[source]

Class constructor.

Parameters:
  • interpolation_surrogate – Surrogate used for interpolation.

  • extrapolation_surrogate – Surrogate used for extrapolation.

  • train_set – Initial training set for the surrogates.

build_convex_hull(train_set: PointList) None[source]

Builds a convex hull from the train set. This convex hull is then used to determine wheather the point value should be interpolated or extrapolated.

Parameters:

train_set – Training set.

train(train_set: PointList) None[source]

Train both surrogate functions with provided data.

Parameters:

train_set – Training data for the model.

is_in_convex_hull(point: Point) bool[source]

Check if the given point lies inside of the convex hull of training points.

Parameters:

point – The point to be checked.

Returns:

True if the given point lies inside the convex hull, False otherwise.

__call__(point: Point) Point[source]

Estimate the value of a single point with the surrogate function.

Parameters:

x – Point to estimate.

Raises:

ValueError – If dimensionality of x doesn’t match self.dim.

Returns:

Estimated point.

Return type:

Point

optilab.metamodels.top_half_metamodel module

Top half metamodel. Estimates all points using the surrogate function, then evaluates the top mu (typically half) points with the objective function.

class TopHalfMetamodel(population_size: int, mu: int, objective_function: ObjectiveFunction, surrogate_function: SurrogateObjectiveFunction, *, buffer_size: int | None = None)[source]

Bases: object

Top-half metamodel.

Estimates all points using the surrogate function, then calculates the real value for the top mu (typically half, hence the name) using the actual objective function. The remaining points get a value that’s guaranteed to be worse than the rest of the points.

__init__(population_size: int, mu: int, objective_function: ObjectiveFunction, surrogate_function: SurrogateObjectiveFunction, *, buffer_size: int | None = None) None[source]

Class constructor.

Parameters:
  • population_size – The population size (lambda).

  • mu – Number of elite solutions (typically population_size // 2).

  • objective_function – The real objective function.

  • surrogate_function – Surrogate used to pre-screen candidates.

  • buffer_size – If set, only the last buffer_size real evaluations are used as the surrogate training set.

__call__(points: PointList) PointList[source]

Return evaluated / estimated values for points.

If adapt() was called immediately before, returns the combined results (real values for top half, penalised for bottom half) and clears the internal cache. Otherwise falls back to pure surrogate estimation.

Parameters:

points – Candidate solutions.

Returns:

PointList with y-values set for every point.

adapt(xs: PointList) None[source]

Screen xs with the surrogate, evaluate the best half with the real objective, and cache a combined result for the next __call__().

Parameters:

xs – Candidate solutions (must have length == population_size).

Raises:

ValueError – If the number of points does not match population_size.

train_surrogate() None[source]

Retrain the surrogate on the real evaluations.

evaluate(xs: PointList) PointList[source]

Evaluate xs with the real objective, extend the training set, and retrain the surrogate.

Parameters:

xs – Points to evaluate.

Returns:

PointList of evaluated points.

get_log() PointList[source]

Return all points evaluated with the real objective so far.

Module contents

Module containing metamodels.