8.2.2. The Bayesian Extension and utilities

Summary of the main classes for the Bayesian Optimization extension

BayesianOptimization(dockarea, dashboard)

PyMoDAQ extension of the DashBoard to perform the optimization of a target signal taken form the detectors as a function of one or more parameters controlled by the actuators.

optimizers_base.models.OptimizerModelGeneric(...)

optimizers_base.models.OptimizerModelDefault(...)

8.2.2.1. The Extension module

class pymodaq.extensions.BayesianOptimization(dockarea, dashboard)[source]

PyMoDAQ extension of the DashBoard to perform the optimization of a target signal taken form the detectors as a function of one or more parameters controlled by the actuators.

Methods

ini_custom_attributes()

Here you can reimplement specific attributes

thread_status(status)

update_after_actuators_changed(actuators)

Actions to do after the actuators have been updated

update_prediction_function()

Get the selected prediction function options and pass them to the Runner

value_changed(param)

to be subclassed for actions to perform when one of the param's value in self.settings is changed

config_saver

runner

set_algorithm

validate_config

ini_custom_attributes()[source]

Here you can reimplement specific attributes

update_after_actuators_changed(actuators)[source]

Actions to do after the actuators have been updated

update_prediction_function()[source]

Get the selected prediction function options and pass them to the Runner

Should be reimplemented in real Optimizer implementation

value_changed(param)[source]

to be subclassed for actions to perform when one of the param’s value in self.settings is changed

For instance:

if param.name() == 'do_something':
    if param.value():
        print('Do something')
        self.settings.child('main_settings', 'something_done').setValue(False)
Parameters:

param (Parameter) – the parameter whose value just changed

8.2.2.2. The Base Models

The models are shared by all the optimizer extensions (see pymodaq.extensions.optimizers_base).

class pymodaq.extensions.optimizers_base.models.OptimizerModelGeneric(optimization_controller)[source]
Attributes:
optimization_algorithm

Methods

convert_input(measurements)

Convert the measurements in the units to be fed to the Optimisation Controller

convert_output(outputs[, best_individual])

Convert the output of the Optimisation Controller in units to be fed into the actuators :param outputs: output value from the controller from which the model extract a value of the same units as the actuators :type outputs: dict[str, Union[float, ndarray]] :param best_individual: the coordinates of the best individual so far :type best_individual: Optional[dict[str, float]]

has_fitness_observable()

Should return True if the model defined a 0D data to be used as fitness value

ini_model()

To be subclassed

runner_initialized()

To be subclassed

update_plots()

Called when updating the live plots

update_settings(param)

Get a parameter instance whose value has been modified by a user on the UI To be overwritten in child class

check_modules

ini_model_base

update_detector_names

convert_input(measurements)[source]

Convert the measurements in the units to be fed to the Optimisation Controller

Parameters:

measurements (DataToExport) – data object exported from the detectors from which the model extract a float value (fitness) to be fed to the algorithm

Return type:

float

convert_output(outputs, best_individual=None)[source]

Convert the output of the Optimisation Controller in units to be fed into the actuators :param outputs: output value from the controller from which the model extract a value of the same units as the actuators :type outputs: dict[str, Union[float, ndarray]] :param best_individual: the coordinates of the best individual so far :type best_individual: Optional[dict[str, float]]

Returns:

DataToActuatorOpti – attribute, either ‘rel’ for relative or ‘abs’ for absolute.

Return type:

DataToActuators

abstractmethod has_fitness_observable()[source]

Should return True if the model defined a 0D data to be used as fitness value

Return type:

bool

ini_model()[source]

To be subclassed

Initialize whatever is needed by your custom model

runner_initialized()[source]

To be subclassed

Initialize whatever is needed by your custom model after the optimization runner is initialized

update_plots()[source]

Called when updating the live plots

update_settings(param)[source]

Get a parameter instance whose value has been modified by a user on the UI To be overwritten in child class

class pymodaq.extensions.optimizers_base.models.OptimizerModelDefault(optimization_controller)[source]

Methods

convert_input(measurements)

Convert the measurements in the units to be fed to the Optimisation Controller

convert_output(outputs[, best_individual])

Convert the output of the Optimisation Controller in units to be fed into the actuators :param outputs: output value from the controller from which the model extract a value of the same units as the actuators :type outputs: dict[str, Union[float, ndarray]] :param best_individual: the coordinates of the best individual so far :type best_individual: Optional[dict[str, float]]

has_fitness_observable()

Should return True if the model defined a 0D data to be used as fitness value

ini_model()

update_settings(param)

optimize_from

convert_input(measurements)[source]

Convert the measurements in the units to be fed to the Optimisation Controller

Parameters:

measurements (DataToExport) – data object exported from the detectors from which the model extract a float value (fitness) to be fed to the algorithm

Return type:

float

convert_output(outputs, best_individual=None)[source]

Convert the output of the Optimisation Controller in units to be fed into the actuators :param outputs: output value from the controller from which the model extract a value of the same units as the actuators :type outputs: dict[str, Union[float, ndarray]] :param best_individual: the coordinates of the best individual so far :type best_individual: Optional[dict[str, float]]

Returns:

DataToActuatorOpti – attribute, either ‘rel’ for relative or ‘abs’ for absolute.

Return type:

DataToActuators

has_fitness_observable()[source]

Should return True if the model defined a 0D data to be used as fitness value

Return type:

bool