Models

class deepdiagnostics.models.model.Model(model_path)

Load a pre-trained model for analysis.

Parameters:

model_path (str) – relative path to a model.

class deepdiagnostics.models.SBIModel(model_path)

Load a trained model that was generated with Mackelab SBI [TCBD+20]. Read more about saving and loading requirements here.

Parameters:

model_path (str) – Relative path to a model - must be a .pkl file.

predict_posterior(data, context_samples)

Sample the posterior and then

Parameters:
  • data (deepdiagnostics.data.Data) – Data module with the loaded simulation

  • context_samples (np.ndarray) – X values to test the posterior over.

Returns:

Simulator output

Return type:

np.ndarray

sample_posterior(n_samples, x_true)

Sample the posterior

Parameters:
  • n_samples (int) – Number of samples to draw

  • x_true (np.ndarray) – Context samples. (must be dims=(n_samples, M))

Returns:

Posterior samples

Return type:

np.ndarray

static save_posterior(neural_posterior, path, allow_overwrite=False)

Save an SBI posterior to a pickle file.

Parameters:
  • neural_posterior (NeuralPosterior) – A neural posterior object. Must be an instance of the base class ‘NeuralPosterior’ from the sbi package.

  • path (str) – Relative path to a model - must be a .pkl file.

  • allow_overwrite (bool, optional) – Controls whether an attempt to overwrite succeeds or results in an error. Defaults to False.

Return type:

None