Installation (v1.0 and up):
pkg> add Expectations
This is a package designed to simplify the process of taking expectations of functions of random variables.
The underlying distributions are objects from
We support different types of Gaussian quadrature (Gauss-Hermite, Gauss-Legendre, Gauss-Laguerre, etc.) based on the distribution, as well as some methods with user-defined nodes (e.g., trapezoidal integration).
The key object is the
expectation function, which returns an operator:
dist = Normal() E = expectation(dist) E(x -> x)
For convenience, the operator can be applied directly to a function instead of being cached,
As a linear operator on vectors using the nodes of the distribution
dist = Normal() E = expectation(dist) x = nodes(E) f(x) = x^2 E * f.(x) == dot(f.(x), weights(E))