emukit.core.loop package

Submodules

class emukit.core.loop.candidate_point_calculators.CandidatePointCalculator

Bases: ABC

Computes the next point(s) for function evaluation

abstract compute_next_points(loop_state, context=None)
Parameters:
  • loop_state (LoopState) – Object that contains current state of the loop

  • context (Optional[dict]) – Contains variables to fix through optimization of acquisition function. The dictionary key is the parameter name and the value is the value to fix the parameter to.

Return type:

ndarray

Returns:

(n_points x n_dims) array of next inputs to evaluate the function at

class emukit.core.loop.candidate_point_calculators.SequentialPointCalculator(acquisition, acquisition_optimizer)

Bases: CandidatePointCalculator

This candidate point calculator chooses one candidate point at a time

compute_next_points(loop_state, context=None)

Computes point(s) to evaluate next

Parameters:
  • loop_state (LoopState) – Object that contains current state of the loop

  • context (Optional[dict]) – Contains variables to fix through optimization of acquisition function. The dictionary key is the parameter name and the value is the value to fix the parameter to.

Return type:

ndarray

Returns:

List of function inputs to evaluate the function at next

class emukit.core.loop.candidate_point_calculators.GreedyBatchPointCalculator(model, acquisition, acquisition_optimizer, batch_size=1)

Bases: CandidatePointCalculator

Batch point calculator. This point calculator calculates the first point in the batch then adds this as a fake observation in the model with a Y value equal to the mean prediction. The model is reset with the original data at the end of collecting a batch but if you use a model where training the model with the same data leads to different predictions, the model behaviour will be modified.

compute_next_points(loop_state, context=None)
Parameters:
  • loop_state (LoopState) – Object containing history of the loop

  • context (Optional[dict]) – Contains variables to fix through optimization of acquisition function. The dictionary key is the parameter name and the value is the value to fix the parameter to.

Return type:

ndarray

Returns:

2d array of size (batch_size x input dimensions) of new points to evaluate

class emukit.core.loop.candidate_point_calculators.RandomSampling(parameter_space)

Bases: CandidatePointCalculator

Samples a new candidate point uniformly at random

compute_next_points(loop_state, context=None)
Parameters:
  • loop_state (LoopState) – Object that contains current state of the loop

  • context (Optional[dict]) – Contains variables to fix through optimization of acquisition function. The dictionary key is the parameter name and the value is the value to fix the parameter to.

Return type:

ndarray

Returns:

(1 x n_dims) array of next inputs to evaluate the function at

class emukit.core.loop.loop_state.LoopState(initial_results)

Bases: object

Contains the state of the loop, which includes a history of all function evaluations

update(results)
Parameters:

results (List[UserFunctionResult]) – The latest function results since last update

Return type:

None

property X: ndarray

Function inputs for all function evaluations in a 2d array: number of points by input dimensions.

Type:

return

property Y: ndarray

Function outputs for all function evaluations in a 2d array: number of points by output dimensions.

Type:

return

emukit.core.loop.loop_state.create_loop_state(x_init, y_init, **kwargs)

Creates a loop state object using the provided data

Parameters:
  • x_init (ndarray) – x values for initial function evaluations. Shape: (n_initial_points x n_input_dims)

  • y_init (ndarray) – y values for initial function evaluations. Shape: (n_initial_points x n_output_dims)

  • kwargs – extra outputs observed from a function evaluation. Shape: (n_initial_points x n_dims)

Return type:

LoopState

class emukit.core.loop.model_updaters.ModelUpdater

Bases: ABC

abstract update(loop_state)

Updates the training data of the model. Chooses whether to update hyper-parameters and how to do it

Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

None

class emukit.core.loop.model_updaters.NoopModelUpdater

Bases: ModelUpdater

update(loop_state)

Dummy model updater that does nothing. It can be used for example for random search

Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

None

class emukit.core.loop.model_updaters.FixedIntervalUpdater(model, interval=1, targets_extractor_fcn=None)

Bases: ModelUpdater

Updates hyper-parameters every nth iteration, where n is defined by the user

update(loop_state)
Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

None

class emukit.core.loop.outer_loop.OuterLoop(candidate_point_calculator, model_updaters, loop_state=None)

Bases: object

Generic outer loop that provides the framework for decision making parts of Emukit.

The loop can be used in two modes:

  1. Emukit calculates the next point(s) to try and evaluates your function at these points until some stopping criterion is met.

  2. Emukit only calculates the next points(s) to try and you evaluate your function or perform the experiment.

This object exposes the following events. See emukit.core.event_handler for details of how to subscribe:
  • loop_start_event called at the start of the run_loop method

  • iteration_end_event called at the end of each iteration

run_loop(user_function, stopping_condition, context=None)
Parameters:
  • user_function (Union[UserFunction, Callable]) – The function that we are emulating

  • stopping_condition (Union[StoppingCondition, int]) – If integer - a number of iterations to run, or an object - a stopping condition object that decides whether we should stop collecting more points. Note that stopping conditions can be logically combined (&, |) to represent complex stopping criteria.

  • context (Optional[dict]) – The context is used to force certain parameters of the inputs to the function of interest to have a given value. It is a dictionary whose keys are the parameter names to fix and the values are the values to fix the parameters to.

Return type:

None

get_next_points(results=None, context={})

This method is used when the user doesn’t want Emukit to evaluate the function of interest but rather just wants the input locations to evaluate the function at. This method calculates the new input locations.

Parameters:
  • results (Optional[List[UserFunctionResult]]) – Function results since last loop step

  • context (dict) – A dictionary of fixed parameters, identical to the context used in self.run_loop()

Return type:

ndarray

Returns:

Next batch of points to run

class emukit.core.loop.stopping_conditions.StoppingCondition

Bases: ABC

Chooses whether to stop the optimization based on the loop state

abstract should_stop(loop_state)
Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

bool

Returns:

Whether to stop collecting new data

class emukit.core.loop.stopping_conditions.And(left, right)

Bases: StoppingCondition

Logical AND of two stopping conditions

should_stop(loop_state)

Evaluate logical AND of two stopping conditions

Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

bool

Returns:

Whether to stop collecting new data

class emukit.core.loop.stopping_conditions.Or(left, right)

Bases: StoppingCondition

Logical OR of two stopping conditions

should_stop(loop_state)

Evaluate logical OR of two stopping conditions

Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

bool

Returns:

Whether to stop collecting new data

class emukit.core.loop.stopping_conditions.FixedIterationsStoppingCondition(i_max)

Bases: StoppingCondition

Stops after a fixed number of iterations

should_stop(loop_state)
Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

bool

Returns:

True if maximum number of iterations has been reached

class emukit.core.loop.stopping_conditions.ConvergenceStoppingCondition(eps)

Bases: StoppingCondition

Stops once we choose a point within eps of a previous point (with respect to euclidean norm). Close evaluations can suggest convergence of the optimization for problems with low observation noise.

should_stop(loop_state)
Parameters:

loop_state (LoopState) – Object that contains current state of the loop

Return type:

bool

Returns:

True if the euclidean distance between the last two evaluations is smaller than the specified eps.

This file contains the “UserFunction” base class and implementations

The user function is the objective function in optimization, the integrand in quadrature or the function to be learnt in experimental design.

class emukit.core.loop.user_function.UserFunction

Bases: ABC, Callable

The user supplied function is interrogated as part of the outer loop

abstract evaluate(X)
Return type:

List[UserFunctionResult]

class emukit.core.loop.user_function.UserFunctionWrapper(f, extra_output_names=None)

Bases: UserFunction

Wraps a user-provided python function.

evaluate(inputs)

Evaluates python function by providing it with numpy types and converts the output to a List of UserFunctionResults

Parameters:

inputs (ndarray) – List of function inputs at which to evaluate function

Return type:

List[UserFunctionResult]

Returns:

List of function results

class emukit.core.loop.user_function.MultiSourceFunctionWrapper(f, source_index=-1, extra_output_names=None)

Bases: UserFunction

Wraps a list of python functions that each correspond to different information source.

evaluate(inputs)

Evaluates the python functions corresponding to the appropriate information source

Parameters:

inputs (ndarray) – A list of inputs to evaluate the function at with information source index appended as last column

Return type:

List[UserFunctionResult]

Returns:

A list of function outputs

class emukit.core.loop.user_function_result.UserFunctionResult(X, Y, **kwargs)

Bases: object

A class that records the inputs, outputs and meta-data of an evaluation of the user function.

Module contents