[mlpack-git] [mlpack] GaussianDistribution should cache covariance matrix factorization (#385)

Ryan Curtin notifications at github.com
Fri Jan 16 17:58:56 EST 2015


This is related to #215.

There is a slight issue with making this change: what happens to this code?

```
GaussianDistribution g(mean, covariance); // This factorizes 'covariance'.
g.Covariance() = newCovariance; // The new covariance isn't factorized.
```

It's easy enough to change the signature...

```
GaussianDistribution g(mean, covariance); // This factorizes 'covariance'.
g.Covariance(newCovariance); // This re-factorizes 'covariance'.
```

but now I can't make simple changes to the covariance while avoiding matrix copies.  So this code becomes impossible:

```
GaussianDistribution g(mean, covariance); // This factorizes 'covariance'.
// Recalculate covariance.
g.Covariance().zeros();
for (size_t i = 0; i < numPoints; ++i)
  g.Covariance() += x.col(i) * x.col(i).t(); // Or something like that.
```

Maybe the better API solution is to leave `GaussianDistribution::Covariance()` intact, allowing direct access to the covariance matrix, but make a note that if the covariance matrix is modified, the user *must* call something like `GaussianDistribution::InvertCovariance()` or whatever after the modification is done, or `Probability()` will return incorrect results.

---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/issues/385#issuecomment-70336533
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20150116/1418df78/attachment.html>


More information about the mlpack-git mailing list