bayesplain.teach.GridPosterior

class bayesplain.teach.GridPosterior(grid, prior, likelihood, unnormalized, posterior, kind='discrete', label='rate')[source]

Prior, likelihood, and posterior over a grid, with the arithmetic shown.

Variables:
grid

The candidate values considered.

prior

Prior weight on each, normalised.

likelihood

Likelihood of the data at each candidate.

unnormalized

prior * likelihood, before dividing through.

posterior

The normalised posterior.

kind='discrete'

'discrete' if the posterior sums to 1, 'continuous' if it integrates to 1 over the grid.

label='rate'

What the grid is a grid of, for printing.

Methods

interval([level])

Equal-tailed credible interval from the grid.

mean()

Posterior mean.

plot([ax])

Draw prior, likelihood, and posterior on shared axes.

table([max_rows])

Show the four columns whose arithmetic produces the posterior.

grid[source]
interval(level=0.95)[source]

Equal-tailed credible interval from the grid.

Parameters:
level : float, default 0.95

Probability the interval should contain.

Returns:

Lower and upper bounds.

Return type:

tuple of float

kind = 'discrete'[source]
label = 'rate'[source]
likelihood[source]
mean()[source]

Posterior mean.

Returns:

A weighted average of the grid values.

Return type:

float

plot(ax=None)[source]

Draw prior, likelihood, and posterior on shared axes.

Parameters:
ax : matplotlib.axes.Axes, optional

Axes to draw on. Created if omitted.

Returns:

The axes drawn on.

Return type:

matplotlib.axes.Axes

posterior[source]
prior[source]
table(max_rows=12)[source]

Show the four columns whose arithmetic produces the posterior.

Parameters:
max_rows : int, default 12

Grid rows to print. A fine grid is summarised rather than dumped.

Returns:

Printable table: grid, prior, likelihood, their product, and the product divided by its own total.

Return type:

_Report

property total[source]

The normalising constant – the number everything got divided by.

unnormalized[source]