lib.samples.plotting.SamplesPlotStyle

class lib.samples.plotting.SamplesPlotStyle(style=None, **kwargs)

Bases: lib.samples.plotting.ParameterPlotStyle

Plotting style for samples. It holds default attributes (truths, colors, etc.) that can be set at initialization (style = SamplesPlotStyle(colors='r')) or at any time using update().

Initialize SamplesPlotStyle.

Parameters
  • style (SamplesPlotStyle, default=None) – A plotting style to start from, which will be updated with kwargs.

  • kwargs (dict) – Attributes for SamplesPlotStyle.

Methods

copy

Return shallow copy of self.

deepcopy

from_state

Instantiate and initalize class with state dictionary.

get

Return value if not None, else attribute name if not None, else default.

get_color

Return color corresponding to label label.

get_default_parameters

If parameters is None, return varied parameters from samples.

get_default_truths

Return default truth / reference values for parameters.

get_list

Same as get(), but ensuring returned value is a list.

get_parameters

Return parameters.

is_mpi_broadcast

is_mpi_gathered

is_mpi_root

is_mpi_scattered

load

Load class in numpy binary format from disk.

load_auto

If different formats are possible, this method should between them based on file name extension.

log_critical

log_debug

log_error

log_info

log_warning

plot_1d

Plot 1D distribution of samples.

plot_2d

Plot 2D distribution of samples.

plot_autocorrelation_time

Plot integrated autocorrelation time.

plot_chain

Make trace plot.

plot_corner

Make corner plot.

plot_gelman_rubin

Plot Gelman-Rubin statistics.

save

Save class to disk.

save_auto

If different formats are possible, this method should between them based on file name extension.

savefig

Save figure to filename.

update

Update attibutes with those in kwargs.

Attributes

logger

mpiattrs

MPI attributes

mpicomm

mpiroot

mpistate

copy()

Return shallow copy of self.

classmethod from_state(state, mpiroot=0, mpicomm=None)

Instantiate and initalize class with state dictionary.

get(name, value=None, default=None)

Return value if not None, else attribute name if not None, else default.

Parameters
  • name (string) – Attribute name. If None, defaults to default.

  • value (object, default=None) – Value. If None, returns attribute name.

  • default (object, default=None) – Default value.

get_color(label, labels=None)

Return color corresponding to label label. If colors is a list, return color at index of label in list of labels labels.

static get_default_parameters(parameters, samples)

If parameters is None, return varied parameters from samples.

get_default_truths(parameters, truths=None)

Return default truth / reference values for parameters.

Parameters
  • parameters (Parameter, tuple, list, ParameterCollection) – Parameters to return truth values for.

  • truths (list, default=None) – List of truth values. If None, return truths if exists, else set all truths to None. If 'value', return list of Parameter.value.

Returns

truths – Return single value if parameters is a single parameter.

Return type

float, list

get_list(name, value=None, default=None)

Same as get(), but ensuring returned value is a list. Default length (see make_list()) is taken as default length.

static get_parameters(parameters, chains=None)

Return parameters.

Parameters
  • parameters (tuple, list, ParameterCollection) – List of parameter (names). If parameter name, get the xorresponding parameter in the first element in chains that contains this parameter.

  • chains (list) – List of classes with parameters attribute.

Returns

toret – Return single parameter if parameters is a single parameter (name).

Return type

Parameter, ParameterCollection

classmethod load(filename, mpiroot=0, mpicomm=None)

Load class in numpy binary format from disk. If the loaded state contains __class__ and that exists in cls._registry, return instance of cls._registry[__class__] (instead of cls).

load_auto(*args, **kwargs)

If different formats are possible, this method should between them based on file name extension.

property mpiattrs

MPI attributes

plot_1d(chains=None, parameter=None, labels=None, truth=None, ax=None, filename=None)

Plot 1D distribution of samples.

Parameters
  • chains (list, default=None) – List of Samples instances. Defaults to chains.

  • parameter (Parameter, ParamName, string, tuple) – Parameter name.

  • labels (list, string) – Label(s) for input chains.

  • truth (float, string, default=None) – Plot this truth / reference value for parameter. If 'value', take Parameter.value.

  • ax (matplotlib.axes.Axes, default=None) – Axes where to plot samples. If None, takes current axes.

  • filename (string, default=None) – If not None, file name where to save figure.

Returns

ax

Return type

matplotlib.axes.Axes

plot_2d(chains=None, parameters=None, labels=None, truths=None, ax=None, filename=None)

Plot 2D distribution of samples.

Parameters
  • chains (list, default=None) – List of Samples instances. Defaults to chains.

  • parameters (tuple, list, ParameterCollection) – The two parameter name(s).

  • labels (list, string) – Label(s) for input chains.

  • truths (list, default=None) – Plot this truths / reference values for parameters. See get_default_truths().

  • ax (matplotlib.axes.Axes, default=None) – Axes where to plot samples. If None, takes current axes.

  • filename (string, default=None) – If not None, file name where to save figure.

Returns

ax

Return type

matplotlib.axes.Axes

plot_autocorrelation_time(chains=None, parameters=None, threshold=50, slices=None, ax=None, filename=None)

Plot integrated autocorrelation time.

Parameters
  • chains (list, default=None) – List of Samples instances. Defaults to chains.

  • parameters (list, ParameterCollection) – The parameter names.

  • threshold (float, default=50) – If not None, plot \(y = x/\mathrm{threshold}\) line. Integrated autocorrelation time estimation can be considered reliable when falling under this line.

  • slices (list, array) – List of increasing number of steps to include in calculation of autocorrelation time.

  • ax (matplotlib.axes.Axes, default=None) – Axes where to plot samples. If None, takes current axes.

  • filename (string, default=None) – If not None, file name where to save figure.

Returns

ax

Return type

matplotlib.axes.Axes

plot_chain(chain, parameters=None, filename=None)

Make trace plot.

Parameters
  • chain (Samples) – Samples to plot.

  • parameters (list, ParameterCollection) – The parameter names.

  • filename (string, default=None) – If not None, file name where to save figure.

Returns

  • fig (matplotlib.figure.Figure) – Figure.

  • lax (array) – Array of axes.

plot_corner(chains=None, parameters=None, labels=None, truths=None, filename=None)

Make corner plot.

Parameters
  • chains (list, default=None) – List of Samples instances. Defaults to chains.

  • parameters (list, ParameterCollection) – The parameter names.

  • labels (list, string) – Label(s) for input chains.

  • truths (list, default=None) – Plot this truths / reference values for parameters. See get_default_truths().

  • filename (string, default=None) – If not None, file name where to save figure.

Returns

  • fig (matplotlib.figure.Figure) – Figure.

  • dax (dict) – Dictionary of ParamName and to matplotlib.axes.Axes: name: axes for 1D plots and (name1, name2): axes for 2D plots.

plot_gelman_rubin(chains=None, parameters=None, multivariate=False, threshold=1.1, slices=None, ax=None, filename=None)

Plot Gelman-Rubin statistics.

Parameters
  • chains (list, default=None) – List of Samples instances. Defaults to chains.

  • parameters (list, ParameterCollection) – The parameter names.

  • multivariate (bool, default=False) – If True, add line for maximum of eigen value of Gelman-Rubin matrix. See Samples.gelman_rubin().

  • threshold (float, default=1.1) – If not None, plot horizontal line at this value.

  • slices (list, array) – List of increasing number of steps to include in calculation of Gelman-Rubin statistics.

  • ax (matplotlib.axes.Axes, default=None) – Axes where to plot samples. If None, takes current axes.

  • filename (string, default=None) – If not None, file name where to save figure.

Returns

ax

Return type

matplotlib.axes.Axes

save(filename)

Save class to disk.

save_auto(*args, **kwargs)

If different formats are possible, this method should between them based on file name extension.

savefig(filename, fig=None)

Save figure to filename.

Parameters
  • filename (string) – Path where to save figure.

  • fig (matplotlib.figure.Figure, default=None) – Figure to save. Defaults to current figure.

update(**kwargs)

Update attibutes with those in kwargs.