optimpv.posterior package

Submodules

optimpv.posterior.approx_posterior module

optimpv.posterior.exploration_density module

Module containing classes and functions to visualize the exploration of the parameter space

optimpv.posterior.exploration_density.plot_density_exploration(params, optimizer=None, best_parameters=None, params_orig=None, optimizer_type='ax', **kwargs)[source]

Generate density plots to visualize the exploration of parameter space.

Parameters:
  • params (list of FitParam() objects) – List of parameters to explore.

  • optimizer (object, optional) – Optimizer object, by default None.

  • best_parameters (dict, optional) – Dictionary of the best parameters, by default None.

  • params_orig (dict, optional) – Dictionary of the original parameters, by default None.

  • optimizer_type (str, optional) – Type of optimizer used, by default ‘ax’.

  • **kwargs (dict) – Additional keyword arguments.

Returns:

  • matplotlib.figure.Figure – The figure object containing the plot.

  • matplotlib.axes._subplots.AxesSubplot – The axes object containing the plot.

Raises:

ValueError – If the optimizer type is not supported.

optimpv.posterior.lazy_posterior module

Module containing classes and functions for posterior analysis of parameters using the ML models from the BO optimization. This module provides functionality to visualize the posterior distributions of parameters using various plots, including 1D and 2D posteriors, devil’s plots, and density plots.

class optimpv.posterior.lazy_posterior.LazyPosterior(params, df, outcome_name, best_params=None, is_nat_scale=False, maximize=True, **kwargs)[source]

Bases: BaseAgent

compute_high_density_interval(param_name, credibility_level=0.95, num_points=1000)[source]

Compute the highest density interval (HDI) for a parameter.

Parameters:
  • param_name (str) – Name of the parameter

  • credibility_level (float, optional) – Credibility level for the HDI, by default 0.95

  • num_points (int, optional) – Number of points to evaluate the KDE, by default 1000

Returns:

  • hdi_lower (float) – Lower bound of the HDI

  • hdi_upper (float) – Upper bound of the HDI

compute_metrics(param_name, metric_name, credibility_level=0.95, num_points=100)[source]

Compute the mean, median, and HDI for a parameter.

Parameters:
  • param_name (str) – Name of the parameter

  • metric_name (str) – Metric to compute: ‘mean’, ‘median’, ‘hdi’, ‘max’, or ‘all’

  • credibility_level (float, optional) – Credibility level for the HDI, by default 0.95

  • num_points (int, optional) – Number of points to evaluate the KDE, by default 100

Returns:

  • mean (float) – Mean of the parameter distribution

  • median (float) – Median of the parameter distribution

  • hdi_lower (float) – Lower bound of the HDI

  • hdi_upper (float) – Upper bound of the HDI

  • max_value (float) – value at the maximum of the parameter distribution

get_best_params()[source]

Get the best parameter values from the true dataframe.

get_max_params()[source]

Get the parameter values at the maximum of the posterior for all free parameters.

get_mean_params()[source]

Get the mean parameter values for all free parameters.

get_median_params()[source]

Get the median parameter values for all free parameters.

get_top_n_best_params(num=10)[source]

Make x params list with the top x best parameters from the true dataframe.

get_top_n_metrics_params(metric_name, num=10)[source]

Get the parameter values computed from the top n best parameters from the true dataframe.

Parameters:
  • metric_name (str) – Metric to compute from the top n best parameters: ‘mean’, ‘median’, ‘max’, or ‘min’

  • num (int, optional) – Number of top best parameters to consider, by default 10

Returns:

List of parameter objects with values computed from the specified metric of the top n best parameters.

Return type:

list

Raises:

ValueError – if metric_name is not ‘mean’, ‘median’, ‘max’, or ‘min’

plot_all_lazyposterior(fig=None, axes=None, **kwargs)[source]

Plot the 1D and 2D posterior KDEs for all free parameters.

Parameters:
  • fig (matplotlib.figure.Figure, optional) – Matplotlib Figure object to plot on. If None, a new figure is created.

  • axes (numpy.ndarray of matplotlib.axes.Axes, optional) – Array of Matplotlib Axes objects to plot on. If None, new axes are created.

  • **kwargs (dict) – Additional keyword arguments passed to seaborn.kdeplot.

Returns:

  • fig (matplotlib.figure.Figure) – The figure object containing the plots.

  • axes (numpy.ndarray of matplotlib.axes.Axes) – The axes object containing the plots.

plot_lazyposterior_1D_kde(param_name, ax=None, **kwargs)[source]

Plot the 1D posterior KDE for a parameter.

Parameters:
  • param_name (str) – Name of the parameter

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

  • **kwargs (dict) –

    Additional keyword arguments passed to seaborn.kdeplot:
    • color: str, optional, default=’blue’

      Color of the KDE line.

    • fill: bool, optional, default=True

      Whether to fill the area under the KDE curve.

    • alpha: float, optional, default=0.5

      Transparency level for the filled area.

    • title: str, optional

      Title of the plot.

    • xlabel: str, optional

      Label for the x-axis.

plot_lazyposterior_2D_kde(x_param_name, y_param_name, ax=None, **kwargs)[source]

Plot the 2D posterior KDE for two parameters.

Parameters:
  • x_param_name (str) – Name of the first parameter

  • y_param_name (str) – Name of the second parameter

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

  • **kwargs (dict) –

    Additional keyword arguments passed to seaborn.kdeplot:
    • levels: int, optional, default=10

      Number of contour levels to draw.

    • cmap: str or Colormap, optional, default=’viridis’

      Colormap to use for the plot.

    • alpha: float, optional, default=0.7

      Transparency level for the filled contours.

    • title: str, optional

      Title of the plot.

    • xlabel: str, optional

      Label for the x-axis.

Module contents