Visualize¶
pypesto comes with various visualization routines. To use these, import pypesto.visualize.
-
class
pypesto.visualize.
ReferencePoint
(reference=None, x=None, fval=None, color=None, legend=None)¶ Bases:
dict
Reference point for plotting. Should contain a parameter value and an objective function value, may alos contain a color and a legend.
Can be used like a dict.
-
x
¶ Reference parameters.
- Type
ndarray
-
fval
¶ Function value, fun(x), for reference parameters.
- Type
float
-
color
¶ Color which should be used for reference point.
- Type
RGBA, optional
-
auto_color
¶ flag indicating whether color for this reference point should be assigned automatically or whether it was assigned by user
- Type
boolean
-
legend
¶ legend text for reference point
- Type
str
-
__init__
(reference=None, x=None, fval=None, color=None, legend=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
pypesto.visualize.
assign_clustered_colors
(vals, balance_alpha=True, highlight_global=True)¶ Cluster and assign colors.
- Parameters
vals (numeric list or array) – List to be clustered and assigned colors.
balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
highlight_global (bool (optional)) – flag indicating whether global optimum should be highlighted
- Returns
colors – One for each element in ‘vals’.
- Return type
list of RGBA
-
pypesto.visualize.
assign_clusters
(vals)¶ Find clustering.
- Parameters
vals (numeric list or array) – List to be clustered.
- Returns
clust (numeric list) – Indicating the corresponding cluster of each element from ‘vals’.
clustsize (numeric list) – Size of clusters, length equals number of clusters.
-
pypesto.visualize.
assign_colors
(vals, colors=None, balance_alpha=True, highlight_global=True)¶ Assign colors or format user specified colors.
- Parameters
vals (numeric list or array) – List to be clustered and assigned colors.
colors (list, or RGBA, optional) – list of colors, or single color
balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
highlight_global (bool (optional)) – flag indicating whether global optimum should be highlighted
- Returns
colors – One for each element in ‘vals’.
- Return type
list of RGBA
-
pypesto.visualize.
create_references
(references=None, x=None, fval=None, color=None, legend=None) → List[pypesto.visualize.reference_points.ReferencePoint]¶ This function creates a list of reference point objects from user inputs
- Parameters
references (ReferencePoint or dict or list, optional) – Will be converted into a list of RefPoints
x (ndarray, optional) – Parameter vector which should be used for reference point
fval (float, optional) – Objective function value which should be used for reference point
color (RGBA, optional) – Color which should be used for reference point.
legend (str) – legend text for reference point
- Returns
colors – One for each element in ‘vals’.
- Return type
list of RGBA
-
pypesto.visualize.
delete_nan_inf
(fvals: numpy.ndarray, x: numpy.ndarray = None) → Tuple[numpy.ndarray, numpy.ndarray]¶ Delete nan and inf values in fvals. If parameters ‘x’ are passend, also the corresponding entries are deleted.
- Parameters
x – array of parameters
fvals – array of fval
- Returns
x (np.array) – array of parameters without nan or inf
fvals (np.array) – array of fval without nan or inf
-
pypesto.visualize.
optimizer_history
(results, ax=None, size=18.5, 10.5, trace_x='steps', trace_y='fval', scale_y='log10', offset_y=None, colors=None, y_limits=None, start_indices=None, reference=None, legends=None)¶ Plot history of optimizer. Can plot either the history of the cost function or of the gradient norm, over either the optimizer steps or the computation time.
- Parameters
results (pypesto.Result or list) – Optimization result obtained by ‘optimize.py’ or list of those
ax (matplotlib.Axes, optional) – Axes object to use.
size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
trace_x (str, optional) – What should be plotted on the x-axis? Possibilities: ‘time’, ‘steps’ Default: ‘steps’
trace_y (str, optional) – What should be plotted on the y-axis? Possibilities: ‘fval’, ‘gradnorm’, ‘stepsize’ Default: ‘fval’
scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
offset_y (float, optional) – Offset for the y-axis-values, as these are plotted on a log10-scale Will be computed automatically if necessary
colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
y_limits (float or ndarray, optional) – maximum value to be plotted on the y-axis, or y-limits
start_indices (list or int) – list of integers specifying the multistart to be plotted or int specifying up to which start index should be plotted
reference (list, optional) – List of reference points for optimization results, containing et least a function value fval
legends (list or str) – Labels for line plots, one label per result object
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
optimizer_history_lowlevel
(vals, scale_y='log10', colors=None, ax=None, size=18.5, 10.5, x_label='Optimizer steps', y_label='Objective value', legend_text=None)¶ Plot optimizer history using list of numpy arrays.
- Parameters
vals (list of numpy arrays) – list of 2xn-arrays (x_values and y_values of the trace)
scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
ax (matplotlib.Axes, optional) – Axes object to use.
size (tuple, optional) – see waterfall
x_label (str) – label for x-axis
y_label (str) – label for y-axis
legend_text (str) – Label for line plots
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
parameters
(results, ax=None, free_indices_only=True, lb=None, ub=None, size=None, reference=None, colors=None, legends=None, balance_alpha=True, start_indices=None)¶ Plot parameter values.
- Parameters
results (pypesto.Result or list) – Optimization result obtained by ‘optimize.py’ or list of those
ax (matplotlib.Axes, optional) – Axes object to use.
free_indices_only (bool, optional) – If True, only free parameters are shown. If False, also the fixed parameters are shown.
ub (lb,) – If not None, override result.problem.lb, problem.problem.ub. Dimension either result.problem.dim or result.problem.dim_full.
size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
reference (list, optional) – List of reference points for optimization results, containing et least a function value fval
colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
legends (list or str) – Labels for line plots, one label per result object
balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
start_indices (list or int) – list of integers specifying the multistarts to be plotted or int specifying up to which start index should be plotted
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
parameters_lowlevel
(xs, fvals, lb=None, ub=None, x_labels=None, ax=None, size=None, colors=None, linestyle='-', legend_text=None, balance_alpha=True)¶ Plot parameters plot using list of parameters.
- Parameters
xs (nested list or array) – Including optimized parameters for each startpoint. Shape: (n_starts, dim).
fvals (numeric list or array) – Function values. Needed to assign cluster colors.
ub (lb,) – The lower and upper bounds.
x_labels (array_like of str, optional) – Labels to be used for the parameters.
ax (matplotlib.Axes, optional) – Axes object to use.
size (tuple, optional) – see parameters
colors (list of RGBA) – One for each element in ‘fvals’.
linestyle (str, optional) – linestyle argument for parameter plot
legend_text (str) – Label for line plots
balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
process_offset_y
(offset_y: Optional[float], scale_y: str, min_val: float) → float¶ compute offset for y-axis, depend on user settings
- Parameters
offset_y – value for offsetting the later plotted values, in order to ensure positivity if a semilog-plot is used
scale_y – Can be ‘lin’ or ‘log10’, specifying whether values should be plotted on linear or on log10-scale
min_val – Smallest value to be plotted
- Returns
offset_y – value for offsetting the later plotted values, in order to ensure positivity if a semilog-plot is used
- Return type
float
-
pypesto.visualize.
process_result_list
(results, colors=None, legends=None)¶ assigns colors and legends to a list of results, check user provided lists
- Parameters
results (list or pypesto.Result) – list of pypesto.Result objects or a single pypesto.Result
colors (list, optional) – list of RGBA colors
legends (str or list) – labels for line plots
- Returns
results (list of pypesto.Result) – list of pypesto.Result objects
colors (list of RGBA) – One for each element in ‘results’.
legends (list of str) – labels for line plots
-
pypesto.visualize.
process_y_limits
(ax, y_limits)¶ apply user specified limits of y-axis
- Parameters
ax (matplotlib.Axes, optional) – Axes object to use.
y_limits (ndarray) – y_limits, minimum and maximum, for current axes object
min_val (float) – Smallest value to be plotted
- Returns
ax – Axes object to use.
- Return type
matplotlib.Axes, optional
-
pypesto.visualize.
profile_cis
(result: pypesto.result.Result, confidence_level: float = 0.95, profile_indices: Sequence[int] = None, profile_list: int = 0, color: Union[str, tuple] = 'C0', show_bounds: bool = False, ax: matplotlib.axes._axes.Axes = None) → matplotlib.axes._axes.Axes¶ Plot approximate confidence intervals based on profiles.
- Parameters
result – The result object after profiling.
confidence_level – The confidence level in (0,1), which is translated to an approximate threshold assuming a chi2 distribution, using pypesto.profile.chi2_quantile_to_ratio.
profile_indices – List of integer values specifying which profiles should be plotted. Defaults to the indices for which profiles were generated in profile list profile_list.
profile_list – Index of the profile list to be used.
color – Main plot color.
show_bounds – Whether to show, and extend the plot to, the lower and upper bounds.
ax – Axes object to use. Default: Create a new one.
-
pypesto.visualize.
profile_lowlevel
(fvals, ax=None, size: Tuple[float, float] = 18.5, 6.5, color=None, legend_text: str = None, show_bounds: bool = False, lb: float = None, ub: float = None)¶ Lowlevel routine for plotting one profile, working with a numpy array only
- Parameters
fvals (numeric list or array) – Values to plot.
ax (matplotlib.Axes, optional) – Axes object to use.
size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified.
color (RGBA, optional) – Color for profiles in plot.
legend_text (str) – Label for line plots.
show_bounds – Whether to show, and extend the plot to, the lower and upper bounds.
lb – Lower bound.
ub – Upper bound.
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
profiles
(results: Union[pypesto.result.Result, Sequence[pypesto.result.Result]], ax=None, profile_indices: Sequence[int] = None, size: Sequence[float] = 18.5, 6.5, reference: Union[pypesto.visualize.reference_points.ReferencePoint, Sequence[pypesto.visualize.reference_points.ReferencePoint]] = None, colors=None, legends: Sequence[str] = None, x_labels: Sequence[str] = None, profile_list_ids: Union[int, Sequence[int]] = 0, ratio_min: float = 0.0, show_bounds: bool = False)¶ Plot classical 1D profile plot (using the posterior, e.g. Gaussian like profile)
- Parameters
results (list or pypesto.Result) – List of or single pypesto.Result after profiling.
ax (list of matplotlib.Axes, optional) – List of axes objects to use.
profile_indices (list of integer values) – List of integer values specifying which profiles should be plotted.
size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified.
reference (list, optional) – List of reference points for optimization results, containing at least a function value fval.
colors (list, or RGBA, optional) – List of colors, or single color.
legends (list or str, optional) – Labels for line plots, one label per result object.
x_labels (list of str) – Labels for parameter value axes (e.g. parameter names).
profile_list_ids (int or list of ints, optional) – Index or list of indices of the profile lists to be used for profiling.
ratio_min – Minimum ratio below which to cut off.
show_bounds – Whether to show, and extend the plot to, the lower and upper bounds.
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
profiles_lowlevel
(fvals, ax=None, size: Tuple[float, float] = 18.5, 6.5, color=None, legend_text: str = None, x_labels=None, show_bounds: bool = False, lb_full=None, ub_full=None)¶ Lowlevel routine for profile plotting, working with a list of arrays only, opening different axes objects in case
- Parameters
fvals (numeric list or array) – Values to plot.
ax (list of matplotlib.Axes, optional) – List of axes object to use.
size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified.
size – Figure size (width, height) in inches. Is only applied when no ax object is specified.
color (RGBA, optional) – Color for profiles in plot.
legend_text (List[str]) – Label for line plots.
legend_text – Label for line plots.
show_bounds – Whether to show, and extend the plot to, the lower and upper bounds.
lb_full – Lower bound.
ub_full – Upper bound.
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
sampling_1d_marginals
(result: pypesto.result.Result, i_chain: int = 0, stepsize: int = 1, plot_type: str = 'both', bw: str = 'scott', suptitle: str = None, size: Tuple[float, float] = None)¶ Plot marginals.
- Parameters
result – The pyPESTO result object with filled sample result.
i_chain – Which chain to plot. Default: First chain.
stepsize – Only one in stepsize values is plotted.
plot_type ({'hist'|'kde'|'both'}) – Specify whether to plot a histogram (‘hist’), a kernel density estimate (‘kde’), or both (‘both’).
bw ({'scott', 'silverman' | scalar | pair of scalars}) – Kernel bandwidth method.
suptitle – Figure super title.
size – Figure size in inches.
- Returns
ax
- Return type
matplotlib-axes
-
pypesto.visualize.
sampling_fval_trace
(result: pypesto.result.Result, i_chain: int = 0, full_trace: bool = False, stepsize: int = 1, title: str = None, size: Tuple[float, float] = None, ax: matplotlib.axes._axes.Axes = None)¶ Plot log-posterior (=function value) over iterations.
- Parameters
result – The pyPESTO result object with filled sample result.
i_chain – Which chain to plot. Default: First chain.
full_trace – Plot the full trace including warm up. Default: False.
stepsize – Only one in stepsize values is plotted.
title – Axes title.
size (ndarray) – Figure size in inches.
ax – Axes object to use.
- Returns
The plot axes.
- Return type
ax
-
pypesto.visualize.
sampling_parameters_trace
(result: pypesto.result.Result, i_chain: int = 0, full_trace: bool = False, stepsize: int = 1, use_problem_bounds: bool = True, suptitle: str = None, size: Tuple[float, float] = None, ax: matplotlib.axes._axes.Axes = None)¶ Plot parameter values over iterations.
- Parameters
result – The pyPESTO result object with filled sample result.
i_chain – Which chain to plot. Default: First chain.
full_trace – Plot the full trace including warm up. Default: False.
stepsize – Only one in stepsize values is plotted.
use_problem_bounds – Defines if the y-limits shall be the lower and upper bounds of parameter estimation problem.
suptitle – Figure suptitle.
size – Figure size in inches.
ax – Axes object to use.
- Returns
The plot axes.
- Return type
ax
-
pypesto.visualize.
sampling_scatter
(result: pypesto.result.Result, i_chain: int = 0, stepsize: int = 1, suptitle: str = None, size: Tuple[float, float] = None)¶ Parameter scatter plot.
- Parameters
result – The pyPESTO result object with filled sample result.
i_chain – Which chain to plot. Default: First chain.
stepsize – Only one in stepsize values is plotted.
suptitle – Figure super title.
size – Figure size in inches.
- Returns
The plot axes.
- Return type
ax
-
pypesto.visualize.
waterfall
(results, ax=None, size=18.5, 10.5, y_limits=None, scale_y='log10', offset_y=None, start_indices=None, reference=None, colors=None, legends=None)¶ Plot waterfall plot.
- Parameters
results (pypesto.Result or list) – Optimization result obtained by ‘optimize.py’ or list of those
ax (matplotlib.Axes, optional) – Axes object to use.
size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
y_limits (float or ndarray, optional) – maximum value to be plotted on the y-axis, or y-limits
scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
offset_y – offset for the y-axis, if it is supposed to be in log10-scale
start_indices (list or int) – list of integers specifying the multistart to be plotted or int specifying up to which start index should be plotted
reference (list, optional) – List of reference points for optimization results, containing et least a function value fval
colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
legends (list or str) – Labels for line plots, one label per result object
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes
-
pypesto.visualize.
waterfall_lowlevel
(fvals, scale_y='log10', offset_y=0.0, ax=None, size=18.5, 10.5, colors=None, legend_text=None)¶ Plot waterfall plot using list of function values.
- Parameters
fvals (numeric list or array) – Including values need to be plotted.
scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
offset_y – offset for the y-axis, if it is supposed to be in log10-scale
ax (matplotlib.Axes, optional) – Axes object to use.
size (tuple, optional) – see waterfall
colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
legend_text (str) – Label for line plots
- Returns
ax – The plot axes.
- Return type
matplotlib.Axes