Optimization Helpers

class aido.optimization_helpers.ContinuousParameter(parameter: SimulationParameter)[source]

Bases: Module

__init__(parameter: SimulationParameter)[source]

Initializes the optimization helper with the given parameters.

Parameters:
  • parameter (dict) – A parameter dict with the format given by

  • ‘modules/simulation_helpers.py – SimulationParameterDictionary’.

starting_value

The initial value as a tensor.

Type:

torch.Tensor

parameter

The parameter wrapped in a PyTorch Parameter object.

Type:

torch.nn.Parameter

min_value

The minimum allowable value.

Type:

float

max_value

The maximum allowable value.

Type:

float

boundaries

A tensor containing the min and max values.

Type:

torch.Tensor

sigma

The standard deviation for the parameter.

Type:

numpy.ndarray

_cost

The cost associated with the parameter.

Type:

float

forward() Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class aido.optimization_helpers.OneHotEncoder(parameter: SimulationParameter)[source]

Bases: Module

OneHotEncoder is a module that performs one-hot encoding on discrete values.

logits

A set of unnormalized, real-valued scores for each category. These logits represent the model’s confidence in each category prior to normalization. They can take any real value, including negatives, and are not probabilities themselves. Use the probabilities property to convert the logits to probabilities.

Type:

torch.Tensor

TODO Restrict the learning rate of the logits since they converge much faster than Continuous parameters.

__init__(parameter: SimulationParameter)[source]
Parameters:

parameter (dict) – A dictionary containing the parameter information.

property cost: Tensor

Costs associated to each entry

property current_value: Tensor

Returns the probability Tensor

forward() Tensor[source]

Passes the probabilities of each entry

property physical_value: Tensor

Returns the value of the highest scoring entry

property probabilities: Tensor

Probabilities for each entry

class aido.optimization_helpers.ParameterModule(parameter_dict: SimulationParameterDictionary)[source]

Bases: ModuleDict

adjust_covariance(direction: Tensor, min_scale: float = 2.0)[source]

Stretches the box_covariance of the generator in the directon specified as input. Direction is a vector in parameter space

property constraints: Tensor

A tensor of shape (P, 2) where P is the number of continuous parameters. In the second index, the order is the same as in the ContinuousParameter class (min, max)

forward() Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

items() Iterable[Tuple[str, OneHotEncoder | ContinuousParameter]][source]

Return an iterable of the ModuleDict key/value pairs.

values() Iterable[OneHotEncoder | ContinuousParameter][source]

Return an iterable of the ModuleDict values.