mpcrl.optim.GradientFreeOptimizer#

class mpcrl.optim.GradientFreeOptimizer(max_percentage_update=inf)[source]#

Bases: BaseOptimizer, ABC

Base class for gradient-free optimization algorithms, e.g., Bayesian Optimization.

This optimizer adopts the ask-tell interface, i.e., it must implement the GradientFreeOptimizer.ask and GradientFreeOptimizer.tell methods. The former allows the agent to ask for a new set of parameters to evaluate, while the latter allows the agent to tell the optimizer the values of the objective function(s) for the set of parameters it asked for.

Methods

ask()

Asks the learning agent for a new set of parameters to evaluate.

set_learnable_parameters(pars)

Makes the optimization class aware of the dictionary of the learnable parameters whose values are to be updated.

tell(values, objective)

Tells the learning agent the values of the objective function for the set of parameters it asked for.

Attributes

prefers_dict

A flag that specifies whether the optimizer prefers to receive the learnable parameters as a dictionary of names and values or as a single concatenated array.

abstractmethod ask()[source]#

Asks the learning agent for a new set of parameters to evaluate.

Returns:
dict of (str, 1d arrays) or a single 1d array

A dictionary of learnable parameter names and their corresponding values. Or a single array that results from the concatenation of the parameter values.

str, optional (default=None)

A string that specifies the status of the optimizer. This is useful to communicate to the learning agent whether the optimization algorithm has encountered, e.g., some error or failure.

Return type:

tuple[Union[dict[str, Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str]]], Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str]], Optional[str]]

prefers_dict: bool#

A flag that specifies whether the optimizer prefers to receive the learnable parameters as a dictionary of names and values or as a single concatenated array.

set_learnable_parameters(pars)#

Makes the optimization class aware of the dictionary of the learnable parameters whose values are to be updated.

Parameters:
pars:class`mpcrl.LearnableParametersDict`

The dictionary of the learnable parameters.

Return type:

None

abstractmethod tell(values, objective)[source]#

Tells the learning agent the values of the objective function for the set of parameters it asked for.

Parameters:
valuesdict of (str, 1d arrays) or a single 1d array

A dictionary of learnable parameter names and their corresponding values for which the objective function(s) was (were) evaluated. Or a single array that results from the concatenation of the parameter values. This depends on the optimizer’s prefers_dict class attribute.

objectivefloat or array

Value(s) of the objective function(s) for the set of parameters. Can be single-objective or multi-objective.

Return type:

None

Examples using mpcrl.optim.GradientFreeOptimizer#

Bayesian Optimization for MPC Data-driven Tuning

Bayesian Optimization for MPC Data-driven Tuning