Small tidying up

This commit is contained in:
Alan Saul 2015-03-27 14:24:24 +00:00
parent 3c7a1b9a91
commit 4d27fddd37
2 changed files with 1 additions and 39 deletions

View file

@ -248,41 +248,3 @@ class Bernoulli(Likelihood):
def exact_inference_gradients(self, dL_dKdiag,Y_metadata=None):
pass
def variational_expectations(self, Y, m, v, gh_points=None):
"""
Probit specific numerical stable integrations
"""
#Move to be faster
if self.gp_link:
pass
Yshape = Y.shape
mshape = m.shape
vshape = v.shape
Y = Y.flatten()
m = m.flatten()
v = v.flatten()
assert Yshape == mshape
assert mshape == vshape
Ysign = np.where(Y==1,1,-1).flatten()
gh_x, gh_w = np.polynomial.hermite.hermgauss(20)
#Shapes a bit weird
X = gh_x[None,:]*np.sqrt(2.*v[:, None]) + (m*Ysign)[:,None]
p = stats.norm.cdf(X)
p = np.clip(p, 1e-9, 1.-1e-9) # for numerical stability
N = stats.norm.pdf(X)
F = np.log(p).dot(gh_w)
NoverP = N/p
dF_dm = (NoverP*Ysign[:,None]).dot(gh_w)
dF_dv = -0.5*(NoverP**2 + NoverP*X).dot(gh_w)
if np.any(np.isnan(dF_dv)) or np.any(np.isinf(dF_dv)):
stop
if np.any(np.isnan(dF_dm)) or np.any(np.isinf(dF_dm)):
stop
#FIXME: Might be wrong reshaping
return F.reshape(Yshape), dF_dm.reshape(mshape), dF_dv.reshape(vshape), None

View file

@ -325,7 +325,7 @@ class Likelihood(Parameterized):
def logpdf_sum(self, f, y, Y_metadata=None):
"""
Convenience function that can overridden for functions where this could
be computed more efficiently (Theano?)
be computed more efficiently
"""
return np.sum(self.logpdf(f, y, Y_metadata=Y_metadata))