Optimizer
- class nexus.Optimizer(measurements, id='', external_fit_variables=[], inequalities=None)
Constructor for the abstract
Optimizer
class. The optimizer is used to minimize a certain residual value. The actual implementation has to be provided by the user in python the following way.# A new python class is derived from the nexus Optimizer class. class DerivedOptimizerClass(nx.Optimizer): def __init__(self, measurements, id): super().__init__(measurements, id) # implementation of the residual def Residual(self): # here goes your code which calculates the residual to be minimized # it must depend on measurement class(es) object with fittable Var(s) ... residual = ... # the return value must be of type float return residual # Set up a optimization scenario # There must exist nx.Var object(s) that should be optimized optimization_parameter = nx.Var(..., fit = True) ... # There are measurement class object(s) defined which depend on the optimization parameter(s) measurement_type = nx.MeasurementClassType(...) # initialize a derived optimizer class object # pass a list with measurement objects on which the residual implementation Residual() depends my_optimizer = DerivedOptimizerClass(measurements = [measurement_type, ...], id = "optimizer id") # calculate the residual value if you want to check your code and print print(my_optimizer.Residual()) # run the optimizer to optimize all nx.Var object(s) on which the residual depends my_optimizer() # or my_optimizer.Evaluate()
You can also pass the negative of the value to maximize. For more information have a look to the tutorial.
- Parameters:
measurements (list) – List of
Measurement
objects used in the Optimizer.id (string) – User identifier.
external_fit_variables (list) –
List of
Var
objects. These Vars are not directly assigned to a Nexus object but can be related to an equality constraint on a Var. Nexus is not able to detect those automatically, so they have to provided manually.Added in version 1.1.0.
inequalities (
Inequality
) –An
Inequality
object. All inequalities constraints are handled by this object.Added in version 1.1.0.
- measurements
List of
Measurement
objects used in the Optimizer.- Type:
list
- id
User identifier.
- Type:
string
- external_fit_variables
List of
Var
objects. These Vars are not directly assigned to a Nexus object but can be related to an equality constraint on a Var. Nexus is not able to detect those automatically, so they have to provided manually.Added in version 1.1.0.
- Type:
list
- inequalities
An
Inequality
object. All inequalities constraints are handled by this object.Added in version 1.1.0.
- Type:
- options
Options that specify how the optimization is performed.
- Type:
- start_residual
The residual value at the beginning of optimization.
Added in version 1.1.0.
- Type:
float
- residual
The residual value to be optimized.
- Type:
float
- initial_parameters
List with initial values of the fit parameters.
- Type:
list
- lower_bounds
List with min values of the fit parameters.
- Type:
list
- upper_bounds
List with max values of the fit parameters.
- Type:
list
- ids
List with ids of the fit parameters.
- Type:
list
- Evaluate()
Evaluates the residual as implemented by the user. Also callable via operator
()
.
- Residual()
Call of the residual implementation function.
- Returns:
The residual value.
- Return type:
float