threeML.minimizer package

Submodules

threeML.minimizer.ROOT_minimizer module

threeML.minimizer.grid_minimizer module

exception threeML.minimizer.grid_minimizer.AllFitFailed[source]

Bases: RuntimeError

class threeML.minimizer.grid_minimizer.GridMinimizer(function, parameters, verbosity=1)[source]

Bases: threeML.minimizer.minimization.GlobalMinimizer

add_callback(function)[source]

This adds a callback function which is called after each point in the grid has been used.

Parameters

function – a function receiving in input a tuple containing the point in the grid and the minimum of the

function reached starting from that point. The function should return nothing :return: none

add_parameter_to_grid(parameter, grid)[source]

Add a parameter to the grid

Parameters
  • parameter – an instance of a parameter or a parameter path

  • grid – a list (or a numpy.array) with the values the parameter is supposed to take during the grid search

Returns

None

remove_callbacks()[source]

Remove all callbacks added with add_callback

Returns

none

valid_setup_keys = ('grid', 'second_minimization', 'callbacks')

threeML.minimizer.minimization module

exception threeML.minimizer.minimization.BetterMinimumDuringProfiling[source]

Bases: RuntimeWarning

exception threeML.minimizer.minimization.CannotComputeCovariance[source]

Bases: RuntimeWarning

exception threeML.minimizer.minimization.CannotComputeErrors[source]

Bases: RuntimeWarning

exception threeML.minimizer.minimization.FitFailed[source]

Bases: Exception

class threeML.minimizer.minimization.FunctionWrapper(function, all_parameters, fixed_parameters)[source]

Bases: object

set_fixed_values(new_fixed_values)[source]
class threeML.minimizer.minimization.GlobalMinimization(minimizer_type)[source]

Bases: threeML.minimizer.minimization._Minimization

get_instance(*args, **kwargs)[source]
get_second_minimization_instance(*args, **kwargs)[source]
setup(**setup_dict)[source]
class threeML.minimizer.minimization.GlobalMinimizer(function, parameters, verbosity=1, setup_dict=None)[source]

Bases: threeML.minimizer.minimization.Minimizer

class threeML.minimizer.minimization.LocalMinimization(minimizer_type)[source]

Bases: threeML.minimizer.minimization._Minimization

get_instance(*args, **kwargs)[source]
class threeML.minimizer.minimization.LocalMinimizer(function, parameters, verbosity=1, setup_dict=None)[source]

Bases: threeML.minimizer.minimization.Minimizer

class threeML.minimizer.minimization.Minimizer(function, parameters, verbosity=1, setup_dict=None)[source]

Bases: object

property Npar
property algorithm_name
contours(param_1, param_1_minimum, param_1_maximum, param_1_n_steps, param_2=None, param_2_minimum=None, param_2_maximum=None, param_2_n_steps=None, progress=True, **options)[source]

Generate confidence contours for the given parameters by stepping for the given number of steps between the given boundaries. Call it specifying only source_1, param_1, param_1_minimum and param_1_maximum to generate the profile of the likelihood for parameter 1. Specify all parameters to obtain instead a 2d contour of param_1 vs param_2

Parameters
  • param_1 – name of the first parameter

  • param_1_minimum – lower bound for the range for the first parameter

  • param_1_maximum – upper bound for the range for the first parameter

  • param_1_n_steps – number of steps for the first parameter

  • param_2 – name of the second parameter

  • param_2_minimum – lower bound for the range for the second parameter

  • param_2_maximum – upper bound for the range for the second parameter

  • param_2_n_steps – number of steps for the second parameter

  • progress – (True or False) whether to display progress or not

  • log – by default the steps are taken linearly. With this optional parameter you can provide a tuple of

booleans which specify whether the steps are to be taken logarithmically. For example, ‘log=(True,False)’ specify that the steps for the first parameter are to be taken logarithmically, while they are linear for the second parameter. If you are generating the profile for only one parameter, you can specify

‘log=(True,)’ or ‘log=(False,)’ (optional)

Param

parallel: whether to use or not parallel computation (default:False)

Returns

a : an array corresponding to the steps for the first parameter b : an array corresponding to the steps for the second parameter (or None if stepping only in one direction) contour : a matrix of size param_1_steps x param_2_steps containing the value of the function at the corresponding points in the grid. If param_2_steps is None (only one parameter), then this reduces to an array of size param_1_steps.

property correlation_matrix
property covariance_matrix
property fit_results
property function
get_errors()[source]

Compute asymmetric errors using the profile likelihood method (slow, but accurate).

Returns

a dictionary with asymmetric errors for each parameter

minimize(compute_covar=True)[source]

Minimize objective function. This call _minimize, which is implemented by each subclass.

Parameters

compute_covar

Returns

best fit values (in external reference) and minimum of the objective function

property parameters
restore_best_fit()[source]

Reset all the parameters to their best fit value (from the last run fit)

Returns

none

set_algorithm(algorithm)[source]
property verbosity
exception threeML.minimizer.minimization.MinimizerNotAvailable[source]

Bases: Exception

exception threeML.minimizer.minimization.ParameterIsNotFree[source]

Bases: Exception

class threeML.minimizer.minimization.ProfileLikelihood(minimizer_instance, fixed_parameters)[source]

Bases: object

step(steps1, steps2=None)[source]
threeML.minimizer.minimization.get_minimizer(minimizer_type)[source]

Return the requested minimizer class (not instance)

Parameters

minimizer_type – MINUIT, ROOT, PYOPT…

Returns

the class (i.e., the type) for the requested minimizer

threeML.minimizer.minuit_minimizer module

exception threeML.minimizer.minuit_minimizer.MINOSFailed[source]

Bases: Exception

class threeML.minimizer.minuit_minimizer.MinuitMinimizer(function, parameters, verbosity=0, setup_dict=None)[source]

Bases: threeML.minimizer.minimization.LocalMinimizer

get_errors()[source]

Compute asymmetric errors using MINOS (slow, but accurate) and print them.

NOTE: this should be called immediately after the minimize() method

Returns

a dictionary containing the asymmetric errors for each parameter.

restore_best_fit()[source]

Set the parameters back to their best fit value

Returns

none

valid_setup_keys = ('ftol',)
threeML.minimizer.minuit_minimizer.add_method(self, method, name=None)[source]

threeML.minimizer.multinest_minimizer module

threeML.minimizer.pagmo_minimizer module

threeML.minimizer.scipy_minimizer module

class threeML.minimizer.scipy_minimizer.ScipyMinimizer(function, parameters, verbosity=10, setup_dict=None)[source]

Bases: threeML.minimizer.minimization.LocalMinimizer

valid_setup_keys = ('tol', 'algorithm')

threeML.minimizer.tutorial_material module

class threeML.minimizer.tutorial_material.Complex(**kwargs)[source]

Bases: threeML.minimizer.tutorial_material.Simple

description :

A convex log likelihood with multiple minima

latex : n.a.

parameters :

k :

desc : normalization initial value : 1.0 fix : yes

mu :

desc : parameter initial value : 5.0 min : 1.0 max : 100

evaluate(x, k, mu)[source]
static info()
class threeML.minimizer.tutorial_material.CustomLikelihoodLike(name)[source]

Bases: threeML.plugin_prototype.PluginPrototype

get_log_like()[source]

Return the value of the log-likelihood with the current values for the parameters

get_number_of_data_points()[source]

This returns the number of data points that are used to evaluate the likelihood. For binned measurements, this is the number of active bins used in the fit. For unbinned measurements, this would be the number of photons/particles that are evaluated on the likelihood

inner_fit()

Return the value of the log-likelihood with the current values for the parameters

set_minus_log_likelihood(likelihood_function)[source]
set_model(likelihood_model_instance)[source]

Set the model to be used in the joint minimization. Must be a LikelihoodModel instance.

class threeML.minimizer.tutorial_material.JointLikelihoodWrap(likelihood_model, data_list, verbose=False, record=True)[source]

Bases: threeML.classicMLE.joint_likelihood.JointLikelihood

fit(*args, **kwargs)[source]

Perform a fit of the current likelihood model on the datasets

Parameters

quiet – If True, print the results (default), otherwise do not print anything

:param compute_covariance:If True (default), compute and display the errors and the correlation matrix. :return: a dictionary with the results on the parameters, and the values of the likelihood at the minimum

for each dataset and the total one.

class threeML.minimizer.tutorial_material.Simple(**kwargs)[source]

Bases: astromodels.functions.function.Function1D

description :

A convex log likelihood

latex : n.a.

parameters :

k :

desc : normalization initial value : 1.0 fix : yes

mu :

desc : parameter initial value : 5.0 min : 1.0 max : 100

evaluate(x, k, mu)[source]
static info()
jump_tracking()[source]
reset_tracking()[source]
start_tracking()[source]
stop_tracking()[source]
threeML.minimizer.tutorial_material.get_callback(jl)[source]
threeML.minimizer.tutorial_material.get_joint_likelihood_object_complex_likelihood()[source]
threeML.minimizer.tutorial_material.get_joint_likelihood_object_simple_likelihood()[source]
threeML.minimizer.tutorial_material.plot_likelihood_function(jl, fig=None)[source]
threeML.minimizer.tutorial_material.plot_minimizer_path(jl, points=False)[source]
Parameters

jl (JointLikelihood) –

Returns

Module contents