more work on the posterior class

This commit is contained in:
James Hensman 2013-12-06 11:48:32 -08:00
parent 83a49f132a
commit ee68377f5e

View file

@ -2,6 +2,7 @@
# Licensed under the BSD 3-clause license (see LICENSE.txt) # Licensed under the BSD 3-clause license (see LICENSE.txt)
import numpy as np import numpy as np
from ...util.linalg import pdinv, dpotrs
class Posterior(object): class Posterior(object):
""" """
@ -42,6 +43,8 @@ class Posterior(object):
cov cov
K_chol (for lazy computation) K_chol (for lazy computation)
Of course, you can supply more than that, but this class will lazily compute all other quantites on demand.
From the supplied quantities, all of the others will be computed on demand (lazy computation) From the supplied quantities, all of the others will be computed on demand (lazy computation)
""" """
@ -84,20 +87,23 @@ class Posterior(object):
@property @property
def precision(self): def precision(self):
if self._precision is None: if self._precision is None:
self._precision = np.linalg.inv(self.covariance) self._precision, _, _, _ = pdinv(self.covariance)
return self._precision return self._precision
@property @property
def woodbury_chol(self): def woodbury_chol(self):
if self._woodbury_chol is None: if self._woodbury_chol is None:
??? B = self._K - self._covariance
tmp, _ = dpotrs(self._K_chol, B)
Wi, _ = dpotrs(self._K_chol, tmp.T)
_, _, self._woodbury_chol, _ = pdinv(Wi)
else: else:
return self._woodbury_chol return self._woodbury_chol
@property @property
def woodbury_vector(self): def woodbury_vector(self):
if self._woodbury_vector is None: if self._woodbury_vector is None:
??? self._woodbury_vector, _ = dpotrs(self._K_chol, self.mean)
else: else:
return self._woodbury_vector return self._woodbury_vector