probabilistic-numerics / probnum

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

Initialization of Gaussian random variables #226

Open JonathanWenger opened 4 years ago

JonathanWenger commented 4 years ago

Currently when initializing a normal random variable one cannot simply specify a Cholesky factor of the covariance but has to pass a covariance as well.

import numpy as np
from probnum.random_variables import Normal

Normal(mean=np.zeros(5), cov_cholesky=np.eye(5))
# TypeError: __init__() missing 1 required positional argument: 'cov'

Normal(mean=np.zeros(5), cov=np.eye(5), cov_cholesky=np.eye(5))
# <(5,) Normal with dtype=float64>

The desired behaviour as discussed in the software meeting is to only allow construction with either a covariance, a cholesky factor, a diagonal vector of singular values and an orthogonal matrix or a vector of eigenvalues and an orthogonal matrix.

This avoids inconsistencies between covariance and matrix root at the expense of having to compute the full covariance via a matrix-matrix multiplication. This behavior is also consistent with tensorflow.

One way to implement this would be to use @classmethods (from_cholesky, from_svd, from_eigendecomposition) and an __init__(mean, cov, random_state).

pnkraemer commented 3 years ago

I can try to do this. I might have some Normal questions though.

How many of those do we want? I'd need a from_cholesky. Is there demand for from_svd or from_eigen(decomposition)? If not, I'll only do the cholesky/matrix-square-root.

JonathanWenger commented 3 years ago

We need from_svd as well for LinearOperators where one can compute the SVD but not the cholesky decomposition.