NuRadioReco.utilities.minimization module

class NuRadioReco.utilities.minimization.Minimizer(objective_function, parameters_initial, parameters_bounds, normalization=None, fixed=None, signal_function=None, save_history=False, debug=False)[source]

Bases: object

Class for radio signal reconstruction and general minimization tasks.

This class unifies the interfaces of different minimization algorithms like SciPy and Minuit. The class has two “modes”. If no signal_function is provided, it behaves like a standard minimizer, which minimizes an objective function with respect to its parameters. If a signal_function is provided, the class behaves like a minimizer specialized for fitting radio signals to traces. In this case, the signal_function should take the parameters as input and return the expected signal in a number of channels. This is then compared to data traces in the objective_function, which should take the data traces and the signal traces as input. When a minimization is run, the objective function is then minimized with respect to the parameters of the signal_function.

This class implements additional functionality, such as user-defined scaling of the parameters, which can improve the stability of the minimization process.

Parameters:
objective_functionfunction

If no signal_function is provided, this is a function which takes a number of parameters (as one numpy.ndarray) as input and returns the objective value to minimize, e.g., a minus two log likelihood or chi-square, i.e., objective_function(parameters). If a signal_function is provided, the objective_function takes the the output of the signal_function and the data as input and returns the objective value to minimize, i.e., objective_function(data, signal).

parameters_initialnumpy.ndarray

Values of parameters for initialization of the minimization with dimensions [n_parameters]

parameters_boundsnumpy.ndarray

Upper and lower bounds on parameters in the minimization. Should have dimensions [2,n_parameters]

signal_functionfunction (optional)

Function which takes a numpy array with parameter values as input (i.e., signal_function(parameters)) and returns a signal. The type and shape of the output depends on what happens in the user-defined objective_function, but it could be a numpy array with shape [n_antennas, n_samples] containing a radio signal in a number channels, or a list of channels.

normalizationnumpy.ndarray (optional)

Set normalization factors for the parameters before fitting. Each parameter is divided by this value internally, which can help with minimizer stability when parameters have different scales. This can, e.g., be set to the natural units of a problem (PeV, km, deg, …) or to the expected/estimated uncertainties on the parameters. Should be a numpy array with length n_parameters. If set to None, a normalization of 1 (i.e., no normalization will be used).

fixedlist(bool)

Wheter to fix some of the parameters in the optimization. Should be a list of bools with length n_parameters. If left as None, all parameters will be free in the optimization.

save_historybool (optional)

Whether to save the history of the parameters in the minimization process. This should only be used for debugging as it can create very large arrays and make the minimization slow.

debugbool (optional)

Whether to print debug information during the minimization process.

Methods

profile_scan_1D(method, i_parameter_scan, ...)

Perform minimization and a 1D profile (likelihood) scan around the minimum of the i_parameter_scan'th parameter by fixing it to different values on a grid and optimizing the objective function with respect to the other parameters.

profile_scan_2D(method, i_parameter_x, ...)

Perform minimization and a 2D profile (likelihood) scan around the minimum of the i_parameter_x'th and i_parameter_y'th parameters by fixing them to different values on a grid and optimizing the objective function with respect to the other parameters.

run_minimization(method[, data])

Run minimization algorithm for the objective function.

fix_parameters

fix_parameters(fixed)[source]
run_minimization(method, data=None, **method_kwargs)[source]

Run minimization algorithm for the objective function. If a signal_function is provided, a data array must be provided which the signal is fitted using the objective_function.

Parameters:
methodstr

Name of the method used to run the minimization

datanumpy.ndarray, any (optional)

Should only be provided if a signal_function is set. The type and shape depends on the objective_function, but it could be a numpy array with shape [n_antennas, n_samples] containing data traces to fit the signal to, or a list of channels.

profile_scan_1D(method, i_parameter_scan, parameter_grid_x, data=None, profile=True, true_value=None, plot=True, **method_kwargs)[source]

Perform minimization and a 1D profile (likelihood) scan around the minimum of the i_parameter_scan’th parameter by fixing it to different values on a grid and optimizing the objective function with respect to the other parameters.

profile_scan_2D(method, i_parameter_x, i_parameter_y, parameter_grid_x, parameter_grid_y, data=None, profile=True, true_values=None, plot=True, cmap='Blues_r', vmax=60, **method_kwargs)[source]

Perform minimization and a 2D profile (likelihood) scan around the minimum of the i_parameter_x’th and i_parameter_y’th parameters by fixing them to different values on a grid and optimizing the objective function with respect to the other parameters.