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

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

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

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

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.

source

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

Computes $x (\log x)^2$ with proper handling of $x = 0$.

xlogx

The package also uses xlogx from LogExpFunctions.jl, which computes $x \log x$.