GWForge.population_fisher.base

Base class for population models, and how their scores get computed.

Attributes

Classes

PopulationModel

Base class: a normalised density over event parameters, given hyper-parameters.

JointPopulationModel

Product of independent sub-models over disjoint event parameters.

Module Contents

GWForge.population_fisher.base.SCORE_METHODS = ('auto', 'analytic', 'finite-difference')[source]
GWForge.population_fisher.base.FD_RELATIVE_STEP = 0.0001[source]
GWForge.population_fisher.base.FD_ABSOLUTE_STEP = 1e-08[source]
class GWForge.population_fisher.base.PopulationModel[source]

Base class: a normalised density over event parameters, given hyper-parameters.

Variables:
  • parameter_names (list of str) – Hyper-parameter names, in the order the score columns come out.

  • fiducial (dict) – Default hyper-parameter values.

  • event_keys (list of str) – Keys the model requires in the events dict.

parameter_names = [][source]
fiducial[source]
event_keys = [][source]
abstractmethod log_prob(events, parameters)[source]

Log density of each event.

Parameters:
  • events (dict) – Arrays of event parameters, all the same length.

  • parameters (dict) – Hyper-parameter values; must cover parameter_names.

Returns:

Shape (n_events,). -inf outside the support.

Return type:

numpy.ndarray

analytic_score(events, parameters)[source]

Closed-form score, or None if this model has none.

Returns:

Shape (n_events, len(parameter_names)), columns in parameter_names order.

Return type:

numpy.ndarray or None

score(events, parameters=None, method='auto')[source]

Score of each event with respect to every hyper-parameter.

Parameters:
  • events (dict)

  • parameters (dict or None) – Defaults to fiducial.

  • method (str) – One of SCORE_METHODS. "auto" tries analytic, then falls back to finite differences.

Returns:

Shape (n_events, len(parameter_names)).

Return type:

numpy.ndarray

to_vector(parameters)[source]

Hyper-parameter dict to array, in parameter_names order.

from_vector(vector, parameters=None)[source]

Array back to a hyper-parameter dict, merged onto parameters.

check_events(events)[source]

Raise if events is missing a key this model needs.

class GWForge.population_fisher.base.JointPopulationModel(models)[source]

Bases: PopulationModel

Product of independent sub-models over disjoint event parameters.

models[source]
parameter_names = [][source]
event_keys = [][source]
property fiducial[source]

Sub-model fiducials, merged live.

log_prob(events, parameters)[source]

Sum of the sub-model log densities.

analytic_score(events, parameters)[source]

Horizontally stacked sub-model scores, None if any sub-model lacks one.

score(events, parameters=None, method='auto')[source]

Per-sub-model dispatch, so one analytic block is not lost to another’s fallback.