CosmicFish_FisherAnalysis#

class cosmicjellyfish.analysis.fisher_plot_analysis.CosmicFish_FisherAnalysis(fisher_list=None, fisher_path=None, search_fisher_guess=False, with_derived=True)[source]#

Bases: object

This class takes care of handeling a set of Fisher matrices with plotting in mind. This class is meant to hold a list of Fisher matrices and have defined on this list a set of vectorized operations. For now no caching is implemented.

Variables:
  • fisher_list – list of Fisher matrices cosmicfish_pylib.fisher_matrix.fisher_matrix

  • fisher_name_list – list of names of the Fisher matrices. The names are used as the unique identifier of the Fisher matrix. No double name is enforced.

get_fisher_list()[source]#
Returns:

the list fisher matrices.

get_fisher_name_list()[source]#
Returns:

the list fisher matrices names. These are the unique identifiers of the list.

search_fisher_path(fisher_path, search_fisher_guess=False, with_derived=True)[source]#

Searches a path for fisher matrices. Will detect wether fisher_path contains directly the paths to the Fisher files or folder. If a list of folders is passed all the folders will be searched, first for Fisher matrices then for derived Fisher matrices.

Parameters:
  • fisher_path (string or list of string) – path or list of paths to search for Fisher matrices. If this contains Fisher matrices files those are imported as well.

  • search_fisher_guess (bool) – wether to guess the Fisher matrix name or not. Guessing assumes that the Fisher matrices have ‘fisher_matrix’ and ‘.dat’ in the name as happens with Fisher matrices produced with CosmicFish.

  • with_derived (bool) – wether to search for derived Fisher matrices to add to the base Fisher that are found.

add_fisher_matrix(fisher)[source]#

Add a set of Fisher matrices to the already existing set. Rejects Fisher matrices if the name is double i.e. the name is the unique identifier of the Fisher matrix. Checks wether the elements that are passed are really Fisher matrices.

Parameters:

fisher_list (cosmicfish_pylib.fisher_matrix.fisher_matrix or list of cosmicfish_pylib.fisher_matrix.fisher_matrix) – Fisher matrix or list of Fisher matrices.

get_fisher_matrix(names=None)[source]#

Returns the list of Fisher matrices corresponding to the given names.

Parameters:

names (a string or a list of string) – names of the Fisher matrices.

Returns:

a list containing the desired Fisher matrices. Notice if the name is not found in the list no error is risen and and the entrance is just ignored.

Return type:

a list of cosmicfish_pylib.fisher_matrix.fisher_matrix

delete_fisher_matrix(names=None)[source]#

Delete the fisher matrix or the fisher matrices in names from the Fisher list.

Parameters:

names (a string or a list of string) – names of the Fisher matrices to delete.

get_parameter_list(names=None)[source]#

Returns the list of parameter names of all the matrices identified in names.

Parameters:

names (a string or a list of string) – names of the Fisher matrices.

Returns:

a list containing the parameter names.

Return type:

a list of string

reshuffle(params, names=None, update_names=True)[source]#

Reshuffles all the Fisher matrices.

Parameters:
  • params (a string or a list of string) – parameters to reshuffle.

  • names (a string or a list of string) – names of the Fisher matrices.

Returns:

a new Fisher list with the reshuffled Fishers

Return type:

a cosmicfish_pylib.fisher_plot_analysis.CosmicFish_FisherAnalysis

marginalise(params, names=None, update_names=True)[source]#

Marginalise all the Fisher matrices over all the parameters that are not in params.

Parameters:
  • params (a string or a list of string) – list of names of the parameters of the output Fisher matrix, in the order that will appear in the output Fisher matrix. All other parameters will be marginalized over.

  • names (a string or a list of string) – names of the Fisher matrices.

Returns:

a new Fisher list with the reshuffled Fishers

Return type:

a cosmicfish_pylib.fisher_plot_analysis.CosmicFish_FisherAnalysis

get_parameter_latex_names(names=None)[source]#

Returns a dictionary mapping parameter names and latex parameter names.

Parameters:

names (a string or a list of string) – names of the Fisher matrices.

Returns:

a dictionary containing parameter names and the LaTeX parameter names.

Return type:

dict

compare_fisher_results(parstomarg=None, fisher_list=None, export_json_path=None, append=False, overwrite=False, extra_metadata=None)[source]#

Compare and print results from Fisher matrices.

This method analyzes each Fisher matrix in the list, calculating and printing various statistics including the Figure of Merit (FoM) and parameter constraints.

Parameters:
  • parstomarg (list of str, optional) – List of parameter names to marginalize over when computing the FoM. If None, the first two parameters of each Fisher matrix are used (independently per matrix).

  • fisher_list (list of FisherMatrix objects, optional) – List of Fisher matrices to analyze. If None, uses the instance’s fisher_list.

  • export_json_path (str, optional) – If provided, a JSON file with the collected statistics is written here.

  • append (bool, default False) – If True and export_json_path exists, merge/append current run results to the existing JSON (keyed by Fisher name, overwriting duplicates for that name only).

  • overwrite (bool, default False) – If True and export_json_path exists, the file is overwritten (takes precedence over append). Ignored if append=True.

  • extra_metadata (dict, optional) – Additional metadata to store at top-level of JSON output.

Notes

This method modifies the instance’s fisher_list if a new list is provided. Returns the structured results list (same objects written to JSON when requested).

Prints#

  • Fisher matrix name

  • Figure of Merit (FoM) for chosen marginalized parameters

  • Per-parameter: fiducial, 1-sigma error, percent error

JSON Schema (export_json_path)#

The JSON output has the following structure:

{
    "metadata": {
        "timestamp": "ISO-8601 str",
        "parstomarg_user_provided": true,
        "n_fishers": 3,
        ...extra_metadata
    },
    "results": [
        {
            "name": "FisherName",
            "FoM": {
                "parameters": ["p1", "p2", ...],
                "value": 123.45
            },
            "parameters": [
                {
                    "name": "param1",
                    "fiducial": 1.0,
                    "sigma": 0.1,
                    "percent_error": 10.0
                },
                ...
            ]
        },
        ...
    ]
}
compute_plot_range(params=None, confidence_level=0.6827, range_factors={'default': 1.0}, names=None, nice=True, dimensions=1)[source]#

Function that computes a meaningfull plot range for the plots involving the specified parameters and the specified Fisher names.

Parameters:
  • params (a string or a list of string) – name of the parameter or list of names of parameters.

  • confidence_level (float) – (optional) Confidence Level of the bounds. Default 68%.

  • names (a string or a list of string) – names of the Fisher matrices.

  • nice (bool) – wether the number is properly rounded to be nice.

Returns:

a dictionary of name and bounds

Return type:

dict

compute_gaussian(params=None, confidence_level=0.6827, names=None, num_points=100, normalized=False, nice_bounds=True)[source]#

Function that computes the (1D) gaussian distribution of a given parameter. Returns a dictionary with all the meaningul information about the gaussian.

Parameters:
  • params (a string or a list of string) – name of the parameter or list of names of parameters.

  • confidence_level (float) – (optional) Confidence Level of the bounds. Default 68%.

  • names (a string or a list of string) – names of the Fisher matrices.

  • num_points (int) – number of (x,y) points.

  • normalized (bool) – wether the distribution is normalized or not.

  • nice_bounds (bool) – wether the x range is properly rounded to be nice or not.

Returns:

a dictionary mapping name and parameter to a tuple of: [x, y, [fiducial,sigma]]

Return type:

dict

compute_ellipse(params1=None, params2=None, confidence_level=0.6827, names=None, num_points=100)[source]#

Function that computes the (2D) ellipses for a given parameters combination. Returns a dictionary with all the meaningul information about the ellipses.

Parameters:
  • params1 (a string or a list of string) – name of the first parameter or list of names of parameters.

  • params2 (default: None) – name of the second parameter or list of names of parameters.

  • confidence_level (float) – (optional) Confidence Level of the bounds. Default 68%.

  • names (a string or a list of string) – names of the Fisher matrices.

  • num_points (int) – number of (x,y) points.

Returns:

a dictionary mapping name and parameters to a tuple of: [x, y, [fiducial_x, fiducial_y, coeff_a, coeff_b, theta_0]]

Return type:

dict