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
__class__

alias of builtins.type

__contains__()

True if D has a key k, else False.

__delattr__

Delete self[key].

__delitem__

Delete self[key].

__dict__ = mappingproxy({'__module__': 'pypesto.visualize.reference_points', '__doc__': '\n Reference point for plotting. Should contain a parameter value and an\n objective function value, may alos contain a color and a legend.\n\n Can be used like a dict.\n\n Attributes\n ----------\n\n x: ndarray\n Reference parameters.\n\n fval: float\n Function value, fun(x), for reference parameters.\n\n color: RGBA, optional\n Color which should be used for reference point.\n\n auto_color: boolean\n flag indicating whether color for this reference point should be\n assigned automatically or whether it was assigned by user\n\n legend: str\n legend text for reference point\n ', '__init__': <function ReferencePoint.__init__>, '__getattr__': <function ReferencePoint.__getattr__>, '__setattr__': <slot wrapper '__setitem__' of 'dict' objects>, '__delattr__': <slot wrapper '__delitem__' of 'dict' objects>, '__dict__': <attribute '__dict__' of 'ReferencePoint' objects>, '__weakref__': <attribute '__weakref__' of 'ReferencePoint' objects>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattr__(key)
__getattribute__

Return getattr(self, name).

__getitem__()

x.__getitem__(y) <==> x[y]

__gt__

Return self>value.

__hash__ = None
__init__(reference=None, x=None, fval=None, color=None, legend=None)

Initialize self. See help(type(self)) for accurate signature.

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__module__ = 'pypesto.visualize.reference_points'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Set self[key] to value.

__setitem__

Set self[key] to value.

__sizeof__() → size of D in memory, in bytes
__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

clear() → None. Remove all items from D.
copy() → a shallow copy of D
fromkeys()

Returns a new dict with keys from iterable and values equal to value.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values
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, chekc 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_lowlevel(fvals, ax=None, size=(18.5, 6.5), color=None, legend_text=None)

Lowlevel routine for plotting one profile, working with a numpy array only

Parameters:
  • fvals (numeric list or array) – Including values need to be plotted.
  • 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
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.profiles(results, ax=None, profile_indices=None, size=(18.5, 6.5), reference=None, colors=None, legends=None, profile_list_id=0)

Plot classical 1D profile plot (using the posterior, e.g. Gaussian like profile)

Parameters:
  • results (list or pypesto.Result) – list of pypesto.Result or single pypesto.Result
  • 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 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, optional) – Labels for line plots, one label per result object
  • profile_list_id (int, optional) – index of the profile list to be used for profiling
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.profiles_lowlevel(fvals, ax=None, size=(18.5, 6.5), color=None, legend_text=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) – Including values need to be plotted.
  • 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 (str) – Label for line plots
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.sampling_1d_marginals(result: pypesto.result.Result, i_chain: int = 0, burn_in: int = None, 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.
  • burn_in – Index after burn-in phase, thus also the burn-in length.
  • 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, burn_in: int = None, 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.
  • burn_in – Index after burn-in phase, thus also the burn-in length.
  • 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, burn_in: int = None, 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.
  • burn_in – Index after burn-in phase, thus also the burn-in length.
  • 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, burn_in: int = None, 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.
  • burn_in – Index after burn-in phase, thus also the burn-in length.
  • 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