bilby.core.grid.Grid

class bilby.core.grid.Grid(likelihood=None, priors=None, grid_size=101, save=False, label='no_label', outdir='.', gzip=False)[source]

Bases: object

__init__(likelihood=None, priors=None, grid_size=101, save=False, label='no_label', outdir='.', gzip=False)[source]
Parameters:
likelihood: bilby.likelihood.Likelihood
priors: bilby.prior.PriorDict
grid_size: int, list, dict

Size of the grid, can be any of - int: all dimensions will have equal numbers of points - list: dimensions will use these points/this number of points in order of priors - dict: as for list

save: bool

Set whether to save the results of the grid

label: str

The label for the filename to which the grid is saved

outdir: str

The output directory to which the grid will be saved

gzip: bool

Set whether to gzip the output grid file

__call__(*args, **kwargs)

Call self as a function.

Methods

__init__([likelihood, priors, grid_size, ...])

Parameters:

marginalize(log_array[, parameters, ...])

Marginalize over a list of parameters.

marginalize_likelihood([parameters, ...])

Marginalize the likelihood over either the specified parameter or all but the specified "not_parameter".

marginalize_ln_likelihood([parameters, ...])

Marginalize the ln likelihood over either the specified parameter or all but the specified "not_parameter".

marginalize_ln_posterior([parameters, ...])

Marginalize the ln posterior over either the specified parameter or all but the specified "not_parameter".

marginalize_posterior([parameters, ...])

Marginalize the posterior over either the specified parameter or all but the specified "not_parameters".

read([filename, outdir, label, gzip])

Read in a saved .json grid file

save_to_file([filename, overwrite, outdir, gzip])

Writes the Grid to a file.

Attributes

ln_evidence

ln_likelihood

ln_posterior

ln_prior

log_evidence

log_noise_evidence

prior

marginalize(log_array, parameters=None, not_parameters=None)[source]

Marginalize over a list of parameters.

Parameters:
log_array: array_like

A numpy.ndarray of log likelihood/posterior values.

parameters: list, str

A list, or single string, of parameters to marginalize over. If None then all parameters will be marginalized over.

not_parameters: list, str

Instead of a list of parameters to marginalize over you can list the set of parameter to not marginalize over.

Returns:
out_array: array_like

An array containing the marginalized log likelihood/posterior.

marginalize_likelihood(parameters=None, not_parameters=None)[source]

Marginalize the likelihood over either the specified parameter or all but the specified “not_parameter”. If neither is specified the likelihood will be fully marginalized over.

Parameters:
parameters: str, list, optional

Name of, or list of names of, the parameter(s) to marginalize over.

not_parameters: str, optional

Name of, or list of names of, the parameter(s) to not marginalize over.

Returns:
array-like:

The marginalized likelihood.

marginalize_ln_likelihood(parameters=None, not_parameters=None)[source]

Marginalize the ln likelihood over either the specified parameter or all but the specified “not_parameter”. If neither is specified the ln likelihood will be fully marginalized over.

Parameters:
parameters: str, list, optional

Name of, or list of names of, the parameter(s) to marginalize over.

not_parameters: str, optional

Name of, or list of names of, the parameter(s) to not marginalize over.

Returns:
array-like:

The marginalized ln likelihood.

marginalize_ln_posterior(parameters=None, not_parameters=None)[source]

Marginalize the ln posterior over either the specified parameter or all but the specified “not_parameter”. If neither is specified the ln posterior will be fully marginalized over.

Parameters:
parameters: str, list, optional

Name of, or list of names of, the parameter(s) to marginalize over.

not_parameters: str, optional

Name of, or list of names of, the parameter(s) to not marginalize over.

Returns:
array-like:

The marginalized ln posterior.

marginalize_posterior(parameters=None, not_parameters=None)[source]

Marginalize the posterior over either the specified parameter or all but the specified “not_parameters”. If neither is specified the posterior will be fully marginalized over.

Parameters:
parameters: str, list, optional

Name of, or list of names of, the parameter(s) to marginalize over.

not_parameters: str, optional

Name of, or list of names of, the parameter(s) to not marginalize over.

Returns:
array-like:

The marginalized posterior.

classmethod read(filename=None, outdir=None, label=None, gzip=False)[source]

Read in a saved .json grid file

Parameters:
filename: str

If given, try to load from this filename

outdir, label: str

If given, use the default naming convention for saved results file

gzip: bool

If given, whether the file is gzipped or not (only required if the file is gzipped, but does not have the standard ‘.gz’ file extension)

Returns:
grid: bilby.core.grid.Grid
Raises:
ValueError: If no filename is given and either outdir or label is None

If no bilby.core.grid.Grid is found in the path

save_to_file(filename=None, overwrite=False, outdir=None, gzip=False)[source]

Writes the Grid to a file.

Parameters:
filename: str, optional

Filename to write to (overwrites the default)

overwrite: bool, optional

Whether or not to overwrite an existing result file. default=False

outdir: str, optional

Path to the outdir. Default is the one stored in the Grid object.

gzip: bool, optional

If true this will gzip the resulting file and add ‘.gz’ to the file extension.