JuliaStats / Distributions.jl

A Julia package for probability distributions and associated functions.
Other
1.08k stars 410 forks source link

No characteristic function of MvNormal #1841

Open jaksle opened 3 months ago

jaksle commented 3 months ago

This is pretty confusing. The characteristic function of multivariate normal distribution cf(d::MvNormal, t::AbstractVector) is the simplest thing there is for it, and it seems it is not implemented! (The same for mgf.)

I could try adding it myself, but I see the current implementation of MvNormal is careful in handling general AbstractMatrix/AbstractVector as covariance matrix and mean vector, so that calculations are always efficient and I am not sure how to replicate that.

sethaxen commented 3 months ago

I think something like this would be sufficient:

_quad(d::AbstractMvNormal, t::AbstractVector) = dot(t, cov(d), t)
_quad(d::MvNormal, t::AbstractVector) = PDMats.quad(cov(d), t)
_quad(d::MvNormalCanon, t::AbstractVector) = PDMats.invquad(d.J, t)

function cf(d::AbstractMvNormal, t::AbstractVector)
    return exp(im * dot(mean(d), t) - _quad(d, t) / 2)
end

function mgf(d::AbstractMvNormal, t::AbstractVector)
    return exp(dot(mean(d), t) + _quad(d, t) / 2)
end
jaksle commented 3 months ago

Thanks! This looks simple and good.