From 9780fb48dea508b1219c000219986dc10e57944e Mon Sep 17 00:00:00 2001 From: James Hensman Date: Thu, 13 Aug 2015 12:07:01 +0100 Subject: [PATCH] fixing qualtile code for some likelhoods --- GPy/likelihoods/bernoulli.py | 11 +++++++++++ GPy/likelihoods/poisson.py | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/GPy/likelihoods/bernoulli.py b/GPy/likelihoods/bernoulli.py index e540f016..3a7d32a5 100644 --- a/GPy/likelihoods/bernoulli.py +++ b/GPy/likelihoods/bernoulli.py @@ -232,6 +232,17 @@ class Bernoulli(Likelihood): np.seterr(**state) return d3logpdf_dlink3 + def predictive_quantiles(self, mu, var, quantiles, Y_metadata=None): + """ + Get the "quantiles" of the binary labels (Bernoulli draws). all the + quantiles must be either 0 or 1, since those are the only values the + draw can take! + """ + p = self.predictive_mean(mu, var) + return [np.asarray(p>(q/100.), dtype=np.int32) for q in quantiles] + + + def samples(self, gp, Y_metadata=None): """ Returns a set of samples of observations based on a given value of the latent variable. diff --git a/GPy/likelihoods/poisson.py b/GPy/likelihoods/poisson.py index 5aa85a91..1c3fec9e 100644 --- a/GPy/likelihoods/poisson.py +++ b/GPy/likelihoods/poisson.py @@ -137,7 +137,7 @@ class Poisson(Likelihood): """ return self.gp_link.transf(gp) - def samples(self, gp, Y_metadata=None): + def samples(self, gp, Y_metadata=None, samples=1): """ Returns a set of samples of observations based on a given value of the latent variable. @@ -145,5 +145,5 @@ class Poisson(Likelihood): """ orig_shape = gp.shape gp = gp.flatten() - Ysim = np.random.poisson(self.gp_link.transf(gp)) - return Ysim.reshape(orig_shape) + Ysim = np.random.poisson(self.gp_link.transf(gp), [samples, gp.size]).T + return Ysim.reshape(orig_shape+(samples,))