dingo.core.density package

Submodules

dingo.core.density.interpolation module

dingo.core.density.interpolation.interpolated_log_prob(sample_points, values, evaluation_point)

Given a distribution discretized on a grid, return a sample and the log prob from an interpolated distribution. Wraps the bilby.core.prior.Interped class.

Parameters:
  • sample_points (np.ndarray) – x values for samples

  • values (np.ndarray) – y values for samples. The distribution does not have to be initially normalized, although the final log_prob will be.

  • evaluation_point (float) – x value at which to evaluate log_prob.

Returns:

float

Return type:

log_prob

dingo.core.density.interpolation.interpolated_log_prob_multi(sample_points, values, evaluation_points, num_processes: int = 1)

Given a distribution discretized on a grid, the log prob at a specific point using an interpolated distribution. Wraps the bilby.core.prior.Interped class. Works with multiprocessing.

Parameters:
  • sample_points (np.ndarray, shape (N)) – x values for samples

  • values (np.ndarray, shape (B, N)) – y values for samples. The distributions do not have to be initially normalized, although the final log_probs will be. B = batch dimension.

  • evaluation_points (np.ndarray, shape (B)) – x values at which to evaluate log_prob.

  • num_processes (int) – Number of parallel processes to use.

Returns:

(np.ndarray, np.ndarray)

Return type:

sample and log_prob arrays, each of length B

dingo.core.density.interpolation.interpolated_sample_and_log_prob(sample_points, values)

Given a distribution discretized on a grid, return a sample and the log prob from an interpolated distribution. Wraps the bilby.core.prior.Interped class.

Parameters:
  • sample_points (np.ndarray) – x values for samples

  • values (np.ndarray) – y values for samples. The distribution does not have to be initially normalized, although the final log_prob will be.

Returns:

(float, float)

Return type:

sample and log_prob

dingo.core.density.interpolation.interpolated_sample_and_log_prob_multi(sample_points, values, num_processes: int = 1)

Given a distribution discretized on a grid, return a sample and the log prob from an interpolated distribution. Wraps the bilby.core.prior.Interped class. Works with multiprocessing.

Parameters:
  • sample_points (np.ndarray, shape (N)) – x values for samples

  • values (np.ndarray, shape (B, N)) – y values for samples. The distributions do not have to be initially normalized, although the final log_probs will be. B = batch dimension.

  • num_processes (int) – Number of parallel processes to use.

Returns:

(np.ndarray, np.ndarray)

Return type:

sample and log_prob arrays, each of length B

dingo.core.density.nde_settings module

Default settings for unconditional density estimation

dingo.core.density.nde_settings.get_default_nde_settings_3d(device='cpu', num_workers=0, inference_parameters=None)

dingo.core.density.unconditional_density_estimation module

class dingo.core.density.unconditional_density_estimation.SampleDataset(data)

Bases: Dataset

Dataset class for unconditional density estimation. This is required, since the training method of dingo.core.posterior_models.Base expects a tuple of (theta, *context) as output of the DataLoader, but here we have no context, so len(context) = 0. This SampleDataset therefore returns a tuple (theta, ) instead of just theta.

dingo.core.density.unconditional_density_estimation.parse_args()
dingo.core.density.unconditional_density_estimation.train_unconditional_density_estimator(result, settings: dict, train_dir: str)

Train unconditional density estimator for a given set of samples.

Parameters:
  • result (Result) – Contains the samples on which to train the density estimator.

  • settings (dict) – Dictionary containing the settings for the density estimator.

  • train_dir (str) – Path to the directory where the trained model should be saved.

Returns:

model – trained density estimator

Return type:

NormalizingFlowPosteriorModel

Module contents

This submodule contains tools for density estimation from samples. This is required for instance to recover the posterior density from GNPE samples, since the density is intractable with GNPE.