flip.fitter¶
Attributes¶
Classes¶
Helper class that provides a standard way to create an ABC using |
|
Class to maximize likelihood with Minuit. |
|
Class to create and run a MCMC sampler with emcee package. |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
Functions¶
|
The create_log function creates a logger object that can be used to log messages. |
Module Contents¶
- class flip.fitter.CovMatrix(model_name=None, model_type=None, los_definition=None, covariance_dict=None, full_matrix=False, number_densities=None, number_velocities=None, variant=None)[source]¶
- classmethod init_from_flip(model_name, model_type, power_spectrum_dict, coordinates_density=None, coordinates_velocity=None, additional_parameters_values=None, los_definition='bisector', variant=None, **kwargs)[source]¶
The init_from_flip function is a function that initializes the covariance matrix from the flip code. It takes as input:
model_name: name of the model used to generate the covariance matrix (e.g., ‘lai22’)
model_type: type of data used to generate the covariance matrix (e.g., ‘density’ or ‘velocity’)
- power_spectrum_dict: dictionary containing all information about power spectrum, including k and P(k) values, redshift, etc…
It is generated by calling getPowerSpectrumDict() in
- Parameters:
cls – Indicate that the function is a class method
model_name – Determine which model to use for the covariance matrix
model_type – Determine the type of model to be used
power_spectrum_dict – Pass the power spectrum of the model
coordinates_density – Specify the coordinates of the density field
coordinates_velocity – Define the velocity coordinates of the covariance matrix
additional_parameters_values – Pass the values of additional parameters to the flip code
**kwargs – Pass a variable number of keyword arguments to the function
- Returns:
A covariancematrix object
- classmethod init_from_generator(model_name, model_type, power_spectrum_dict, coordinates_velocity=None, coordinates_density=None, additional_parameters_values=None, variant=None, **kwargs)[source]¶
The init_from_generator function is a helper function that allows the user to initialize a Covariance object from a generator. The init_from_generator function takes in as arguments:
cls: the class of the object being initialized (Covariance)
model_name: name of covariance model used to generate covariance matrix (e.g., ‘lai22’)
model_type: type of covariance matrix generated (‘density’ or ‘velocity’)
- power spectrum dictionary containing keys for each redshift bin and values corresponding to
power spectra at those red
- Parameters:
cls – Refer to the class itself
model_name – Specify the type of model used to generate the covariance matrix
model_type – Determine which model to use
power_spectrum_dict – Pass the power spectrum to the generate_* functions
coordinates_velocity – Generate the velocity covariance matrix
coordinates_density – Generate the density field
additional_parameters_values – Pass additional parameters to the generator function
**kwargs – Pass a variable number of keyword arguments to the function
:param : Generate the covariance matrix from a given model
- Returns:
An object of the class covariancematrix
- property type¶
- The type function is used to determine the type of covariance model that will be computed.
- The options are:
- - velocity: The covariance model is computed for velocity only.
- - density: The covariance model is computed for density only.
- - density_velocity: The covariance model is computed for both velocity and density, without cross-term (i.e., the covariances between velocities and densities are zero). This option should be used when computing a full 3D tomography in which we want to compute a separate 1D tomography along each axis (x, y, z
- Parameters:
self – Represent the instance of the class
- Returns:
The type of the model
- property loaded¶
- The loaded function checks if the covariance matrix is loaded.
- Parameters:
self – Refer to the object itself
- Returns:
A boolean
- compute_covariance_sum(parameter_values_dict, vector_err)[source]¶
- The compute_covariance_sum function computes the sum of all covariance matrices
and adds the diagonal terms.
- Parameters:
self – Access the attributes of the class
parameter_values_dict – Pass the values of the parameters
:param : Compute the covariance matrix
- Returns:
The sum of the covariance matrices with their respective coefficients
- compute_full_matrix()[source]¶
The compute_full_matrix function takes the covariance matrix and fills in all of the missing values.
- Parameters:
self – Bind the method to the object
- Returns:
A dictionary with the full covariance matrices for each redshift bin
- write(filename, file_format)[source]¶
The write function writes the covariance matrix to a file.
- Parameters:
self – Represent the instance of the class
filename – Specify the name of the file to be written
:param : Specify the name of the file in which we want to save our covariance matrix
- Returns:
Nothing
- flip.fitter.create_log(log_level='info')[source]¶
The create_log function creates a logger object that can be used to log messages. The function takes one argument, the log_level, which is set to "info" by default. The function returns a Logger object with the specified logging level.
- Parameters:
log_level – Set the logging level
- Returns:
A logger object
- flip.fitter.log¶
- class flip.fitter.BaseFitter(covariance=None, data=None)[source]¶
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- 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
- class flip.fitter.FitMinuit(covariance=None, data=None, likelihood=None, minuit=None)[source]¶
Bases:
BaseFitterClass to maximize likelihood with Minuit.
- 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_type, 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_type – 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:
BaseFitterClass to create and run a MCMC sampler with emcee package.
- classmethod init_from_covariance(covariance, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties=None, sampler_name='emcee', nwalkers=1, backend_file=None)[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
- class flip.fitter.Sampler(likelihood, p0=None)[source]¶
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- property ndim¶
- property p0¶