Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linear transformations on MvNormal #307

Closed
goretkin opened this issue Nov 11, 2014 · 10 comments · Fixed by #1051
Closed

linear transformations on MvNormal #307

goretkin opened this issue Nov 11, 2014 · 10 comments · Fixed by #1051

Comments

@goretkin
Copy link

Are these functions within the scope of the package? These seem harmless

+(x::AbstractVector,n::MvNormal) = MvNormal(n.μ+x,n.Σ)
+(n::MvNormal,x::AbstractVector) = MvNormal(n.μ+x,n.Σ)
Xt_A_X
*(A::AbstractMatrix,n::MvNormal) = MvNormal(A*n.μ,  PDMats.Xt_A_X(n.Σ,A)  )

More contentious is allowing +(x::MvNormal,y::MvNormal), assuming independence.

My main motivation was from seeing the StateSpace package that @ElOceanografo wrote. For example: https://github.com/ElOceanografo/StateSpace.jl/blob/master/src/KalmanFilter.jl#L49 . Having functions for linear transformations of Multivariate Normal distributions might improve readability in only a minor way, but they might be worth including in Distributions anyway.

@johnmyleswhite
Copy link
Member

Dup of #298?

@lindahua
Copy link
Contributor

Linear transformations are more than scaling. I think this issue can stay as a separate one.

@lindahua lindahua added this to the v0.7 milestone Nov 11, 2014
@lindahua lindahua removed this from the v0.9 milestone Jul 29, 2015
@mschauer
Copy link
Member

I am running into the same problem trying to port a Kalman filter now from
https://github.com/mschauer/GaussianDistributions.jl/blob/master/src/GaussianDistributions.jl
to Distributions. How do you see this?

@simonbyrne
Copy link
Member

It would be good to have some way to do this, at least for constants. Mathematically, I'm a bit reluctant to overload +/* directly: the objects are intended to be distributions, not random variables. But maybe that isn't such a big deal?

Alternatively we could overload map (e.g. so that you would do map(x -> x + k, d)), but that would require much more "plumbing" to get it to work.

@goretkin
Copy link
Author

goretkin commented Oct 12, 2018 via email

@mschauer
Copy link
Member

For example you would not overload +(A::RandomVariable,B::RandomVariable) because the result depends on whether RVs are dependent and the independent sum deserves a new symbol like ⊕. But +(A::Vector, B::MvNormal) and *(A::Matrix B::MvNormal) can only mean one thing imho.

@simonbyrne
Copy link
Member

I mean, the only other interpretation it could mean would be transforming it as a measure, but (a) that isn't very useful (since it would no longer be a probability measure), and (b) we don't treat it as a measure in other contexts, e.g. defining (d::Distribution)(x::Interval) to get the probability of an interval.

independent sum deserves a new symbol like ⊕

That's a great idea!

@mschauer
Copy link
Member

One thing, for scalar λ the expression λ*D1 + (1-λ)*D2 could denote a mixture distribution.

matbesancon pushed a commit that referenced this issue Jan 10, 2020
* Add affine transformations for MvNormal.

Fixes #307.

* Update src/multivariate/mvnormal.jl

Co-Authored-By: Moritz Schauer <moritzschauer@web.de>

* consistently define methods with MvNormal first, remove @inline

Co-authored-by: Moritz Schauer <moritzschauer@web.de>
@matbesancon
Copy link
Member

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Registration pull request created: JuliaRegistries/General/7761

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.22.1 -m "<description of version>" 16ba0b4cb040f87a098377bd01fd62161c6c4491
git push origin v0.22.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants