pyabc.visualization
Visualization
Visualize results of ABCSMC runs.
- pyabc.visualization.plot_acceptance_rates_trajectory(histories: List | History, labels: List | str = None, title: str = 'Acceptance rates', yscale: str = 'lin', size: tuple = None, colors: List[str] = None, normalize_by_ess: bool = False, ax: Axes = None) Axes [source]
Plot of acceptance rates over all iterations, i.e. one trajectory per history.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
title – Title for the plot.
yscale – The scale on which to plot the counts. Can be one of ‘lin’, ‘log’ (basis e) or ‘log10’
size – The size of the plot in inches.
colors – Colors to use for the trajectories. If None, then the matplotlib default values are used.
normalize_by_ess (bool, optional (default = False)) – Indicator to use effective sample size for the acceptance rate in place of the population size.
ax – Axis of the plot. If None, a new axis object is generated.
- Returns:
Axis of the generated plot.
- Return type:
ax
- pyabc.visualization.plot_acceptance_rates_trajectory_plotly(histories: List | History, labels: List | str = None, title: str = 'Acceptance rates', yscale: str = 'lin', size: tuple = None, colors: List[str] = None, normalize_by_ess: bool = False, fig: go.Figure = None) go.Figure [source]
Plot acceptance rates trajectories using plotly.
- pyabc.visualization.plot_contour_2d(history: History, x: str, y: str, m: int = 0, t: int = None, xmin: float = None, xmax: float = None, ymin: float = None, ymax: float = None, numx: int = 50, numy: int = 50, ax=None, size=None, title: str = None, refval=None, refval_color='C1', kde=None, xname: str = None, yname: str = None, show_clabel: bool = False, show_legend: bool = False, clabel_kwargs: dict = None, **kwargs)[source]
Plot 2d contour of parameter samples.
- Parameters:
history (History) – History to extract data from.
x (str) – The variable for the x-axis.
y (str) – The variable for the y-axis.
m (int, optional) – Id of the model to plot for.
t (int, optional) – Time point to plot for. Defaults to last time point.
xmin (float, optional) – The lower limit in x for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as x.
xmax (float, optional) – The upper limit in x for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as x.
ymin (float, optional) – The lower limit in y for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as y.
ymax (float, optional) – The upper limit in y for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as y.
numx (int, optional) – The number of bins in x direction.
int (numy) – The number of bins in y direction.
optional – The number of bins in y direction.
ax (matplotlib.axes.Axes, optional) – The axis object to use.
size (2-Tuple of float) – Size of the plot in inches.
title (str, optional) – Title for the plot. Defaults to None.
refval (dict, optional) – A reference parameter to be shown in the plots. Default: None.
refval_color (str, optional) – Color to use for the reference value.
kde (pyabc.Transition, optional) – The kernel density estimator to use for creating a smooth density from the sample. If None, a multivariate normal kde with cross-validated scaling is used.
xname – Parameter name for the x-axis.
xname – Parameter name for the y-axis.
show_clabel – Whether to show in-line contour labels.
show_legend – Whether to show line labels in form of a legend.
clabel_kwargs – Arguments to pass to matplotlib.contour.ContourLabeler.clabel. E.g.: “inline”, “inline_spacing”.
matplotlib.axes.Axes.contour. (Additional keyword arguments are passed to)
- Returns:
ax – Axis of the plot.
- Return type:
matplotlib axis
- pyabc.visualization.plot_contour_2d_lowlevel(df, w, x, y, xmin=None, xmax=None, ymin=None, ymax=None, numx=50, numy=50, ax=None, size=None, title: str = None, refval=None, refval_color='C1', kde=None, xname: str = None, yname: str = None, show_clabel: bool = False, show_legend: bool = False, clabel_kwargs: dict = None, **kwargs)[source]
Plot a 2d contour of parameter samples.
- Parameters:
df (Pandas Dataframe) – The rows are the observations, the columns the variables
w (The corresponding weights.)
parameters (For the other)
plot_contour_2d. (see)
- Returns:
ax – Axis of the plot.
- Return type:
matplotlib axis
- pyabc.visualization.plot_contour_matrix(history, m: int = 0, t: int = None, limits: dict = None, height: float = 2.5, numx: int = 50, numy: int = 50, refval: dict = None, refval_color='C1', kde=None, names: dict = None, show_clabel: bool = False, show_legend: bool = False, clabel_kwargs: dict = None, arr_ax=None, **kwargs)[source]
Plot a contour matrix for 1- and 2-dim marginals of the parameter samples.
- Parameters:
history (History) – History to extract data from.
m (int, optional) – Id of the model to plot for.
t (int, optional) – Time point to plot for. Defaults to last time point.
limits (dictionary, optional) – Dictionary of the form
{"name": (lower_limit, upper_limit)}
.height (float, optional) – Height of each subplot in inches. Default: 2.5.
numx (int, optional) – The number of bins in x direction. Defaults to 50.
numy (int, optional) – The number of bins in y direction. Defaults to 50.
refval (dict, optional) – A reference parameter to be shown in the plots (e.g. the underlying ground truth parameter used to simulate the data for testing purposes). Default: None.
refval_color (str, optional) – Color to use for the reference value.
kde (pyabc.Transition, optional) – The kernel density estimator to use for creating a smooth density from the sample. If None, a multivariate normal kde with cross-validated scaling is used.
names – Parameter names to use.
show_clabel – Whether to show in-line contour labels.
show_legend – Whether to show line labels in form of a legend.
clabel_kwargs – Arguments to pass to matplotlib.contour.ContourLabeler.clabel. E.g.: “inline”, “inline_spacing”.
arr_ax – Array of axes objects to use.
- Returns:
Array of the generated plots’ axes.
- Return type:
arr_ax
- pyabc.visualization.plot_contour_matrix_lowlevel(df: DataFrame, w: ndarray, limits: dict = None, height: int = 2.5, numx: int = 50, numy: int = 50, refval: dict = None, refval_color='C1', kde=None, names: dict = None, show_clabel: bool = False, show_legend: bool = False, clabel_kwargs: dict = None, arr_ax=None, **kwargs)[source]
Plot a contour matrix for 1- and 2-dim marginals of the parameter samples.
- Parameters:
df (Pandas Dataframe) – The rows are the observations, the columns the variables.
w (np.narray) – The corresponding weights.
parameters (Other)
- Returns:
Array of the generated plots’ axes.
- Return type:
arr_ax
- pyabc.visualization.plot_credible_intervals(history: History, m: int = 0, ts: List[int] | int = None, par_names: List = None, levels: List = None, colors: List = None, color_median: str = None, show_mean: bool = False, color_mean: str = None, show_kde_max: bool = False, color_kde_max: str = None, show_kde_max_1d: bool = False, color_kde_max_1d: str = None, size: tuple = None, refval: dict = None, refval_color: str = 'C1', kde: Transition = None, kde_1d: Transition = None, arr_ax: List[Axes] = None)[source]
Plot credible intervals over time.
- Parameters:
history – The history to extract data from.
m – The id of the model to plot for.
ts – The time points to plot for.
par_names – The parameter to plot for. If None, then all parameters are used.
levels – Confidence intervals to compute. Default is [0.95].
colors – Colors to use for the errorbars.
color_median – Color to use for the median line.
show_mean – Whether to show the mean apart from the median as well.
color_mean – Color to use for the mean.
show_kde_max – Whether to show the one of the sampled points that gives the highest KDE value for the specified KDE. Note: It is not attemtped to find the overall hightest KDE value, but rather the sampled point with the highest value is taken as an approximation (of the MAP-value).
color_kde_max – Color to use for KDE max value.
show_kde_max_1d – Same as show_kde_max, but here the KDE is applied component-wise.
color_kde_max_1d – Color to use for the KDE max value.
size – Size of the plot.
refval – A dictionary of reference parameter values to plot for each of par_names.
refval_color – Color to use for the reference value.
kde – The KDE to use for show_kde_max. Defaults to
pyabc.MultivariateNormalTransition
.kde_1d – The KDE to use for show_kde_max_1d. Defaults to
pyabc.MultivariateNormalTransition
.arr_ax – Array of axes to use. Assumed to be a 1-dimensional list.
- Returns:
arr_ax
- Return type:
Array of generated axes.
- pyabc.visualization.plot_credible_intervals_for_time(histories: List[History] | History, labels: List[str] | str = None, ms: List[int] | int = None, ts: List[int] | int = None, par_names: List[str] = None, levels: List[float] = None, show_mean: bool = False, show_kde_max: bool = False, show_kde_max_1d: bool = False, size: tuple = None, rotation: int = 0, refvals: List[dict] | dict = None, kde: Transition = None, kde_1d: Transition = None)[source]
Plot credible intervals over time.
- Parameters:
histories – The histories to extract data from.
labels – Labels for the histories. If None, they are just numbered.
ms – List of the ids of the models to plot for. Default is model id 0 for all histories.
ts – The time points to plot for, same length as histories. If None, the last times are taken.
par_names – The parameter to plot for. If None, then all parameters are used. Assumes all histories have these parameters.
levels – Confidence intervals to compute.
show_mean – As in plot_credible_intervals.
show_kde_max – As in plot_credible_intervals.
show_kde_max_1d – As in plot_credible_intervals.
size – Size of the plot.
refvals – A dictionary of reference parameter values to plot for each of par_names, for each history. Same length as histories.
kde – The KDE to use for show_kde_max.
kde_1d – The KDE to use for show_kde_max_1d.
- pyabc.visualization.plot_credible_intervals_plotly(history: History, m: int = 0, ts: List[int] | int = None, par_names: List = None, levels: List = None, colors=None, size: tuple = None, refval: dict = None, refval_color: str = 'gray', kde: Transition = None, kde_1d: Transition = None)[source]
Plot credible intervals over time using plotly.
- pyabc.visualization.plot_data_callback(history: History, f_plot: Callable = None, f_plot_aggregated: Callable = None, t: int = None, n_sample: int = None, ax: Axes = None, **kwargs)[source]
Plot the summary statistics from the history using callback functions to plot single statistics or aggregated values.
- Parameters:
history – The history object to use.
f_plot – Function to plot a single summary statistic. Takes the parameters
(sum_stat, weight, ax, **kwargs)
.f_plot_aggregated – Function to plot aggregated values on summary statistics. Takes the parameters
(sum_stats, weights, ax, **kwargs)
.t – Time point to extract data from the history for.
n_sample – Number of samples to plot. Defaults to all.
ax – Axis object for the plot. This object is not touched directly and can thus be also e.g. a list of axis objects.
functions. (Additional arguments are passed on to the plotting)
- Returns:
ax
- Return type:
Axis of the generated plot.
- pyabc.visualization.plot_data_default(obs_data: dict, sim_data: dict, keys: List[str] | str = None)[source]
Plot summary statistic data.
- Parameters:
obs_data (dict) – A dictionary for the summary statistic of the observed data, where keys represent the summary statistic name and values represent the data itself. The values can be represented as pandas dataframe, 1d numpy array, or 2d numpy array.
sim_data (dict) – A dictionary for the summary statistic of the simulated data, where keys represent the summary statistic name and values represent the data itself. The values can be represented as pandas dataframe, 1d numpy array, or 2d numpy array.
key (Union[List[str], str], optional) – Specific summary statistic keys to be used. If None, then all entries are used.
- Returns:
arr_ax
- Return type:
Axes of the generated plot.
- pyabc.visualization.plot_distance_weights(log_files: List[str] | str, ts: List[int] | List[str] | int | str = 'last', labels: List[str] | str = None, colors: List[Any] | Any = None, linestyles: List[str] | str = None, keys_as_labels: bool = True, keys: List[str] = None, xticklabel_rotation: float = 0, normalize: bool = True, size: Tuple[float, float] = None, xlabel: str = 'Summary statistic', ylabel: str = 'Weight', title: str = None, ax: Axes = None, **kwargs) Axes [source]
Plot distance weights, one curve per argument.
Assumes that the weights to be plotted from each file and timepoint have the same keys.
- Parameters:
log_files – The weight log files, as passed to the distance functions, e.g. as “scale_log_file” or “info_log_file”.
ts – Time points to plot. Defaults to the last entry in each file.
labels – A label for each log file.
colors – A color for each log file.
linestyles – Linestyles to apply.
keys_as_labels – Whether to use the summary statistic keys as x tick labels.
keys – Data keys to plot.
xticklabel_rotation – Angle by which to rotate x tick labels.
normalize – Whether to normalize the weights to sum 1.
size – Figure size in inches, (width, height).
xlabel – x-axis label.
ylabel – y-axis label.
title – Plot title.
ax – Axis object to use.
**kwargs – Additional keyword arguments are passed on to plt.plot() when plotting lines.
- Return type:
The used axis object.
- pyabc.visualization.plot_effective_sample_sizes(histories: List | History, labels: List | str = None, rotation: int = 0, title: str = 'Effective sample size', relative: bool = False, colors: List = None, size: tuple = None, ax: Axes = None) Axes [source]
Plot effective sample sizes over all iterations.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
rotation – Rotation to apply to the plot’s x tick labels. For longer labels, a tilting of 45 or even 90 can be preferable.
title – Title for the plot.
relative – Whether to show relative sizes (to 1) or w.r.t. the real number of particles.
colors – Colors to use for the lines. If None, then the matplotlib default values are used.
size – The size of the plot in inches.
ax – The matplotlib axes object to use. If None, a new figure is created.
- Returns:
The matplotlib axes object.
- Return type:
ax
- pyabc.visualization.plot_effective_sample_sizes_plotly(histories: List | History, labels: List | str = None, rotation: int = 0, title: str = 'Effective sample size', relative: bool = False, colors: List = None, size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot effective sample sizes using plotly.
- pyabc.visualization.plot_eps_walltime(histories: List[History] | History, labels: List | str = None, colors: List[Any] = None, group_by_label: bool = True, indicate_end: bool = True, unit: str = 's', xscale: str = 'linear', yscale: str = 'log', title: str = 'Epsilon over walltime', size: tuple = None, ax: Axes = None) Axes [source]
Plot epsilon values (y-axis) over the walltime (x-axis), iterating over the generations.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
colors – One color for each history.
group_by_label – Whether to group colors (unless explicitly provided) and legends by label.
indicate_end – Whether to indicate the final time by a line.
unit – Time unit to use (‘s’, ‘m’, ‘h’, ‘d’ as seconds, minutes, hours, days).
xscale – Scale of the x-axis. Use matplotlib’s notation.
yscale – Scale of the y-axis. Use matplotlib’s notation.
title – Title for the plot.
size (tuple of float, optional) – The size of the plot in inches.
ax (matplotlib.axes.Axes, optional) – The axis object to use.
- Return type:
A reference of the plot object.
- pyabc.visualization.plot_eps_walltime_lowlevel(end_times: List, eps: List, labels: List | str = None, colors: List[Any] = None, group_by_label: bool = True, indicate_end: bool = True, unit: str = 's', xscale: str = 'linear', yscale: str = 'log', title: str = 'Epsilon over walltime', size: tuple = None, ax: Axes = None) Axes [source]
Low-level access to plot_eps_walltime. Directly define end_times and eps. Note that both should be arrays of the same length and at the beginning include a value for the calibration iteration. This is just what pyabc.History.get_all_populations() returns. The first time is used as the base time differences to which are plotted. The first epsilon is ignored.
- pyabc.visualization.plot_eps_walltime_lowlevel_plotly(end_times: List, eps: List, labels: List | str = None, colors: List[Any] = None, group_by_label: bool = True, indicate_end: bool = True, unit: str = 's', xscale: str = 'linear', yscale: str = 'log', title: str = 'Epsilon over walltime', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot epsilon values over walltime using plotly.
- pyabc.visualization.plot_eps_walltime_plotly(histories: List[History] | History, labels: List | str = None, colors: List[Any] = None, group_by_label: bool = True, indicate_end: bool = True, unit: str = 's', xscale: str = 'linear', yscale: str = 'log', title: str = 'Epsilon over walltime', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot epsilon values over walltime using plotly.
- pyabc.visualization.plot_epsilons(histories: List | History, labels: List | str = None, colors: List = None, yscale: str = 'log', title: str = 'Epsilon values', size: tuple = None, ax: Axes = None) Axes [source]
Plot epsilon trajectory.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
colors – Colors to use for the lines. If None, then the matplotlib default values are used.
yscale – Scaling to apply to the y-axis. Use matplotlib’s notation.
title – Title for the plot.
size – The size of the plot in inches.
ax – The axis object to use. A new one is created if None.
- Returns:
The axis object used.
- Return type:
ax
- pyabc.visualization.plot_epsilons_plotly(histories: List | History, labels: List | str = None, colors: List = None, yscale: str = 'log', title: str = 'Epsilon values', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot epsilon trajectory using plotly.
- pyabc.visualization.plot_histogram_1d(history: History, x: str, m: int = 0, t: int = None, xmin=None, xmax=None, ax=None, size=None, refval=None, refval_color='C1', xname: str = None, **kwargs)[source]
Plot 1d histogram of parameter samples.
- Parameters:
history (History) – History to extract data from.
x (str) – Id of the parameter to plot for.
m (int, optional (default = 0)) – Id of the model to plot for.
t (int, optional (default = None, i.e. the last time)) – Time point to plot for.
xmin (float) – Bounds for x. Both must be specified for bounds to be applied.
xmax (float) – Bounds for x. Both must be specified for bounds to be applied.
ax (matplotlib.axes.Axes) – Axis object for the plot. If None is passed, a new figure is created.
size (2-Tuple of float, optional) – Size of the plot in inches.
refval (dict, optional (default = None)) – A reference value for x, to be highlighted in the plot.
refval_color (str, optional) – Color to use for the reference value.
xname – Parameter name for x. Defaults to x.
- Returns:
ax
- Return type:
Axis of the generated plot.
- pyabc.visualization.plot_histogram_1d_lowlevel(df: DataFrame, w: DataFrame, x: str, xmin=None, xmax=None, ax=None, size=None, refval=None, refval_color='C1', xname: str = None, **kwargs)[source]
Lowlevel interface for plot_histogram_1d (see there for the remaining parameters).
- Parameters:
df (pd.DataFrame) – Contains the parameters. Must have a column ‘x’.
w (pd.DataFrame) – Parameter weights.
- pyabc.visualization.plot_histogram_2d(history: History, x: str, y: str, m: int = 0, t: int = None, xmin=None, xmax=None, ymin=None, ymax=None, ax=None, size=None, refval=None, refval_color='C1', xname: str = None, yname: str = None, **kwargs)[source]
Plot 2d histogram of parameter pair samples.
- Parameters:
history (History) – History to extract data from.
x (str) – Ids of the parameters to plot for.
y (str) – Ids of the parameters to plot for.
m (int, optional (default = 0)) – Id of the model to plot for.
t (int, optional (default = None, i.e. the last time)) – Time point to plot for.
xmin (float) – Bounds for x and y. All must be specified for bounds to be applied.
xmax (float) – Bounds for x and y. All must be specified for bounds to be applied.
ymin (float) – Bounds for x and y. All must be specified for bounds to be applied.
ymax (float) – Bounds for x and y. All must be specified for bounds to be applied.
ax (matplotlib.axes.Axes) – Axis object for the plot. If None is passed, a new figure is created.
size (2-Tuple of float, optional) – Size of the plot in inches.
refval (dict, optional (default = None)) – Reference values for x and y, to be highlighted in the plot.
refval_color (str, optional) – Color to use for the reference value.
xname – Parameter name for x. Defaults to x.
yname – Parameter name for y. Defaults to y.
- Returns:
ax
- Return type:
Axis of the generated plot.
- pyabc.visualization.plot_histogram_2d_lowlevel(df: DataFrame, w: DataFrame, x, y, xmin=None, xmax=None, ymin=None, ymax=None, ax=None, size=None, refval=None, refval_color='C1', xname: str = None, yname: str = None, **kwargs)[source]
Lowlevel interface for plot_histogram_2d (see there for the remaining parameters).
- Parameters:
df (pd.DataFrame) – Contains the parameters. Must have a column ‘x’.
w (pd.DataFrame) – Parameter weights.
- pyabc.visualization.plot_histogram_matrix(history: History, m: int = 0, t: int = None, size=None, refval=None, refval_color='C1', names: dict = None, **kwargs)[source]
Plot matrix of 1d and 2d histograms over all parameters.
- Parameters:
history (History) – History to extract data from.
m (int, optional (default = 0)) – Id of the model to plot for.
t (int, optional (default = None, i.e. the last time)) – Time point to plot for.
size (2-Tuple of float, optional) – Size of the plot in inches.
refval (dict, optional (default = None)) – Reference parameter values, to be highlighted in the plot.
refval_color (str, optional) – Color to use for the reference value.
names – Parameter names to plot.
- Returns:
arr_ax – Axis objects of the generated plots.
- Return type:
list of matplotlib.axis.Axis
- pyabc.visualization.plot_histogram_matrix_lowlevel(df: DataFrame, w: DataFrame, size=None, refval=None, refval_color='C1', names: dict = None, **kwargs)[source]
Lowlevel interface for plot_histogram_matrix (see there for the remaining parameters).
- Parameters:
df (pd.DataFrame) – Contains the parameters. Must have a column ‘x’.
w (pd.DataFrame) – Parameter weights.
- pyabc.visualization.plot_kde_1d(df, w, x, xmin=None, xmax=None, numx=50, ax: Axes = None, size=None, title: str = None, refval=None, refval_color='C1', kde=None, xname: str = None, **kwargs) Axes [source]
Lowlevel interface for plot_kde_1d_highlevel (see there for the remaining parameters).
- Parameters:
df (pandas.DataFrame) – The rows are the observations, the columns the variables.
w (pandas.DataFrame) – The corresponding weights.
- Returns:
ax – Axis of the plot.
- Return type:
matplotlib axis
- pyabc.visualization.plot_kde_1d_highlevel(history: History, x: str, m: int = 0, t: int = None, xmin=None, xmax=None, numx=50, ax: Axes = None, size=None, title: str = None, refval=None, refval_color='C1', kde=None, xname: str = None, **kwargs) Axes [source]
Plot 1d kernel density estimate of parameter samples.
- Parameters:
history (History) – History to extract data from.
x (str) – The variable for the x-axis.
m (int, optional) – Id of the model to plot for.
t (int, optional) – Time point to plot for. Defaults to last time point.
xmin (float, optional) – The lower limit in x for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as x.
xmax (float, optional) – The upper limit in x for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as x.
numx (int, optional) – The number of bins in x direction. Defaults to 50.
ax (matplotlib.axes.Axes, optional) – The axis object to use.
size (2-Tuple of float, optional) – Size of the plot in inches.
title (str, optional) – Title for the plot. Defaults to None.
refval (dict, optional) – A reference value for x (as refval[x]: float). If not None, the value will be highlighted in the plot. Default: None.
refval_color (str, optional) – Color to use for the reference value.
kde (pyabc.Transition, optional) – The kernel density estimator to use for creating a smooth density from the sample. If None, a multivariate normal kde with cross-validated scaling is used.
xname – Parameter name. Defaults to x.
- Returns:
ax – axis of the plot
- Return type:
matplotlib axis
- pyabc.visualization.plot_kde_1d_plotly(df, w, x, xmin=None, xmax=None, numx=50, fig: go.Figure = None, row: int = 1, col: int = 1, size=None, title: str = None, refval=None, refval_color='gray', marker_color=None, kde=None, xname: str = None, **kwargs) go.Figure [source]
Plot 1d kde using plotly.
- pyabc.visualization.plot_kde_2d(df, w, x, y, xmin=None, xmax=None, ymin=None, ymax=None, numx=50, numy=50, ax: Axes = None, size=None, colorbar=True, title: str = None, refval=None, refval_color='C1', kde=None, xname: str = None, yname: str = None, **kwargs) Axes [source]
Plot a 2d kernel density estimate of parameter samples.
- Parameters:
df (Pandas Dataframe) – The rows are the observations, the columns the variables
w (The corresponding weights.)
parameters (For the other)
plot_kde_2d_highlevel. (see)
- Returns:
ax – Axis of the plot.
- Return type:
matplotlib axis
- pyabc.visualization.plot_kde_2d_highlevel(history: History, x: str, y: str, m: int = 0, t: int = None, xmin: float = None, xmax: float = None, ymin: float = None, ymax: float = None, numx: int = 50, numy: int = 50, ax: Axes = None, size=None, colorbar=True, title: str = None, refval=None, refval_color='C1', kde=None, xname: str = None, yname: str = None, **kwargs) Axes [source]
Plot 2d kernel density estimate of parameter samples.
- Parameters:
history (History) – History to extract data from.
x (str) – The variable for the x-axis.
y (str) – The variable for the y-axis.
m (int, optional) – Id of the model to plot for.
t (int, optional) – Time point to plot for. Defaults to last time point.
xmin (float, optional) – The lower limit in x for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as x.
xmax (float, optional) – The upper limit in x for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as x.
ymin (float, optional) – The lower limit in y for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as y.
ymax (float, optional) – The upper limit in y for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as y.
numx (int, optional) – The number of bins in x direction. Defaults to 50.
int (numy) – The number of bins in y direction. Defaults tp 50.
optional – The number of bins in y direction. Defaults tp 50.
ax (matplotlib.axes.Axes, optional) – The axis object to use.
size (2-Tuple of float) – Size of the plot in inches.
colorbar (bool, optional) – Whether to plot a colorbar. Defaults to True.
title (str, optional) – Title for the plot. Defaults to None.
refval (dict, optional) – A reference parameter to be shown in the plots. Default: None.
refval_color (str, optional) – Color to use for the reference value.
kde (pyabc.Transition, optional) – The kernel density estimator to use for creating a smooth density from the sample. If None, a multivariate normal kde with cross-validated scaling is used.
xname – Parameter name for the x-axis. Defaults to x.
xname – Parameter name for the y-axis. Defaults to y.
- Returns:
ax – Axis of the plot.
- Return type:
matplotlib axis
- pyabc.visualization.plot_kde_2d_highlevel_plotly(history: History, x: str, y: str, m: int = 0, t: int = None, xmin: float = None, xmax: float = None, ymin: float = None, ymax: float = None, numx: int = 50, numy: int = 50, fig: go.Figure = None, row: int = 1, col: int = 1, size=None, showscale=True, showlegend=True, title: str = None, refval=None, refval_color='gray', kde=None, xname: str = None, yname: str = None, **kwargs) go.Figure [source]
Plot 2d kernel density estimate of parameter samples using plotly.
- pyabc.visualization.plot_kde_2d_plotly(df, w, x, y, xmin=None, xmax=None, ymin=None, ymax=None, numx=50, numy=50, fig: go.Figure = None, row: int = 1, col: int = 1, size=None, showscale=True, showlegend=True, title: str = None, refval=None, refval_color='gray', kde=None, xname: str = None, yname: str = None, **kwargs)[source]
Plot a 2d kernel density estimate of parameter samples using plotly.
- pyabc.visualization.plot_kde_matrix(df, w, limits=None, colorbar=True, height=2.5, numx=50, numy=50, refval=None, refval_color='C1', kde=None, names: dict = None, arr_ax=None)[source]
Plot a KDE matrix for 1- and 2-dim marginals of the parameter samples.
- Parameters:
df (Pandas Dataframe) – The rows are the observations, the columns the variables.
w (np.narray) – The corresponding weights.
parameters (Other)
- Returns:
Array of the generated plots’ axes.
- Return type:
arr_ax
- pyabc.visualization.plot_kde_matrix_highlevel(history, m: int = 0, t: int = None, limits=None, colorbar: bool = True, height: float = 2.5, numx: int = 50, numy: int = 50, refval=None, refval_color='C1', kde=None, names: dict = None, arr_ax=None)[source]
Plot a KDE matrix for 1- and 2-dim marginals of the parameter samples.
- Parameters:
history (History) – History to extract data from.
m (int, optional) – Id of the model to plot for.
t (int, optional) – Time point to plot for. Defaults to last time point.
limits (dictionary, optional) – Dictionary of the form
{"name": (lower_limit, upper_limit)}
.colorbar (bool) – Whether to plot the colorbars or not.
height (float, optional) – Height of each subplot in inches. Default: 2.5.
numx (int, optional) – The number of bins in x direction. Defaults to 50.
numy (int, optional) – The number of bins in y direction. Defaults to 50.
refval (dict, optional) – A reference parameter to be shown in the plots (e.g. the underlying ground truth parameter used to simulate the data for testing purposes). Default: None.
refval_color (str, optional) – Color to use for the reference value.
kde (pyabc.Transition, optional) – The kernel density estimator to use for creating a smooth density from the sample. If None, a multivariate normal kde with cross-validated scaling is used.
names – Parameter names to use
arr_ax – Array of axes objects to use.
- Returns:
Array of the generated plots’ axes.
- Return type:
arr_ax
- pyabc.visualization.plot_kde_matrix_highlevel_plotly(history, m: int = 0, t: int = None, limits=None, height: float = 30, numx: int = 50, numy: int = 50, refval=None, refval_color='gray', marker_color=None, kde=None, names: dict = None, title: str = 'Univariate and bivariate distributions using KDE') go.Figure [source]
Plot a KDE matrix for 1- and 2-dim marginals of the parameter samples, using plotly.
- pyabc.visualization.plot_kde_matrix_plotly(df, w, limits=None, height=100, numx=50, numy=50, refval=None, refval_color='gray', marker_color=None, kde=None, names: dict = None, title: str = 'Univariate and bivariate distributions using KDE') go.Figure [source]
Plot a KDE matrix for 1- and 2-dim marginals of the parameter samples, using plotly.
- pyabc.visualization.plot_lookahead_acceptance_rates(sampler_df: DataFrame | str, t_min: int = 0, title: str = 'Acceptance rates', size: tuple = None, ax: Axes = None)[source]
Plot acceptance rates for look-ahead vs ordinary samples. The ratios are relative to all accepted particles, including eventually discarded ones.
- Parameters:
sampler_df – Dataframe or file as generated via RedisEvalParallelSampler(log_file=…).
t_min – The minimum generation to show. E.g. a value of 1 omits the first generation.
title – Plot title.
size – The size of the plot in inches.
ax – The axis object to use.
- Returns:
ax
- Return type:
Axis of the generated plot.
- pyabc.visualization.plot_lookahead_evaluations(sampler_df: DataFrame | str, relative: bool = False, fill: bool = False, alpha: float = None, t_min: int = 0, title: str = 'Total evaluations', size: tuple = None, ax: Axes = None)[source]
Plot total vs look-ahead evaluations over the generations.
- Parameters:
sampler_df – Dataframe or file as generated via RedisEvalParallelSampler(log_file=…).
relative – Whether to normalize the total evaluations for each generation to 1.
fill – If True, instead of lines, filled areas are drawn that sum up to the totals.
alpha – Alpha value for lines or areas.
t_min – The minimum generation to show. E.g. a value of 1 omits the first generation.
title – Plot title.
size – The size of the plot in inches.
ax – The axis object to use.
- Returns:
ax
- Return type:
Axis of the generated plot.
- pyabc.visualization.plot_lookahead_final_acceptance_fractions(sampler_df: DataFrame | str, population_sizes: ndarray | History, relative: bool = False, fill: bool = False, alpha: float = None, t_min: int = 0, title: str = 'Composition of final acceptances', size: tuple = None, ax: Axes = None)[source]
Plot fraction of look-ahead samples in final acceptances, over generations.
- Parameters:
sampler_df – Dataframe or file as generated via RedisEvalParallelSampler(log_file=…).
population_sizes – The sizes of the populations of accepted particles. If a History is passed, those values are extracted automatically, otherwise should be for the same time values as sampler_df.
relative – Whether to normalize the total evaluations for each generation to 1.
fill – If True, instead of lines, filled areas are drawn that sum up to the totals.
alpha – Alpha value for lines or areas.
t_min – The minimum generation to show. E.g. a value of 1 omits the first generation.
title – Plot title.
size – The size of the plot in inches.
ax – The axis object to use.
- Returns:
ax
- Return type:
Axis of the generated plot.
- pyabc.visualization.plot_model_probabilities(history: History, rotation: int = 0, title: str = 'Model probabilities', size: tuple = None, ax: Axes = None) Axes [source]
Plot the probabilities of models over time.
- Parameters:
history (History) – The history to extract data from.
rotation – Rotation of x axis labels.
title – Title of the plot.
size – Size of the figure.
ax – Matplotlib axes to plot on.
- Returns:
The matplotlib axes on which the plot was created.
- Return type:
ax
- pyabc.visualization.plot_model_probabilities_plotly(history: History, rotation: int = 0, title: str = 'Model probabilities', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot model probabilities using plotly.
- pyabc.visualization.plot_sample_numbers(histories: List[History] | History, labels: List[str] | str = None, rotation: int = 0, title: str = 'Required samples', size: Tuple[float, float] = None, ax: Axes = None) Axes [source]
Stacked bar plot of required numbers of samples over all iterations.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
rotation – Rotation to apply to the plot’s x tick labels. For longer labels, a tilting of 45 or even 90 can be preferable.
title – Title for the plot.
size – The size of the plot in inches.
ax – The matplotlib axes to plot on. If None, a new figure is created.
- Returns:
A reference to the axis object created.
- Return type:
ax
- pyabc.visualization.plot_sample_numbers_plotly(histories: List[History] | History, labels: List[str] | str = None, rotation: int = 0, title: str = 'Required samples', size: Tuple[float, float] = None, fig: go.Figure = None) go.Figure [source]
Plot sample numbers using plotly.
- pyabc.visualization.plot_sample_numbers_trajectory(histories: List | History, labels: List | str = None, title: str = 'Required samples', yscale: str = 'lin', size: tuple = None, ax: Axes = None) Axes [source]
Plot of required sample number over all iterations, i.e. one trajectory per history.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
title – Title for the plot.
yscale – The scale on which to plot the counts. Can be one of ‘lin’, ‘log’ (basis e) or ‘log10’
size – The size of the plot in inches.
ax – The matplotlib axes to plot on. If None, a new figure is created.
- Returns:
Axis of the generated plot.
- Return type:
ax
- pyabc.visualization.plot_sample_numbers_trajectory_plotly(histories: List | History, labels: List | str = None, title: str = 'Required samples', yscale: str = 'lin', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot sample number trajectories using plotly.
- pyabc.visualization.plot_sensitivity_sankey(info_sample_log_file: str, t: int | str, h: History, predictor: Predictor, par_trafo: ParTrafoBase = None, sumstat: Sumstat = None, subsetter: Subsetter = None, feature_normalization: str = 'mad', normalize_by_par: bool = True, fd_deltas: List[float] | float = None, scale_weights: Dict[int, ndarray] = None, title: str = 'Data-parameter sensitivities', width: float = None, height: float = None, sumstat_color: Callable[[str], str] = None, par_color: Callable[[str], str] = None, node_kwargs: dict = None, layout_kwargs: dict = None)[source]
Plot sensitivity matrix as a Sankey flow plot.
This visualization allows to analyze the parameter-data relationships, unraveling how informative data points are considered, and of which parameters.
We use plotly to generate this plot, which may need to be separately installed, e.g. via pip install plotly.
Customization of e.g. colors, to group by e.g. observable or parameter, is easily possible, however at the moment not implemented.
To store the generated figure, use e.g. fig.write_image({filename}.{format}).
- Parameters:
info_sample_log_file – Base of summary statistics, parameters, and weights files names containing samples used for model training, e.g. as generated via the info_sample_log_file argument of
pyabc.distance.InfoWeightedPNormDistance
.t – Time point at which the training was performed. Can also be an info_log_file, from which then the latest time is extracted.
h – History object. Required to extract observed data.
predictor – Predictor model.
par_trafo – Parameter transformations applied. Should be the same as applied for generation of the training sample.
sumstat – Summary statistic used on the raw model outputs. Defaults to identity.
subsetter – Subset generation method used. Defaults to identity.
feature_normalization – Feature normalization method, as in
pyabc.distance.InfoWeightedPNormDistance
.normalize_by_par – Whether to normalize sensitivities by parameter (transformation).
fd_deltas – Finite difference step sizes to evaluate.
scale_weights – Scale weights. Only needed if feature_normalization is “weights”.
title – Plot title.
width – Plot width.
height – Plot height.
sumstat_color – Callable assigning a color code for a given flattened summary statistic id.
par_color – Callable assigning a color code for a given parameter or parameter transformation id.
node_kwargs – Arguments for go.Sankey.nodes.
layout_kwargs – Arguments for fig.update_layout.
- Returns:
Generated figure.
- Return type:
fig
- pyabc.visualization.plot_total_sample_numbers(histories: List | History, labels: List | str = None, rotation: int = 0, title: str = 'Total required samples', yscale: str = 'lin', size: tuple = None, ax: Axes = None) Axes [source]
Bar plot of total required sample number over all iterations, i.e. a single-colored bar per history, in contrast to plot_sample_numbers, which visually distinguishes iterations.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
rotation – Rotation to apply to the plot’s x tick labels. For longer labels, a tilting of 45 or even 90 can be preferable.
title – Title for the plot.
yscale – The scale on which to plot the counts. Can be one of ‘lin’, ‘log’ (basis e) or ‘log10’
size – The size of the plot in inches.
ax – The matplotlib axes to plot on. If None, a new figure is created.
- Returns:
A reference to the axis object created.
- Return type:
ax
- pyabc.visualization.plot_total_sample_numbers_plotly(histories: List | History, labels: List | str = None, rotation: int = 0, title: str = 'Total required samples', yscale: str = 'lin', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot total sample numbers using plotly.
- pyabc.visualization.plot_total_walltime(histories: List[History] | History, labels: List | str = None, unit: str = 's', rotation: int = 0, title: str = 'Total walltimes', size: tuple = None, ax: Axes = None) Axes [source]
Plot total walltimes, for each history one single-color bar.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
unit – Time unit to use (‘s’, ‘m’, ‘h’, ‘d’ as seconds, minutes, hours, days).
rotation – Rotation to apply to the plot’s x tick labels. For longer labels, a tilting of 45 or even 90 can be preferable.
title – Title for the plot.
size (tuple of float, optional) – The size of the plot in inches.
- Return type:
A reference to the axis of the generated plot.
- pyabc.visualization.plot_total_walltime_plotly(histories: List[History] | History, labels: List | str = None, unit: str = 's', rotation: int = 0, title: str = 'Total walltimes', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot total walltimes using plotly.
- pyabc.visualization.plot_walltime(histories: List[History] | History, labels: List | str = None, show_calibration: bool = None, unit: str = 's', rotation: int = 0, title: str = 'Walltime by generation', size: tuple = None, ax: Axes = None) Axes [source]
Plot walltimes, with different colors indicating different iterations.
- Parameters:
histories – The histories to plot from. History ids must be set correctly.
labels – Labels corresponding to the histories. If None are provided, indices are used as labels.
show_calibration – Whether to show the calibration iteration (-1). Defaults to whether there are samples in the calibration iteration.
unit – Time unit to use (‘s’, ‘m’, ‘h’, ‘d’ as seconds, minutes, hours, days).
rotation – Rotation to apply to the plot’s x tick labels. For longer labels, a tilting of 45 or even 90 can be preferable.
title – Title for the plot.
size (tuple of float, optional) – The size of the plot in inches.
ax (matplotlib.axes.Axes, optional) – The axis object to use.
- Returns:
A reference to the axis of the generated plot.
- Return type:
ax
- pyabc.visualization.plot_walltime_lowlevel(end_times: List, start_times: List | None = None, labels: List | str = None, show_calibration: bool = None, unit: str = 's', rotation: int = 0, title: str = 'Walltime by generation', size: tuple = None, ax: Axes = None) Axes [source]
Low-level access to plot_walltime.
Directly define end_times and start_times.
- pyabc.visualization.plot_walltime_lowlevel_plotly(end_times: List, start_times: List | None = None, labels: List | str = None, show_calibration: bool = None, unit: str = 's', rotation: int = 0, title: str = 'Walltime by generation', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Low-level access to plot_walltime_plotly.
- pyabc.visualization.plot_walltime_plotly(histories: List[History] | History, labels: List | str = None, show_calibration: bool = None, unit: str = 's', rotation: int = 0, title: str = 'Walltime by generation', size: tuple = None, fig: go.Figure = None) go.Figure [source]
Plot walltimes using plotly.