OptimizationMap#
- class OptimizationMap[source]#
Bases:
objectOptimization parameter map utility class.
Utility class that collects all parameters that shall be considered during optimization and associates them with the corresponding Optimizable interface. With this class, Quantities can be traced back to the Optimizable to which they belong. Before optimization, an instance of this class needs to be filled and passed to the optimizer.
Examples:
>>> from paraqeet import OptimizationMap >>> from paraqeet.signal.envelopes import ConstantEnvelope >>> envelope = ConstantEnvelope() >>> optmap = OptimizationMap() >>> optmap.add(envelope, [envelope.amplitude]) >>> len(optmap.get_all_parameters()) 1
Methods
__init__()add(optimizable[, optimizable_quantities])Add an optimizable object and a list of its quantities to the map.
append(optimizable[, optimizable_quantities])Append an optimizable object and a list of its quantities to the map.
filter_by_name(name)Filter parameters by name of parameter.
filter_parameters(filter_function)Filter parameters using filter function.
from_dict(data)Restore the values of all optimized quantities in the dictionary.
Return all parameters that were added to the system map.
Return all optimizable objects that were added to this map.
get_parameters(optimizable)Return all quantities associated with the given optimizable.
Register optimizable parameters with the system.
remove(optimizable[, params])Remove the given optimizable or parameter(s) from the optimization map.
remove_by_name(name)Remove parameters by name of parameter.
replace(optimizable, old_parameters, ...)Perform an in-place substitution of the old and new parameters.
to_dict()Create a dictionary representation of the optimization map.
- add(optimizable, optimizable_quantities=None)[source]#
Add an optimizable object and a list of its quantities to the map.
The list contains all parameters of the optimizable object that shall be considered during the optimization. If the list is empty, all parameters of the class will be used. If the object was already added, the list of quantities will be overwritten.
- Parameters:
optimizable (Optimizable) – Input Optimizable object for adding to the map.
optimizable_quantities (Quantity | list[Quantity] | None) – List of all parameters of the optimizable object considered for optimization.
- append(optimizable, optimizable_quantities=None)[source]#
Append an optimizable object and a list of its quantities to the map.
This method is similar to the
addmethod, but instead of overwriting the existing entries, this appends the specified list of quantities to the already existing quantities.- Parameters:
optimizable (Optimizable) – Input optimizable object for adding to the map.
optimizable_quantities (Quantity | list[Quantity] | None) – List of all parameters of the optimizable object considered for optimization.
- filter_by_name(name)[source]#
Filter parameters by name of parameter.
- Parameters:
name (str) – Name of parameter to be filtered with.
- filter_parameters(filter_function)[source]#
Filter parameters using filter function.
Updates the list of parameters for all Optimizables in this map using a filter function. Only parameters for which the filter function returns true will remain in this map.
- Parameters:
filter_function (Callable) – Filter function that maps quantities to boolean values.
- from_dict(data)[source]#
Restore the values of all optimized quantities in the dictionary.
The format of the dictionary needs to be in the same format as generated by the
to_dictfunction.- Parameters:
data (dict) – All quantities that should be restored.
- Raises:
SerializationException – If the dict contains an Optimizable or a Quantity that does not exist in this optimization map.
- get_optimizables()[source]#
Return all optimizable objects that were added to this map.
- Returns:
Set of all optimizable objects from the map.
- Return type:
- get_parameters(optimizable)[source]#
Return all quantities associated with the given optimizable.
- Parameters:
optimizable (Optimizable) – Input optimizable object.
- Returns:
List of parameters or None (if the optimizable has not been added yet).
- Return type:
- register_params_with_optimizables()[source]#
Register optimizable parameters with the system.
Utility function that synchronizes the list of parameters with each optimizable class. This needs to be called by the optimizer before gradient based optimization to tell the layers which gradients to compute.
- remove(optimizable, params=None)[source]#
Remove the given optimizable or parameter(s) from the optimization map.
If params is None, it removes the optimizable from the optimization map. Else it only removes the specific parameter from the optimization map.
- Parameters:
optimizable (Optimizable) – optimizable to be removed.
params (Quantity | list[Quantity] | None) – Parameter(s) to be removed from the optimization map. If None removes the optimizable.
- remove_by_name(name)[source]#
Remove parameters by name of parameter.
- Parameters:
name (str) – Name of parameter to be filtered with.
- replace(optimizable, old_parameters, new_parameters)[source]#
Perform an in-place substitution of the old and new parameters.
This helps to keep the ordering of parameters the same while replacing parameters.
- to_dict()[source]#
Create a dictionary representation of the optimization map.
Creates a dictionary that contains the values of all quantities that are being optimized, sorted by the Optimizable instances to which they belong. The returned dictionary is meant for export using the serialization package. It uses the names of Optimizables and Quantities and assumes that those are unique and not None. The format of the dict will be
"optimizable name": { "quantity name": { "unit": string, "shape": tuple[int, ...], "twoPi": bool, "value': Array, "min": Array, "max": Array } }
where the innermost part is generated by Quantity’s to_dict function.
- Returns:
All optimized quantities in an exportable format.
- Raises:
SerializationException – If the name of any Optimizable or Quantity is None or not unique.
- Return type: