pymcmcstat.plotting package

pymcmcstat.plotting.MCMCPlotting module

Created on Wed Jan 31 12:54:16 2018

@author: prmiles

class pymcmcstat.plotting.MCMCPlotting.Plot[source]

Plotting routines for analyzing sampling chains from MCMC process.

Attributes:
pymcmcstat.plotting.MCMCPlotting.plot_chain_metrics(chain, name=None, figsizeinches=None)[source]

Plot chain metrics for individual chain

  • Scatter plot of chain
  • Histogram of chain
Args:
  • chains (ndarray): Sampling chain for specific parameter
  • names (str): Name of each parameter
  • figsizeinches (list): Specify figure size in inches [Width, Height]
pymcmcstat.plotting.MCMCPlotting.plot_chain_panel(chains, names=None, figsizeinches=None, maxpoints=500)[source]

Plot sampling chain for each parameter

Args:
  • chains (ndarray): Sampling chain for each parameter
  • names (list): List of strings - name of each parameter
  • figsizeinches (list): Specify figure size in inches [Width, Height]
  • maxpoints (int): Max number of display points - keeps scatter plot from becoming overcrowded
pymcmcstat.plotting.MCMCPlotting.plot_density_panel(chains, names=None, hist_on=False, figsizeinches=None)[source]

Plot marginal posterior densities

Args:
  • chains (ndarray): Sampling chain for each parameter
  • names (list): List of strings - name of each parameter
  • hist_on (bool): Flag to include histogram on density plot
  • figsizeinches (list): Specify figure size in inches [Width, Height]
pymcmcstat.plotting.MCMCPlotting.plot_histogram_panel(chains, names=None, figsizeinches=None)[source]

Plot histogram from each parameter’s sampling history

Args:
  • chains (ndarray): Sampling chain for each parameter
  • names (list): List of strings - name of each parameter
  • hist_on (bool): Flag to include histogram on density plot
  • figsizeinches (list): Specify figure size in inches [Width, Height]
pymcmcstat.plotting.MCMCPlotting.plot_pairwise_correlation_panel(chains, names=None, figsizeinches=None, skip=1)[source]

Plot pairwise correlation for each parameter

Args:
  • chains (ndarray): Sampling chain for each parameter
  • names (list): List of strings - name of each parameter
  • figsizeinches (list): Specify figure size in inches [Width, Height]
  • skip (int): Indicates step size to be used when plotting elements from the chain

pymcmcstat.plotting.PredictionIntervals module

Created on Wed Nov 8 12:00:11 2017

@author: prmiles

class pymcmcstat.plotting.PredictionIntervals.PredictionIntervals[source]

Prediction/Credible interval methods.

Attributes:
generate_prediction_intervals(sstype=None, nsample=500, calc_pred_int=True, waitbar=False)[source]

Generate prediction/credible interval.

Args:
  • sstype (int): Sum-of-squares type
  • nsample (int): Number of samples to use in generating intervals.
  • calc_pred_int (bool): Flag to turn on prediction interval calculation.
  • waitbar (bool): Flag to turn on progress bar.
plot_prediction_intervals(plot_pred_int=True, adddata=False, addlegend=True, figsizeinches=None, model_display={}, data_display={}, interval_display={})[source]

Plot prediction/credible intervals.

Args:
  • plot_pred_int (bool): Flag to include PI on plot.
  • adddata (bool): Flag to include data on plot.
  • addlegend (bool): Flag to include legend on plot.
  • figsizeinches (list): Specify figure size in inches [Width, Height].
  • model_display (dict): Model display settings.
  • data_display (dict): Data display settings.
  • interval_display (dict): Interval display settings.
Available display options (defaults in parantheses):
  • model_display: linestyle ('-'), marker (''), color ('r'), linewidth (2), markersize (5), label (model), alpha (1.0)
  • data_display: linestyle (''), marker ('.'), color ('b'), linewidth (1), markersize (5), label (data), alpha (1.0)
  • data_display: linestyle (':'), linewidth (1), alpha (1.0), edgecolor ('k')
setup_prediction_interval_calculation(results, data, modelfunction, burnin=0)[source]

Setup calculation for prediction interval generation

Args:

pymcmcstat.plotting.utilities module

Created on Mon May 14 06:24:12 2018

@author: prmiles

pymcmcstat.plotting.utilities.append_to_nrow_ncol_based_on_shape(sh, nrow, ncol)[source]

Append to list based on shape of array

Args:
  • sh (tuple): Shape of array.
  • nrow (list): List of number of rows
  • ncol (list): List of number of columns
Returns:
  • nrow (list): List of number of rows
  • ncol (list): List of number of columns
pymcmcstat.plotting.utilities.check_defaults(kwargs, defaults)[source]

Check if defaults are defined in kwargs

Args:
  • kwargs (dict): Keyword arguments.
  • defaults (dict): Default settings.
Returns:
  • kwargs (dict): Updated keyword arguments with at least defaults set.
pymcmcstat.plotting.utilities.check_symmetric(a, tol=1e-08)[source]

Check if array is symmetric by comparing with transpose.

Args:
  • a (ndarray): Array to test.
  • tol (float): Tolerance for testing equality.
Returns:
  • (bool): True -> symmetric, False -> not symmetric.
pymcmcstat.plotting.utilities.convert_flag_to_boolean(flag)[source]

Convert flag to boolean for backwards compatibility.

Args:
  • flag (bool or int): Flag to specify something.
Returns:
  • flag (bool): Flag to converted to boolean.
pymcmcstat.plotting.utilities.empirical_quantiles(x, p=array([0.25, 0.5, 0.75]))[source]

Calculate empirical quantiles.

Args:
  • x (ndarray): Observations from which to generate quantile.
  • p (ndarray): Quantile limits.
Returns:
  • (ndarray): Interpolated quantiles.
pymcmcstat.plotting.utilities.extend_names_to_match_nparam(names, nparam)[source]

Append names to list using default convention until length of names matches number of parameters.

For example, if names = [‘name_1’, ‘name_2’] and nparam = 4, then two additional names will be appended to the names list. E.g.,:

names = ['name_1', 'name_2', 'p_{2}', 'p_{3}']
Args:
  • names (list): Names of parameters provided by user
  • nparam (int): Number of parameter names to generate
Returns:
  • names (list): List of strings - extended list of parameter names
pymcmcstat.plotting.utilities.gaussian_density_function(x, mu=0, sigma2=1)[source]

Standard normal/Gaussian density function.

Args:
  • x (float): Value of which to calculate probability.
  • mu (float): Mean of Gaussian distribution.
  • sigma2 (float): Variance of Gaussian distribution.
Returns:
  • y (float): Likelihood of x.
pymcmcstat.plotting.utilities.generate_default_names(nparam)[source]

Generate generic parameter name set.

For example, if nparam = 4, then the generated names are:

names = ['p_{0}', 'p_{1}', 'p_{2}', 'p_{3}']
Args:
  • nparam (int): Number of parameter names to generate
Returns:
  • names (list): List of strings - parameter names
pymcmcstat.plotting.utilities.generate_ellipse(mu, cmat, ndp=100)[source]

Generates points for a probability contour ellipse

Args:
  • mu (ndarray): Mean values
  • cmat (ndarray): Covariance matrix
  • npd (int): Number of points to generate
Returns:
pymcmcstat.plotting.utilities.generate_names(nparam, names)[source]

Generate parameter name set.

For example, if nparam = 4, then the generated names are:

names = ['p_{0}', 'p_{1}', 'p_{2}', 'p_{3}']
Args:
  • nparam (int): Number of parameter names to generate
  • names (list): Names of parameters provided by user
Returns:
  • names (list): List of strings - parameter names
pymcmcstat.plotting.utilities.generate_subplot_grid(nparam=2)[source]

Generate subplot grid.

For example, if nparam = 2, then the subplot will have 2 rows and 1 column.

Args:
  • nparam (int): Number of parameters
Returns:
  • ns1 (int): Number of rows in subplot
  • ns2 (int): Number of columns in subplot
pymcmcstat.plotting.utilities.iqrange(x)[source]

Interquantile range of each column of x.

Args:
Returns:
  • (ndarray): Interquantile range - single element array, q3 - q1.
pymcmcstat.plotting.utilities.is_semi_pos_def_chol(x)[source]

Check if matrix is semi positive definite by calculating Cholesky decomposition.

Args:
Returns:
  • If matrix is not semi positive definite return False, None
  • If matrix is semi positive definite return True and the Upper triangular form of the Cholesky decomposition matrix.
pymcmcstat.plotting.utilities.make_x_grid(x, npts=100)[source]

Generate x grid based on extrema.

1. If len(x) > 200, then generates grid based on difference between the max and min values in the array.

2. Otherwise, the grid is defined with respect to the array mean plus or minus four standard deviations.

Args:
  • x (ndarray): Array of points
  • npts (int): Number of points to use in generated grid
Returns:
  • Uniformly spaced array of points with shape =(npts,1). (ndarray)
pymcmcstat.plotting.utilities.scale_bandwidth(x)[source]

Scale bandwidth of array.

Args:
  • x (ndarray): Array of points - column of chain.
Returns:
  • s (ndarray): Scaled bandwidth - single element array.
pymcmcstat.plotting.utilities.set_local_parameters(ii, local)[source]

Set local parameters based on tests.

Test 1:
  • local == 0
Test 2:
  • local == ii
Args:
Returns:
  • test (ndarray): Array of Booleans indicated test results.
pymcmcstat.plotting.utilities.setup_plot_features(nparam, names, figsizeinches)[source]

Setup plot features.

Args:
  • nparam (int): Number of parameters
  • names (list): Names of parameters provided by user
  • figsizeinches (list): [Width, Height]
Returns:
  • ns1 (int): Number of rows in subplot
  • ns2 (int): Number of columns in subplot
  • names (list): List of strings - parameter names
  • figsizeiches (list): [Width, Height]