Moments and expectation
Moment
Given a measure $\mu$ and a monomial $m$, the moment $m$ of the measure is defined by the expectation $\mathbb{E}_\mu[m]$. Given a monomial and a value for the moment, a moment can be created using the moment
function
MultivariateMoments.moment
— Functionmoment(α, m::AbstractMonomial)
Creates the moment of the monomial m
of value α
.
The moment
function returns an AbstractMoment
which is a subtype of AbstractMomentLike
. An AbstractMomentLike
is a type that can act like an AbstractMoment
(it is similar to MultivariatePolynomials' AbstractMonomialLike
, AbstractTermLike
and AbstractPolynomialLike
), that is, it implements the following two functions
MultivariateMoments.moment_value
— Functionmoment_value(m::AbstractMomentLike)
Returns the value of the moment m
.
Examples
Calling moment_value(moment(3.1, x*y^2))
should return 3.1
.
MultivariatePolynomials.monomial
— Methodmonomial(m::AbstractMomentLike)
Returns the monomial of the moment m
.
Examples
Calling monomial(moment(3.1, x*y^2))
should return x*y^2
.
Measure
Given a monomials and a values for the moments, a "measure" can be created using the measure
function
MultivariateMoments.measure
— Functionmeasure(a::AbstractVector{T}, X::AbstractVector{<:AbstractMonomial}; rtol=Base.rtoldefault(T), atol=zero(T))
Creates a measure with moments moment(a[i], X[i])
for each i
. An error is thrown if there exists i
and j
such that X[i] == X[j]
but !isapprox(a[i], a[j]; rtol=rtol, atol=atol)
.
The measure
function returns an AbstractMeasure
which is a subtype of AbstractMeasureLike
. Note that it does not actually compute the probability density function of a measure having these moments, it simply stores a vector of moments belonging to a hypothetical measure. However, it acts like a measure when taking its scalar product with a polynomial.
An AbstractMeasureLike
is a type that can act like an AbstractMeasure
, that is, it implements the following two functions
MultivariatePolynomials.variables
— Methodvariables(μ::AbstractMeasureLike)
Returns the variables of μ
in decreasing order. Just like in MultivariatePolynomials, it could contain variables of zero degree in every monomial.
MultivariatePolynomials.monomials
— Methodmonomials(μ::AbstractMeasureLike)
Returns an iterator over the monomials of μ
sorted in the decreasing order.
MultivariatePolynomials.maxdegree
— Methodmaxdegree(μ::AbstractMeasureLike)
Returns the maximal degree of the monomials of μ
.
MultivariatePolynomials.mindegree
— Methodmindegree(μ::AbstractMeasureLike)
Returns the minimal degree of the monomials of μ
.
MultivariatePolynomials.extdegree
— Methodextdegree(μ::AbstractMeasureLike)
Returns the extremal degrees of the monomials of μ
.
MultivariateMoments.moments
— Functionmoments(μ::AbstractMeasureLike)
Returns an iterator over the moments of μ
sorted in decreasing order of monomial.
The moments of the dirac measure for a vector of monomials can be obtained by the dirac
function
MultivariateMoments.dirac
— Functiondirac(X::AbstractVector{<:AbstractMoment}, s::AbstractSubstitution...)
Creates the dirac measure by evaluating the moments of X
using s
.
Examples
Calling dirac([x*y, x*y^2], x=>3, y=>2)
should the measure with moment x*y
of value 6
and moment x*y^2
of value 12
.
Expectation
The expectation of polynomial with respect to a measure can be computed either using MultivariateMoments.expectation
or using the Base.dot
scalar product.
MultivariateMoments.expectation
— FunctionMultivariateMoments.expectation(μ::AbstractMeasureLike, p::AbstractPolynomialLike)
MultivariateMoments.expectation(p::AbstractPolynomialLike, μ::AbstractMeasureLike)
Computes the expectation $\mathbb{E}_{\mu}[p]$.
LinearAlgebra.dot
— Functiondot(μ::AbstractMeasureLike, p::AbstractPolynomialLike)
dot(p::AbstractPolynomialLike, μ::AbstractMeasureLike)
See expectation