_Bayes

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

Bayes' theorem over a finite set of hypotheses: bayes(prior, likelihood) (F_0050).

Two vectors of the same shape — a 1×n row or an n×1 column — give the normalised posterior pᵢ·Lᵢ / Σⱼ pⱼ·Lⱼ, in that same shape. No new carrier was needed: a row is what tabulate and eigen already return, and it is the form every textbook opens with.

Exact on exact input. When every entry of both vectors is a core._Rational the posterior is computed over the rationals and returned as the prior's own node rebuilt with exact cells, so a posterior of fractions stays a posterior of fractions; one inexact entry demotes the whole computation to Double, the float-contagion rule. The rebuild goes through the prior's core._MatrixShaped node, which is how this package yields a symbolic matrix without importing matrix.

Refuses, staying symbolic: a shape mismatch, an operand that is not a row or a column, a negative entry (neither a probability nor a likelihood), and zero evidence, Σ = 0, which has no posterior at all rather than a degenerate one.

Value parameters

likelihood

the likelihood of the observation under each hypothesis, the same shape

prior

the prior weights over the hypotheses, a row or a column

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