aspire.history#

Classes#

History

Base class for storing history of a sampler.

FlowHistory

Base class for storing history of a sampler.

SMCHistory

Base class for storing history of a sampler.

Module Contents#

class aspire.history.History[source]#

Base class for storing history of a sampler.

save(h5_file, path='history')[source]#

Save the history to an HDF5 file.

classmethod load(h5_file, path='history')[source]#

Load the history from an HDF5 file.

Parameters:
  • h5_file (h5py.File) – The open HDF5 file to load from.

  • path (str, optional) – The path within the HDF5 file to load the history from. Default is “history”.

class aspire.history.FlowHistory[source]#

Bases: History

Base class for storing history of a sampler.

training_loss: list[float] = [][source]#
validation_loss: list[float] = [][source]#
plot_loss()[source]#

Plot the training and validation loss.

Return type:

matplotlib.figure.Figure

save(h5_file, path='flow_history')[source]#

Save the history to an HDF5 file.

class aspire.history.SMCHistory[source]#

Bases: History

Base class for storing history of a sampler.

log_norm_ratio: list[float] = [][source]#
log_norm_ratio_var: list[float] = [][source]#
beta: list[float] = [][source]#
ess: list[float] = [][source]#
ess_target: list[float] = [][source]#
eff_target: list[float] = [][source]#
mcmc_autocorr: list[float] = [][source]#
mcmc_acceptance: list[float] = [][source]#
sample_history: list[aspire.samples.SMCSamples] = [][source]#
save(h5_file, path='smc_history')[source]#

Save the history to an HDF5 file.

The sample history is saved as a separate group under the main history group, with one subgroup per iteration. The number of iterations is stored in the main history group to allow for loading the sample history correctly.

Parameters:
  • h5_file (h5py.File) – The open HDF5 file to save to.

  • path (str, optional) – The path within the HDF5 file to save the history. Default is “smc_history”.

classmethod load(h5_file, path='smc_history')[source]#

Load the history from an HDF5 file.

Parameters:
  • h5_file (h5py.File) – The open HDF5 file to load from.

  • path (str, optional) – The path within the HDF5 file to load the history from. Default is “smc_history”.

Returns:

The loaded history instance.

Return type:

SMCHistory

plot_beta(ax=None)[source]#
Return type:

matplotlib.figure.Figure | None

plot_log_norm_ratio(ax=None)[source]#
Return type:

matplotlib.figure.Figure | None

plot_ess(ax=None)[source]#
Return type:

matplotlib.figure.Figure | None

plot_ess_target(ax=None)[source]#
Return type:

matplotlib.figure.Figure | None

plot_eff_target(ax=None)[source]#
Return type:

matplotlib.figure.Figure | None

plot_mcmc_acceptance(ax=None)[source]#
Return type:

matplotlib.figure.Figure | None

plot_mcmc_autocorr(ax=None)[source]#
Return type:

matplotlib.figure.Figure | None

plot(fig=None)[source]#
Parameters:

fig (matplotlib.figure.Figure | None)

Return type:

matplotlib.figure.Figure

plot_sample_history(n_samples=None, parameters=None, ax=None, cmap='viridis', scatter_kwargs=None, x_axis='log_p_t', iterations=None)[source]#

Plot the history of samples in the SMC sampler.

Parameters:
  • n_samples (int, optional) – Number of samples to plot from each iteration. If None, plot all samples.

  • parameters (list of str, optional) – List of parameter names to plot. If None, plot all parameters.

  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure and axes will be created.

  • cmap (str, optional) – Colormap to use for plotting the samples. Default is “viridis”.

  • scatter_kwargs (dict, optional) – Keyword arguments to pass to the scatter function. If None, no additional arguments will be passed

  • x_axis (str, optional) – Quantity to use for the x-axis. Supported values are "log_p_t" and "log_likelihood". Falls back to iteration index if required fields are missing.

  • iterations (list[int] | None)

Return type:

matplotlib.figure.Figure | None

plot_quantile_bands(parameters=None, quantile_interval=(0.1, 0.9), ax=None, line_kwargs=None, band_kwargs=None)[source]#

Plot per-parameter quantile bands vs iteration.

Parameters:
  • parameters (list[str] | None, optional) – Parameters to plot. If None, all parameters are used.

  • quantile_interval (tuple[float, float], optional) – Lower/upper quantiles to plot as a band.

  • ax (matplotlib.axes.Axes | list[matplotlib.axes.Axes] | None, optional) – Axes to draw on. If None, creates a new figure.

  • line_kwargs (dict | None, optional) – Keyword arguments for the median line.

  • band_kwargs (dict | None, optional) – Keyword arguments for the quantile band fill.

Return type:

matplotlib.figure.Figure | None