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
- 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
- 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
- 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
- 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
- property X: ndarray¶
Function inputs for all function evaluations in a 2d array: number of points by input dimensions.
- Type
return
- Return type
ndarray
- property Y: ndarray¶
Function outputs for all function evaluations in a 2d array: number of points by output dimensions.
- Type
return
- Return type
ndarray
- 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
- class emukit.core.loop.model_updaters.NoopModelUpdater¶
Bases:
ModelUpdater
- 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
- 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:
Emukit calculates the next point(s) to try and evaluates your function at these points until some stopping criterion is met.
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 methoditeration_end_event
called at the end of each iteration
- run_loop(user_function, stopping_condition, context=None)¶
- Parameters
user_function (
Callable
) – The function that we are emulatingstopping_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
- 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 stepcontext (
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
- class emukit.core.loop.stopping_conditions.And(left, right)¶
Bases:
StoppingCondition
Logical AND of two stopping conditions
- class emukit.core.loop.stopping_conditions.Or(left, right)¶
Bases:
StoppingCondition
Logical OR of two stopping conditions
- class emukit.core.loop.stopping_conditions.FixedIterationsStoppingCondition(i_max)¶
Bases:
StoppingCondition
Stops after a fixed number of iterations
- 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.
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(*args, **kwds)¶
Bases:
ABC
,Callable
The user supplied function is interrogated as part of the outer loop
- abstract evaluate(X)¶
- Return type
- 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
- 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
- Returns
A list of function outputs