flip.fitter
===========

.. py:module:: flip.fitter


Attributes
----------

.. autoapisummary::

   flip.fitter.log


Classes
-------

.. autoapisummary::

   flip.fitter.BaseFitter
   flip.fitter.FitMinuit
   flip.fitter.FitMCMC
   flip.fitter.Sampler
   flip.fitter.EMCEESampler


Module Contents
---------------

.. 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:attribute:: covariance
      :value: None



   .. py:attribute:: data
      :value: None



   .. 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:attribute:: likelihood
      :value: None



   .. py:attribute:: minuit
      :value: None



   .. 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_kind, 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_kind: 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:attribute:: sampler_name
      :value: 'emcee'



   .. py:attribute:: sampler
      :value: None



   .. py:method:: init_from_covariance(covariance, data, parameter_dict, likelihood_type='multivariate_gaussian', likelihood_properties={}, sampler_name='emcee', nwalkers=1, backend_file=None, **kwargs)
      :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:attribute:: likelihood


   .. py:attribute:: _p0
      :value: None



   .. 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:attribute:: backend
      :value: None



   .. 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.



