# magni.cs.phase_transition.plotting module¶

Module providing plotting for the magni.cs.phase_transition subpackage.

## Routine listings¶

plot_phase_transitions(curves, plot_l1=True, output_path=None)
Function for plotting phase transition boundary curves.
plot_phase_transition_colormap(dist, delta, rho, plot_l1=True,
output_path=None) Function for plotting reconstruction probabilities in the phase space.
plot_phase_transition_computation_times(time, delta, rho, output_path=None)
Function for plotting average computation times in the phase space.
magni.cs.phase_transition.plotting.plot_phase_transitions(curves, plot_l1=True, output_path=None, legend_loc='upper left', errorevery=None, reference_curves=None)[source]

Plot of a set of phase transition boundary curves.

The set of phase transition boundary curves are plotted an saved under the output_path, if specified. The curves must be a list of dictionaries each having keys delta, rho, and label. delta must be an ndarray of $$\delta$$ values in the phase space. rho must be an ndarray of the corresponding $$\rho$$ values in the phase space. label must be a str describing the curve. Optionally, a curves dictionary may have an yerr key with a corresponding 2-by-“len(delta)” array as value. The first row in this array specifices the location of the upper error bars whereas the second row specifies the location of the lower error bars.

Parameters: curves (list) – A list of dicts describing the curves to plot. plot_l1 (bool, optional) – Whether or not to plot the theoretical $$\ell_1$$ curve (the default is True). output_path (str, optional) – Path (including file type extension) under which the plot is saved (the default value is None, which implies that the plot is not saved). legend_loc (str) – Location of legend as a matplotlib legend location string (the default is ‘upper left’, which implies that the legend is placed in the upper left corner of the plot.) errorevery (int) – The subsampling of error bars if used (the default value is None, which implies that the default Matplotlib value for errorevery is used.) reference_curves (list, optional) – The list of dicts describing the reference curves to plot.

Notes

The plotting is done using matplotlib, which implies that an open figure containing the plot will result from using this function.

Tabulated values of the theoretical $$\ell_1$$ phase transition boundary is available at http://people.maths.ox.ac.uk/tanner/polytopes.shtml

Examples

For example,

>>> import numpy as np
>>> from magni.cs.phase_transition.plotting import plot_phase_transitions
>>> delta = np.array([0.1, 0.2, 0.9])
>>> rho = np.array([0.1, 0.3, 0.8])
>>> curves = [{'delta': delta, 'rho': rho, 'label': 'data1'}]
>>> output_path = 'phase_transitions.pdf'
>>> plot_phase_transitions(curves, output_path=output_path)

magni.cs.phase_transition.plotting.plot_phase_transition_colormap(dist, delta, rho, plot_l1=True, output_path=None)[source]

Create a colormap of the phase space reconstruction probabilities.

The delta and rho values span a 2D grid in the phase space. Reconstruction probabilities are then calculated from the dist 3D array of reconstruction error distances. The resulting 2D grid of reconstruction probabilites is visualised over the square centers in this 2D grid using a colormap. Values in this grid at lower indicies correspond to lower values of $$\delta$$ and $$\rho$$. If plot_l1 is True, then the theoretical l1 curve is overlayed the colormap. The colormap is saved under the output_path, if specified.

Parameters: dist (ndarray) – A 3D array of reconstruction error distances. delta (ndarray) – $$\delta$$ values used in the 2D grid. rho (ndarray) – $$\rho$$ values used in the 2D grid. plot_l1 (bool) – Whether or not to plot the theoretical $$\ell_1$$ curve. (the default is True) output_path (str, optional) – Path (including file type extension) under which the plot is saved (the default value is None which implies, that the plot is not saved).

Notes

The plotting is done using matplotlib, which implies that an open figure containing the plot will result from using this function.

The values in delta and rho are assumed to be equally spaced.

Due to the centering of the color coded rectangles, they are not necessarily square towards the ends of the intervals defined by delta and rho.

Tabulated values of the theoretical $$\ell_1$$ phase transition boundary is available at http://people.maths.ox.ac.uk/tanner/polytopes.shtml

Examples

For example,

>>> import numpy as np
>>> from magni.cs.phase_transition.plotting import (
...     plot_phase_transition_colormap)
>>> delta = np.array([0.2, 0.5, 0.8])
>>> rho = np.array([0.3, 0.6])
>>> dist = np.array([[[1.35e-08, 1.80e-08], [1.08, 1.11]],
... [[1.40e-12, 8.32e-12], [8.57e-01, 7.28e-01]], [[1.92e-13, 1.17e-13],
... [2.10e-10,   1.12e-10]]])
>>> out_path = 'phase_transition_cmap.pdf'
>>> plot_phase_transition_colormap(dist, delta, rho, output_path=out_path)

magni.cs.phase_transition.plotting.plot_phase_transition_computation_times(time, delta, rho, output_path=None)[source]

Create a colormap of the phase space average algorithm computation time.

The delta and rho values span a 2D grid in the phase space. Average computation times are then calculated from the time 3D array of reconstruction times. The resulting 2D grid of average reconstruction times is visualised over the square centers in this 2D grid using a colormap. Values in this grid at lower indicies correspond to lower values of $$\delta$$ and $$\rho$$. The colormap is saved under the output_path, if specified.

Parameters: time (ndarray) – A 3D array of algorithm computation times. delta (ndarray) – $$\delta$$ values used in the 2D grid. rho (ndarray) – $$\rho$$ values used in the 2D grid. output_path (str, optional) – Path (including file type extension) under which the plot is saved (the default value is None which implies, that the plot is not saved).

Notes

The plotting is done using matplotlib, which implies that an open figure containing the plot will result from using this function.

The values in delta and rho are assumed to be equally spaced.

Due to the centering of the color coded rectangles, they are not necessarily square towards the ends of the intervals defined by delta and rho.

Examples

For example,

>>> import numpy as np
>>> from magni.cs.phase_transition.plotting import (
...     plot_phase_transition_computation_times)
>>> delta = np.array([0.2, 0.5, 0.8])
>>> rho = np.array([0.3, 0.6])
>>> times = np.array([[[1.35e-08, 1.80e-08], [1.08, 1.11]],
... [[1.40e-12, 8.32e-12], [8.57e-01, 7.28e-01]], [[1.92e-13, 1.17e-13],
... [2.10e-10,   1.12e-10]]])
>>> out_path = 'computation_times_cmap.pdf'
>>> plot_phase_transition_computation_times(
...     times, delta, rho, output_path=out_path)

magni.cs.phase_transition.plotting._plot_extra_curves(axes, plot_l1, reference_curves)[source]

Plot any extra curves that might be needed in a phase space plot.

Parameters: axes (matplotlib.axes.Axes) – The matplotlib Axes instance on which the theoretical l1 phase transition should be plotted. plot_l1 (bool, optional) – Whether or not to plot the theoretical $$\ell_1$$ curve (the default is True). reference_curves (list) – The list of dicts describing the reference curves to plot.
magni.cs.phase_transition.plotting._plot_theoretical_l1(axes)[source]

Plot the theoretical l1 phase transition on the axes.

Parameters: axes (matplotlib.axes.Axes) – The matplotlib Axes instance on which the theoretical l1 phase transition should be plotted.

Notes

The plotted theoretical $$\ell1$$ phase transition is based on tabulated values of available at http://people.maths.ox.ac.uk/tanner/polytopes.shtml