flip.fitter =========== .. py:module:: flip.fitter Attributes ---------- .. autoapisummary:: flip.fitter.log Classes ------- .. autoapisummary:: flip.fitter.CovMatrix flip.fitter.BaseFitter flip.fitter.FitMinuit flip.fitter.FitMCMC flip.fitter.Sampler flip.fitter.EMCEESampler Functions --------- .. autoapisummary:: flip.fitter.create_log Module Contents --------------- .. py:class:: CovMatrix(model_name=None, model_type=None, los_definition=None, covariance_dict=None, full_matrix=False, number_densities=None, number_velocities=None, variant=None) .. py:method:: 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) :classmethod: 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 :param cls: Indicate that the function is a class method :param model_name: Determine which model to use for the covariance matrix :param model_type: Determine the type of model to be used :param power_spectrum_dict: Pass the power spectrum of the model :param coordinates_density: Specify the coordinates of the density field :param coordinates_velocity: Define the velocity coordinates of the covariance matrix :param additional_parameters_values: Pass the values of additional parameters to the flip code :param \*\*kwargs: Pass a variable number of keyword arguments to the function :returns: A covariancematrix object .. py:method:: init_from_generator(model_name, model_type, power_spectrum_dict, coordinates_velocity=None, coordinates_density=None, additional_parameters_values=None, variant=None, **kwargs) :classmethod: 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 :param cls: Refer to the class itself :param model_name: Specify the type of model used to generate the covariance matrix :param model_type: Determine which model to use :param power_spectrum_dict: Pass the power spectrum to the generate_* functions :param coordinates_velocity: Generate the velocity covariance matrix :param coordinates_density: Generate the density field :param additional_parameters_values: Pass additional parameters to the generator function :param \*\*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 .. py:method:: init_from_file(filename, file_format) :classmethod: .. py: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 :param self: Represent the instance of the class :returns: The type of the model .. py:property:: loaded The loaded function checks if the covariance matrix is loaded. :param self: Refer to the object itself :returns: A boolean .. py:method:: compute_covariance_sum(parameter_values_dict, vector_err) The compute_covariance_sum function computes the sum of all covariance matrices and adds the diagonal terms. :param self: Access the attributes of the class :param 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 .. py:method:: compute_covariance_sum_eigenvalues(parameter_values_dict, vector_err) .. py:method:: compute_full_matrix() The compute_full_matrix function takes the covariance matrix and fills in all of the missing values. :param self: Bind the method to the object :returns: A dictionary with the full covariance matrices for each redshift bin .. py:method:: write(filename, file_format) The write function writes the covariance matrix to a file. :param self: Represent the instance of the class :param 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 .. py:function:: create_log(log_level='info') 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. :param log_level: Set the logging level :returns: A logger object .. py:data:: log .. py:class:: BaseFitter(covariance=None, data=None) Bases: :py:obj:`abc.ABC` Helper class that provides a standard way to create an ABC using inheritance. .. py:method:: init_from_covariance() :abstractmethod: 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 :param cls: Pass a class object into a method .. py:method:: init_from_file() :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 :param cls: Pass a class object into a method .. py:method:: get_likelihood(parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties=None, **kwargs) 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. :param self: Bind the method to a class :param parameter_dict: Pass the parameters to be used in the likelihood function :param likelihood_type: Select the likelihood class :param : Select the likelihood function :returns: A likelihood object .. py:method:: select_likelihood(likelihood_type) :staticmethod: The select_likelihood function takes in a string, likelihood_type, and returns the corresponding class. :param likelihood_type: Determine which likelihood function to use :returns: The likelihood class .. py:class:: FitMinuit(covariance=None, data=None, likelihood=None, minuit=None) Bases: :py:obj:`BaseFitter` Class to maximize likelihood with Minuit. .. py:method:: init_from_covariance(covariance, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties={}, **kwargs) :classmethod: 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 :param cls: Create a new instance of the class :param covariance: Initialize the covariance matrix of the likelihood :param data: Pass the data to the likelihood function :param parameter_dict: Pass the parameters to be fitted :param likelihood_type: Specify the type of likelihood function to be used :param : Set the covariance matrix of the data :returns: A minuit_fitter object .. py:method:: init_from_file(model_name, model_type, filename, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties=None) :classmethod: The init_from_file function is a class method that initializes the fitter object from a covariance matrix. :param cls: Pass the class object to the function :param model_name: Specify the name of the model :param model_type: Specify the type of model :param filename: Load the covariance matrix from a file :param data: Initialize the fitter's data attribute :param parameter_dict: Pass in the parameters that are used to :param likelihood_type: Specify the type of likelihood function to use :param : Specify the type of likelihood :returns: A fitter object .. py:method:: setup_minuit(parameter_dict) 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. :param self: Refer to the object itself :param parameter_dict: Set the initial values of the parameters :returns: A minuit object .. py:method:: run(migrad=True, hesse=False, minos=False, n_iter=1) 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: :param self: Bind the method to the object :param migrad: Run the migrad algorithm :param hesse: Run the hesse function :param 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 .. py:class:: FitMCMC(covariance=None, data=None, sampler_name='emcee') Bases: :py:obj:`BaseFitter` Class to create and run a MCMC sampler with emcee package. .. py:method:: init_from_covariance(covariance, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties=None, sampler_name='emcee', nwalkers=1, backend_file=None) :classmethod: The init_from_covariance function is a class method that initializes the MCMC fitter from a covariance matrix. :param cls: Create a new instance of the class :param covariance: Set the covariance matrix of the multivariate gaussian :param data: Calculate the likelihood :param parameter_dict: Pass in the parameters of the model :param likelihood_type: Specify the type of likelihood function to use :param : Set the covariance matrix :returns: A mcmc_fitter object .. py:method:: init_from_file() :classmethod: :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 :param cls: Pass a class object into a method .. py:method:: set_sampler(likelihood, p0=None, **kwargs) .. py:class:: Sampler(likelihood, p0=None) Bases: :py:obj:`abc.ABC` Helper class that provides a standard way to create an ABC using inheritance. .. py:method:: run_chains(nsteps) :abstractmethod: .. py:property:: ndim .. py:property:: p0 .. py:class:: EMCEESampler(likelihood, p0=None, backend_file=None) Bases: :py:obj:`Sampler` Helper class that provides a standard way to create an ABC using inheritance. .. py:method:: run_chains(nsteps, number_worker=1, progress=False) .. py:method:: run_chains_untilconv(number_worker=1, maxstep=100, tau_conv=0.01, progress=False) Run chains until reaching auto correlation convergence criteria.