chain = PcaChain(posterior=posterior, start=initial_guess) # We generate samples by advancing the chain by a chosen number of steps using the advance method: chain.advance(25000) # we can check the status of the chain using the plot_diagnostics method: chain.plot_diagnostics() # The burn-in (how many samples from the start of the chain are discarded) # can be chosen by setting the burn attribute of the chain object: chain.burn = 5000 # we can get a quick overview of the posterior using the matrix_plot method # of chain objects, which plots all possible 1D & 2D marginal distributions # of the full parameter set (or a chosen sub-set). chain.matrix_plot(labels=['area', 'width', 'center', 'background']) # We can easily estimate 1D marginal distributions for any parameter # using the get_marginal method: area_pdf = chain.get_marginal(0) area_pdf.plot_summary(label='Gaussian area') # We can assess the level of uncertainty in the model predictions by passing each sample # through the forward-model and observing the distribution of model expressions that result: # generate an axis on which to evaluate the model x_fits = linspace(0, 12, 500) # get the sample sample = chain.get_sample() # pass each through the forward model curves = array([PeakModel.forward_model(x_fits, theta) for theta in sample])
# we can check the status of the chain using the plot_diagnostics method chain.plot_diagnostics(show=False, filename='plot_diagnostics_example.png') print(' # diagnostics plot finished') # We can automatically set sensible burn and thin values for the sample chain.autoselect_burn_and_thin() # we can get a quick overview of the posterior using the matrix_plot # functionality of chain objects, which plots all possible 1D & 2D # marginal distributions of the full parameter set (or a chosen sub-set). chain.thin = 1 labels = [ 'peak 1 area', 'peak 1 width', 'peak 2 area', 'peak 2 width', 'background' ] chain.matrix_plot(show=False, labels=labels, filename='matrix_plot_example.png') print(' # matrix plot finished') # We can easily estimate 1D marginal distributions for any parameter # using the get_marginal method: w1_pdf = chain.get_marginal(1, unimodal=True) w2_pdf = chain.get_marginal(3, unimodal=True) # get_marginal returns a density estimator object, which can be called ax = linspace(0.2, 4., 1000) # build an axis to evaluate the pdf estimates plt.plot(ax, w1_pdf(ax), label='peak #1 width marginal', lw=2) # plot estimates of each marginal PDF plt.plot(ax, w2_pdf(ax), label='peak #2 width marginal', lw=2) plt.xlabel('peak width') plt.ylabel('probability density') plt.legend()
chain = PcaChain(posterior=posterior, start=[600, 1, 600, 1, 15]) # generate a sample by advancing the chain chain.advance(20000) # we can check the status of the chain using the plot_diagnostics method chain.plot_diagnostics() # We can automatically set sensible burn and thin values for the sample chain.autoselect_burn() chain.autoselect_thin() # we can get a quick overview of the posterior using the matrix_plot # functionality of chain objects, which plots all possible 1D & 2D # marginal distributions of the full parameter set (or a chosen sub-set). chain.matrix_plot() # We can easily estimate 1D marginal distributions for any parameter # using the get_marginal method: w1_pdf = chain.get_marginal(1, unimodal=True) w2_pdf = chain.get_marginal(3, unimodal=True) # get_marginal returns a density estimator object, which can be called # as a function to return the value of the pdf at any point. # Make an axis on which to evaluate the PDFs: ax = linspace(0.2, 4., 1000) plt.plot(ax, w1_pdf(ax), label='width #1 marginal', lw=2) plt.plot(ax, w2_pdf(ax), label='width #2 marginal', lw=2) plt.xlabel('peak width') plt.ylabel('probability density') plt.legend()
chain = PcaChain(posterior=posterior, start=initial_guess) # We generate samples by advancing the chain by a chosen number of steps using the advance method: chain.advance(25000) # we can check the status of the chain using the plot_diagnostics method: chain.plot_diagnostics(filename='plot_diagnostics_example.png') # The burn-in (how many samples from the start of the chain are discarded) # can be chosen by setting the burn attribute of the chain object: chain.burn = 5000 # we can get a quick overview of the posterior using the matrix_plot method # of chain objects, which plots all possible 1D & 2D marginal distributions # of the full parameter set (or a chosen sub-set). chain.matrix_plot(labels=['area', 'width', 'center', 'background'], filename='matrix_plot_example.png') # We can easily estimate 1D marginal distributions for any parameter # using the get_marginal method: area_pdf = chain.get_marginal(0) area_pdf.plot_summary(label='Gaussian area', filename='pdf_summary_example.png') # We can assess the level of uncertainty in the model predictions by passing each sample # through the forward-model and observing the distribution of model expressions that result: # generate an axis on which to evaluate the model x_fits = linspace(0, 12, 500) # get the sample sample = chain.get_sample() # pass each through the forward model