chain_array = ChainArray.from_file(keys=['sample', 'accepted'], path=sampler_output_pilot_path) # %% Drop burn-in samples chain_array.vals['sample'] = chain_array.vals['sample'][ diagnostic_iter_thres:, :] chain_array.vals['accepted'] = chain_array.vals['accepted'][ diagnostic_iter_thres:] # %% Plot traces of simulated chain for i in range(model.num_params()): ps.trace(chain_array.get_param(i), title=r'Traceplot of $\theta_{{{}}}$'.format(i + 1), xlabel='Iteration', ylabel='Parameter value') # %% Plot running means of simulated chain for i in range(model.num_params()): ps.running_mean( chain_array.get_param(i), title=r'Running mean plot of parameter $\theta_{{{}}}$'.format(i + 1), xlabel='Iteration', ylabel='Running mean') # %% Plot histograms of marginals of simulated chain for i in range(model.num_params()): ps.hist(chain_array.get_param(i),
import matplotlib.pyplot as plt from numpy import genfromtxt from statistics import mean import kanga.plots as ps # %% Read chains chains = genfromtxt('chain01.csv', delimiter=',') num_iters, num_pars = chains.shape # %% Trace plot of a single chain with default trace input arguments ps.trace(chains[:, 0]) # %% Trace plot of a single chain with a custom range of x values ps.trace(chains[:, 0], x=range(1000, 1000 + num_iters)) # %% Trace plot of a single chain with some non-default trace input arguments ps.trace(chains[:, 0], ylim=[-8, 10], margins=0.01, title=r'Trace plot of parameter $\theta_{{{}}}$'.format(1), xlabel='Iteration', ylabel='Parameter value') # %% Overlaid trace plots of all three parameters