_Posterior

it.grypho.scala.leonardo.probability._Posterior
case class _Posterior(prior: _Expression, likelihood: _Expression, data: _Expression) extends _Expression

Conjugate updating: posterior(prior, likelihood, data) (F_0050).

The likelihood is written as the family with its unknown parameter left free — posterior(betadist(2, 2), binomial(10, p), 7) — where p is the one free name, the same exactly-one-free-name rule Predicate applies to a random variable. The answer is an ordinary _Distribution, so pdf/cdf/quantile/expect/variance apply to it unchanged and nothing downstream learns a new type.

The table, each arm validating its data:

prior likelihood (free) data posterior
betadist(a, b) binomial(n, p) a count k in 0..n betadist(a + k, b + n − k)
gammadist(k, rate) poisson(l) observations, non-negative integers gammadist(k + Σx, rate + n)
normal(μ₀, σ₀) normal(μ, σ), σ known observations precision-weighted normal(μₙ, σₙ)

Observations are a 1×n row or an n×1 column; a single number is a sample of one.

Everything else stays symbolic: a pair outside the table, two free names or none, a likelihood whose free slot is not the conjugate parameter (binomial(n, 0.5)), the Normal–Normal case with unknown σ (that needs the Normal-inverse-gamma family, a two-parameter carrier this package does not have), and invalid data. A general posterior — an unnormalised density with no closed form — is deliberately not attempted: it needs numerical integration over the parameter space or sampling, which is a package rather than a function, and declining beats a confident approximation.

Exactness: a _Distribution stores Double parameters, so a conjugate posterior is a Double result even from exact input — the lu/qr precedent, demote rather than refuse. Only _Bayes is exact.

Value parameters

data

the observation: a count, a number, or a vector of observations

likelihood

the sampling family with its unknown parameter free

prior

a distribution expression, the prior

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait _Expression
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def children: List[_Expression]

Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.

Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.

Attributes

Definition Classes
override def eval(env: Environment): Either[_Expression, _Value]

Reduces this expression in the given environment.

Reduces this expression in the given environment.

Value parameters

env

variable bindings and display precision

Attributes

Returns

Right(v) when all free variables resolved to concrete values; Left(e) when reduction is partial or impossible

Definition Classes
override def rebuild(c: List[_Expression]): _Expression

Reconstructs the same node shape with replacement sub-expressions.

Reconstructs the same node shape with replacement sub-expressions.

Value parameters

newChildren

replacements in the same order and count as children

Attributes

Definition Classes
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Inherited fields

lazy val freeVars: Set[String]

Cached set of free variable names; O(1) after the first access.

Cached set of free variable names; O(1) after the first access.

Attributes

Inherited from:
_Expression