flip.fitter#

Attributes#

log

Classes#

BaseFitter

Helper class that provides a standard way to create an ABC using

FitMinuit

Class to maximize likelihood with Minuit.

FitMCMC

Class to create and run a MCMC sampler with emcee package.

Sampler

Helper class that provides a standard way to create an ABC using

EMCEESampler

Helper class that provides a standard way to create an ABC using

Module Contents#

flip.fitter.log#
class flip.fitter.BaseFitter(covariance=None, data=None)[source]#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

covariance = None#
data = None#
abstract init_from_covariance()[source]#
The init_from_covariance function is a class method that initializes the

fitter from the covariance matrix. It is here an abstract method that needs to be override

Parameters:

cls – Pass a class object into a method

abstract init_from_file()[source]#
The init_from_covariance function is a class method that initializes the

fitter from the a file containing covariance matrix. It is here an abstract method that needs to be override

Parameters:

cls – Pass a class object into a method

get_likelihood(parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties=None, **kwargs)[source]#

The get_likelihood function is used to create a likelihood object from the covariance matrix. The function takes in a dictionary of parameters, and returns an instance of the likelihood class.

Parameters:
  • self – Bind the method to a class

  • parameter_dict – Pass the parameters to be used in the likelihood function

  • likelihood_type – Select the likelihood class

:param : Select the likelihood function

Returns:

A likelihood object

static select_likelihood(likelihood_type)[source]#

The select_likelihood function takes in a string, likelihood_type, and returns the corresponding class.

Parameters:

likelihood_type – Determine which likelihood function to use

Returns:

The likelihood class

class flip.fitter.FitMinuit(covariance=None, data=None, likelihood=None, minuit=None)[source]#

Bases: BaseFitter

Class to maximize likelihood with Minuit.

likelihood = None#
minuit = None#
classmethod init_from_covariance(covariance, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties={}, **kwargs)[source]#

The init_from_covariance function is a class method that initializes the MinuitFitter object. It takes in the covariance matrix, data, parameter dictionary and likelihood type as arguments. The minuit_fitter object is initialized with the covariance matrix and data. The likelihood function is then calculated using get_likelihood() which returns an instance of LikelihoodFunction(). This instance is assigned to minuit_fitter’s attribute ‘likelihood’. The parameter values are extracted from the parameter dictionary and stored in a list called ‘parameter_values’. A Minuit object called ‘minuit’ is

Parameters:
  • cls – Create a new instance of the class

  • covariance – Initialize the covariance matrix of the likelihood

  • data – Pass the data to the likelihood function

  • parameter_dict – Pass the parameters to be fitted

  • likelihood_type – Specify the type of likelihood function to be used

:param : Set the covariance matrix of the data

Returns:

A minuit_fitter object

classmethod init_from_file(model_name, model_kind, filename, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties=None)[source]#

The init_from_file function is a class method that initializes the fitter object from a covariance matrix.

Parameters:
  • cls – Pass the class object to the function

  • model_name – Specify the name of the model

  • model_kind – Specify the type of model

  • filename – Load the covariance matrix from a file

  • data – Initialize the fitter’s data attribute

  • parameter_dict – Pass in the parameters that are used to

  • likelihood_type – Specify the type of likelihood function to use

:param : Specify the type of likelihood

Returns:

A fitter object

setup_minuit(parameter_dict)[source]#

The setup_minuit function is used to set up the minuit object. It takes a dictionary of parameters as input and sets the errors, fixed values, and limits for each parameter. The error is set to be equal to the value if no error is specified in the dictionary. If a parameter has been fixed then its error will be zero.

Parameters:
  • self – Refer to the object itself

  • parameter_dict – Set the initial values of the parameters

Returns:

A minuit object

run(migrad=True, hesse=False, minos=False, n_iter=1)[source]#

The run function is the main function of the class. It takes in a number of arguments, and then runs them through Minuit. The arguments are:

Parameters:
  • self – Bind the method to the object

  • migrad – Run the migrad algorithm

  • hesse – Run the hesse function

  • minos – Run the minos function, which is a

:param : Set the number of iterations for migrad

Returns:

A dictionary with the results of the minimization

class flip.fitter.FitMCMC(covariance=None, data=None, sampler_name='emcee')[source]#

Bases: BaseFitter

Class to create and run a MCMC sampler with emcee package.

sampler_name = 'emcee'#
sampler = None#
classmethod init_from_covariance(covariance, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties={}, sampler_name='emcee', nwalkers=1, backend_file=None, **kwargs)[source]#

The init_from_covariance function is a class method that initializes the MCMC fitter from a covariance matrix.

Parameters:
  • cls – Create a new instance of the class

  • covariance – Set the covariance matrix of the multivariate gaussian

  • data – Calculate the likelihood

  • parameter_dict – Pass in the parameters of the model

  • likelihood_type – Specify the type of likelihood function to use

:param : Set the covariance matrix

Returns:

A mcmc_fitter object

classmethod init_from_file()[source]#
Abstractmethod:

The init_from_covariance function is a class method that initializes the

fitter from the a file containing covariance matrix. It is here an abstract method that needs to be override

Parameters:

cls – Pass a class object into a method

set_sampler(likelihood, p0=None, **kwargs)[source]#
class flip.fitter.Sampler(likelihood, p0=None)[source]#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

likelihood#
_p0 = None#
abstract run_chains(nsteps)[source]#
property ndim#
property p0#
class flip.fitter.EMCEESampler(likelihood, p0=None, backend_file=None)[source]#

Bases: Sampler

Helper class that provides a standard way to create an ABC using inheritance.

backend = None#
run_chains(nsteps, number_worker=1, progress=False)[source]#
run_chains_untilconv(number_worker=1, maxstep=100, tau_conv=0.01, progress=False)[source]#

Run chains until reaching auto correlation convergence criteria.