fisher_matrix#

class cosmicjellyfish.analysis.fisher_matrix.fisher_matrix(fisher_matrix=None, param_names=None, param_names_latex=None, fiducial=None, file_name=None, name='')[source]#

Bases: object

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.

get_fisher_matrix()[source]#
Returns:

the fisher matrix as a numpy array.

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_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_fiducial()[source]#
Returns:

the fiducial values of the parameters of the Fisher matrix.

get_param_names_fiducial_dict()[source]#
Returns:

a dictionary with parameter names as keys and fiducial values as values.

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

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

load_paramnames_from_file(file_name=None)[source]#

Loads the paramnames array from a file.

Parameters:

file_name (default: None) – (optional) file name and path of the parameter names file. If file_name is None this reads the file self.name+.paramnames.

save_paramnames_to_file(file_name=None)[source]#

Saves the paramnames to a file.

Parameters:

file_name (default: None) – (optional) file name and path of the parameter names file. If file_name is None this saves the file self.name+.paramnames.

save_to_file(file_name, simple_header=False, file_format='.txt')[source]#

Saves the fisher matrix to a file. Notice that the file name has to be specified to avoid overwriting an existing fisher matrix.

Parameters:

file_name – file name and path of the output fisher matrix. The file extension gets automatically added as is not needed.

inverse_fisher_matrix()[source]#

Invert the Fisher matrix.

Returns:

a matrix containing the inverse of the Fisher matrix.

Return type:

numpy.array

check_symmetric()[source]#

Assert if the Fisher matrix is symmetric or not :returns: a bool :rtype: bool

make_symmetric(method=None)[source]#

Transforms a non-symmetric matrix into a symmetric 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.

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

get_confidence_bounds(confidence_level=0.6827, marginal=True, 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

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.

translate_param_names(trans_param_dict)[source]#

Function substituting individual param names, effectively translating between names.

Parameters:

trans_param_dict (dict of string) – dict containing the equivalence between 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.

set_fiducial(fiducial)[source]#

Function sets a new fiducial substituting the old one.

Parameters:

fiducial – list containing the new fiducial.