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:
objectThis 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_param_names_latex()[source]#
- Returns:
the parameter names, in LaTeX format 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.
- get_param_index(name)[source]#
Returns the index of a parameter as specified by his name. Notice that indices starts at 0.
- 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.
- 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
- 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.
- determinant()[source]#
This function returns the determinant of the Fisher matrix.
- Returns:
a
floatwith 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
- 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.arraycontaining 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 (
listofstring) – 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 (
dictofstring) – dict containing the equivalence between names