variouschanges

This commit is contained in:
James Hensman 2014-02-13 13:53:49 +00:00
parent 83d3389644
commit 80a734e153
4 changed files with 20 additions and 10 deletions

View file

@ -33,7 +33,8 @@ class Transformation(object):
class Logexp(Transformation): class Logexp(Transformation):
domain = _POSITIVE domain = _POSITIVE
def f(self, x): def f(self, x):
return np.where(x>_lim_val, x, np.log(1. + np.exp(x))) return np.where(x>_lim_val, x, np.log(1. + np.exp(np.clip(x, -np.inf, _lim_val))))
#raises overflow warning: return np.where(x>_lim_val, x, np.log(1. + np.exp(x)))
def finv(self, f): def finv(self, f):
return np.where(f>_lim_val, f, np.log(np.exp(f) - 1.)) return np.where(f>_lim_val, f, np.log(np.exp(f) - 1.))
def gradfactor(self, f): def gradfactor(self, f):

View file

@ -44,9 +44,8 @@ class DTC(object):
Kmmi, L, Li, _ = pdinv(Kmm) Kmmi, L, Li, _ = pdinv(Kmm)
# Compute A # Compute A
#LiUT, _ = dtrtrs(L, U.T*np.sqrt(beta), lower=1) LiUTbeta = np.dot(Li, U.T)*np.sqrt(beta)
LiUT = np.dot(Li, U.T)*np.sqrt(beta) A = tdot(LiUTbeta) + np.eye(num_inducing)
A = tdot(LiUT) + np.eye(num_inducing)
# factor A # factor A
LA = jitchol(A) LA = jitchol(A)

View file

@ -2,7 +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, tdot, dtrtrs, dpotri, symmetrify from ...util.linalg import pdinv, dpotrs, tdot, dtrtrs, dpotri, symmetrify, jitchol, dtrtri
class Posterior(object): class Posterior(object):
""" """
@ -80,8 +80,8 @@ class Posterior(object):
@property @property
def covariance(self): def covariance(self):
if self._covariance is None: if self._covariance is None:
LiK, _ = dtrtrs(self.woodbury_chol, self._K, lower=1) #LiK, _ = dtrtrs(self.woodbury_chol, self._K, lower=1)
self._covariance = self._K - tdot(LiK.T) self._covariance = self._K - self._K.dot(self.woodbury_inv).dot(self._K)
return self._covariance return self._covariance
@property @property
@ -93,20 +93,30 @@ class Posterior(object):
@property @property
def woodbury_chol(self): def woodbury_chol(self):
if self._woodbury_chol is None: if self._woodbury_chol is None:
#try computing woodbury chol from cov #compute woodbury chol from
if self._woodbury_inv is not None: if self._woodbury_inv is not None:
_, _, self._woodbury_chol, _ = pdinv(self._woodbury_inv) _, _, self._woodbury_chol, _ = pdinv(self._woodbury_inv)
#Li = jitchol(self._woodbury_inv)
#self._woodbury_chol, _ = dtrtri(Li)
#W, _, _, _, = pdinv(self._woodbury_inv)
#symmetrify(W)
#self._woodbury_chol = jitchol(W)
#try computing woodbury chol from cov
elif self._covariance is not None: elif self._covariance is not None:
raise NotImplementedError, "TODO: check code here"
B = self._K - self._covariance B = self._K - self._covariance
tmp, _ = dpotrs(self.K_chol, B) tmp, _ = dpotrs(self.K_chol, B)
self._woodbury_inv, _ = dpotrs(self.K_chol, tmp.T) self._woodbury_inv, _ = dpotrs(self.K_chol, tmp.T)
_, _, self._woodbury_chol, _ = pdinv(self._woodbury_inv) _, _, self._woodbury_chol, _ = pdinv(self._woodbury_inv)
else:
raise ValueError, "insufficient information to compute posterior"
return self._woodbury_chol return self._woodbury_chol
@property @property
def woodbury_inv(self): def woodbury_inv(self):
if self._woodbury_inv is None: if self._woodbury_inv is None:
self._woodbury_inv, _ = dpotri(self.woodbury_chol) self._woodbury_inv, _ = dpotri(self.woodbury_chol, lower=0)
#self._woodbury_inv, _ = dpotrs(self.woodbury_chol, np.eye(self.woodbury_chol.shape[0]), lower=1)
symmetrify(self._woodbury_inv) symmetrify(self._woodbury_inv)
return self._woodbury_inv return self._woodbury_inv

View file

@ -34,7 +34,7 @@ class VarDTC(object):
Note that L may have fewer columns than Y. Note that L may have fewer columns than Y.
""" """
N, D = Y.shape N, D = Y.shape
if (N>D): if (N>=D):
return param_to_array(Y) return param_to_array(Y)
else: else:
return jitchol(tdot(Y)) return jitchol(tdot(Y))