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 — Function
moment(α, p)Creates the moment of the polynomial p 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 — Function
moment_value(m::AbstractMomentLike)Returns the value of the moment m.
Examples
Calling moment_value(moment(3.1, x*y^2)) should return 3.1.
Measure
Given a monomials and a values for the moments, a "moment vector" can be created using the moment_vector function
MultivariateMoments.moment_vector — Function
moment_vector(values::AbstractVector{T}, monos::AbstractVector{<:AbstractMonomial}; rtol=Base.rtoldefault(T), atol=zero(T))Creates a measure with moments moment(values[i], monos[i]) for each i. An error is thrown if there exists i and j such that monos[i] == monos[j] but !isapprox(values[i], values[j]; rtol=rtol, atol=atol).
The moment_vector 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 — Method
variables(μ::MomentVector)Returns the variables of μ in decreasing order. Just like in MultivariatePolynomials, it could contain variables of zero degree in every monomial.
MultivariatePolynomials.maxdegree — Method
maxdegree(μ::AbstractMeasureLike)Returns the maximal degree of the monomials of μ.
MultivariatePolynomials.mindegree — Method
mindegree(μ::MomentVector)Returns the minimal degree of the monomials of μ.
MultivariatePolynomials.extdegree — Method
extdegree(μ::MomentVector)Returns the extremal degrees of the monomials of μ.
MultivariateMoments.moments — Function
moments(μ::MomentVector)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 — Function
dirac(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 — Function
MultivariateMoments.expectation(μ::AbstractMeasureLike, p::AbstractPolynomialLike)
MultivariateMoments.expectation(p::AbstractPolynomialLike, μ::AbstractMeasureLike)Computes the expectation $\mathbb{E}_{\mu}[p]$.
LinearAlgebra.dot — Function
dot(μ::AbstractMeasureLike, p::AbstractPolynomialLike)
dot(p::AbstractPolynomialLike, μ::AbstractMeasureLike)See expectation