cosmicfish_pylib.fisher_matrix

Module that contains the fisher_matrix class and the operations defined on it. The idea is that of creating a Fisher matrix safely, with all operations being well defined and safe-guarded once the input matrix is accepted as a Fisher matrix.

class cosmicfish_pylib.fisher_matrix.fisher_matrix(fisher_matrix=None, param_names=None, param_names_latex=None, fiducial=None, file_name=None)[source]

This class contains the relevant code to define a fisher matrix and basic operations on it.

Variables:
  • fisher_cutoff – cutoff for the spectrum of the Fisher matrix. Parameter of the class. Starts at 10**(-9) but, if needed, is fixed during computations.
  • fisher_spectrum – maximum condition number allowed for the Fisher matrix. Worse constrained modes that go above this value will be flattened to this value.
  • fisher_matrix – numpy array with the fisher matrix. Passed to the constructor of by file.
  • path – absolute path of the input Fisher matrix. Computed at initialization if passing a file or just an empty string.
  • name – name of the input Fisher matrix. Computed at initialization if passing a file or just an empty string.
  • indir – absoulte path of the directory of the input Fisher matrix. Computed at initialization if passing a file or just an empty string.
  • num_params – number of parameters of the input Fisher matrix. Computed at initialization.
  • fisher_eigenvalues – eigenvalues of the input Fisher matrix. Computed at initialization or by the PCA function.
  • fisher_eigenvectors – eigenvectors of the input Fisher matrix. Computed at initialization or by the PCA function.
  • fisher_matrix_inv – inverse of the input Fisher matrix. Computed at initialization or by inverse_fisher_matrix.
  • param_names – name of the parameters of the input Fisher matrix. Passed to the constructor of by file.
  • param_names_latex – LaTeX name of the parameters of the Fisher matrix. Passed to the constructor of by file.
  • param_fiducial – numpy array with the values of the fiducial parameters. Passed to the constructor of by file.
  • param_names_dict – a dictionary that maps parameter names to numbers and vice versa.
__add__(other)[source]

Addition operator (+). Safeguarded agains adding Fisher matrices with different parameters and different fiducials. The addition will add parameters with the same name and append parameters with different names. Notice that if a parameter is in one of the two Fisher matrices but not in the other it will be assumed independent from the other.

__eq__(other)[source]

Equality check operator (==). Ensures equality in all properties of the Fisher matrix. Notice that also name, path and indir are checked.

__ne__(other)[source]

Non-equality operator (!=). Simply implemented as the inverse of the equality operator.

fisher_matrix class constructor. The constructor will read from file the Fisher matrix if it is initialized with the name of a file (and the file exists). Otherwise it will read the matrix and the parameter names as passed by the user.

Parameters:
  • fisher_matrix (2D list or numpy.array) – array containing the input Fisher matrix. You can initialize a Fisher matrix passing a matrix or by filename.
  • param_names (list of string) – names of the parameters of the Fisher matrix. If initialized from file it will read them if a file file_name.paramnames is found. If a file is found and param_names are given to the constructor the latter will be used. If param_names is None when itialized from python it will just use some defaults names (p1, p2,...).
  • param_names_latex (list of string) – LaTeX names of the parameters of the Fisher matrix. If initialized from file it will read them if a file file_name.paramnames is found. If a file is found and param_names_latex are given to the constructor the latter will be used. If it is none when itialized from python it will just use some defaults names (p1, p2,...).
  • fiducial (list of float or numpy.array) – values of the fiducial parameters. If initialized from file it will have the value found in .paramnames. If not found on a file it will be zero. Passing it to the constructor overwrites the values.
  • file_name (string) – name of the file (and path) of the input Fisher matrix.
PCA()[source]

This function performs the principal component analysis of the Fisher matrix returning its eigenvalues and its eigenvectors. As of now it just works just as a wrapper for numpy.

Returns:a list with (eigenvalues, eigenvectors) as numpy.array.
Return type:list of numpy.array
determinant()[source]

This function returns the determinant of the Fisher matrix.

Returns:a float with the determinant of the Fisher matrix.
get_confidence_bounds(confidence_level=0.68, cache=False)[source]

Computes the marginal 1D confidence bounds on the Fisher parameters

Parameters:
  • confidence_level (float in [0,1]) – (optional) C.L. of the bounds. Default 68%.
  • cache (bool) – (optional) wether to use cached results or compute everything again
get_fiducial(name)[source]

Returns the fiducial of the parameter called name.

Parameters:name (string or a list of string) – input name or list of names of the parameters.
Returns:the fiducial or a list of fiducials corresponding to the parameter names.
Return type:float or a list of float.
get_fisher_eigenvalues()[source]
Returns:the eigenvalues of the Fisher matrix as a numpy array.
get_fisher_eigenvectors()[source]
Returns:the eigenvectors of the Fisher matrix.
get_fisher_inverse()[source]
Returns:the inverse of the Fisher matrix.
get_fisher_matrix()[source]
Returns:the fisher matrix as a numpy array.
get_param_fiducial()[source]
Returns:the fiducial values of the parameters of the Fisher matrix.
get_param_index(name)[source]

Returns the index of a parameter as specified by his name. Notice that indices starts at 0.

Parameters:name (string or a list of string) – input name or list of names of the parameters.
Returns:the index of the parameter or a list of numbers.
Return type:int or a list of int
get_param_name(number)[source]

Returns the name of the parameter corresponding to the given number.

Parameters:number (int or a list of int) – number of the parameter or list of numbers. Notice that parameters are numbered starting from 1.
Returns:the name or a list of names of the parameters.
Return type:string or a list of string.
get_param_name_latex(name)[source]

Returns the Latex name of the parameter called name.

Parameters:name (string or a list of string) – input name or list of names of the parameters.
Returns:the Latex name or a list of Latex names corresponding to the parameter names.
Return type:string or a list of string.
get_param_names()[source]
Returns:the parameter names of the Fisher matrix.
get_param_names_latex()[source]
Returns:the parameter names, in LaTeX format of the Fisher matrix.
get_param_number(name)[source]

Returns the number of a parameter as specified by his name. Notice this differs from get_param_index becasue number = index+1.

Parameters:name (string or a list of string) – input name or list of names of the parameters.
Returns:the index of the parameter or a list of numbers.
Return type:int or a list of int
inverse_fisher_matrix()[source]

Invert the Fisher matrix.

Returns:a matrix containing the inverse of the Fisher matrix.
Return type:numpy.array
load_paramnames_from_file(file_name=None)[source]

Loads the paramnames array from a file.

Parameters:file_name – (optional) file name and path of the parameter names file. If file_name is None this reads the file self.name+.paramnames.
protect_degenerate(cache=True)[source]

Protects the Fisher matrix against degeneracies. Modifies the spectrum to ensure that the absolute value of the eigenvalues is bounded. This will make the Fisher matrix strictly positive definite. It will modify the magnitude of the worst constrained parameter combinations without modifying the degeneracies directions.

Parameters:cache (bool) – (optional) wether to use cached results or compute everything again
set_fiducial(fiducial)[source]

Function sets a new fiducial substituting the old one.

Parameters:fiducial – list containing the new fiducial.
set_fisher_matrix(fisher_matrix)[source]

Function sets a new fisher matrix substituting the old one. Notice that this will reset parameter names, latex parameter names and fiducial values.

Parameters:fisher_matrix (numpy.array) – numpy.array containing the input Fisher matrix.
set_param_names(param_names)[source]

Function sets a new list of param names substituting the old one. Notice that latex parameter names will be reset.

Parameters:param_names (list of string) – list containing the new parameter names.
set_param_names_latex(param_names_latex)[source]

Function sets a new list of LaTeX param names substituting the old one.

Parameters:param_names_latex – list containing the new LaTeX parameter names.