Expression Types
The package defines an Expression abstract type and several concrete expression types that can be used as the integrand f in BayesBase.expectation(ClosedFormExpectation(), f, q). These types support function composition via the ∘ operator.
ExpLogSquare
ClosedFormExpectations.ExpLogSquare — Type
ExpLogSquare(μ, σ)ExpLogSquare is a type that represents the exp(-(log(x) - μ)^2/(2σ^2)) function.
Represents the function:
\[\text{ExpLogSquare}(\mu, \sigma)(x) = \exp\left(-\frac{(\log x - \mu)^2}{2\sigma^2}\right)\]
Typically used in composed form with log:
# Computes E_q[-(log x - μ)² / (2σ²)]
BayesBase.expectation(ClosedFormExpectation(), log ∘ ExpLogSquare(μ, σ), q)Square
ClosedFormExpectations.Square — Type
SquareSquare is a type that represents the x^2 function.
Represents $x^2$. Typically used composed with log to compute expectations of $(\log x)^2$:
# Computes E_q[(log x)²]
BayesBase.expectation(ClosedFormExpectation(), Square() ∘ log, q)Power
ClosedFormExpectations.Power — Type
Power
Power is a type that represents the x^N function.
Represents $x^N$ for compile-time constant $N$. Used composed with log:
# Computes E_q[(log x)³]
BayesBase.expectation(ClosedFormExpectation(), Power(Val(3)) ∘ log, q)Abs
ClosedFormExpectations.Abs — Type
AbsExpression type representing the absolute value function $|x|$.
Represents the absolute value function $|x|$:
# Computes E_q[|x|] where q is Normal
BayesBase.expectation(ClosedFormExpectation(), Abs(), Normal(0, 1))Product
ClosedFormExpectations.Product — Type
Product(multipliers)Expression type representing a product of multiple functions. When composed with log, the product decomposes into a sum of logarithms.
Represents a product of multiple expressions. When composed with log, the logarithm of the product decomposes into a sum:
\[\mathbb{E}_q[\log(f_1 \cdot f_2 \cdots f_n)] = \sum_i \mathbb{E}_q[\log f_i]\]
Standalone Functions
xlog2x
ClosedFormExpectations.xlog2x — Function
Return x * log(x)^2 for x ≥ 0, handling $x = 0$ by taking the downward limit.
julia> xlog2x(0)
0.0Computes $x (\log x)^2$ with proper handling of $x = 0$.
xlogx
The package also uses xlogx from LogExpFunctions.jl, which computes $x \log x$.