probabilistic-numerics / probnum

Probabilistic Numerics in Python.
http://probnum.org
MIT License
434 stars 56 forks source link

Refactor normal distribution into protected subclasses #16

Closed JonathanWenger closed 4 years ago

JonathanWenger commented 4 years ago

Write an (abstract) superclass Normal which has subclasses:

The _MatrixvariateNormal class should implement specific methods for (symmetric) Kronecker structured covariance. Maybe it could have two subclasses:

This relates to #15 .

JonathanWenger commented 4 years ago

Subclasses

* `_UnivariateNormal`

* `_MultivariateNormal`

* `_MatrixvariateNormal`

* `_OperatorvariateNormal`

implemented by f3601622ff8f2cec3b7c23eb3b8464910649c550 and 6035e98cf4f719eec19b0531ec0e6c3b1d4e6f08.

JonathanWenger commented 4 years ago

The structural assumptions allow implementation of faster sampling and density evaluation methods than the naive implementation, in particular for Kronecker structured covariances.

pnkraemer commented 4 years ago

I found it a lot easier to just have a MultivariateGaussian class, for compatibility reasons. It was way easier to write the code such that everything is a (d,), respectively (d, d) numpy array. UnivariateNormal could be automatically turned into a MultivariateGaussian. MatrixvariateNormal classes would have the same structure anyway, no? Is the speedup noticeable for Kronecker-structured covariances?

JonathanWenger commented 4 years ago

It looks the way to the user as you described, there being only on class Normal that is public. However we need the subclass structure to reduce complexity. There is a substantial speedup for kronecker structured covariances, i.e. Sigma^{-1} in O(n^3) vs O(n^6) for matrix-variate normal distributions.

Regarding shapes of random variable realizations, we can discuss that in #39 .