mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-10 20:42:39 +02:00
Merge branch 'devel' into devel
This commit is contained in:
commit
e623078954
1 changed files with 14 additions and 23 deletions
|
|
@ -578,7 +578,7 @@ class GP(Model):
|
||||||
mag[n] = np.sqrt(np.linalg.det(G[n, :, :]))
|
mag[n] = np.sqrt(np.linalg.det(G[n, :, :]))
|
||||||
return mag
|
return mag
|
||||||
|
|
||||||
def posterior_samples_f(self,X, size=10, full_cov=True, **predict_kwargs):
|
def posterior_samples_f(self,X, size=10, **predict_kwargs):
|
||||||
"""
|
"""
|
||||||
Samples the posterior GP at the points X.
|
Samples the posterior GP at the points X.
|
||||||
|
|
||||||
|
|
@ -586,35 +586,28 @@ class GP(Model):
|
||||||
:type X: np.ndarray (Nnew x self.input_dim)
|
:type X: np.ndarray (Nnew x self.input_dim)
|
||||||
:param size: the number of a posteriori samples.
|
:param size: the number of a posteriori samples.
|
||||||
:type size: int.
|
:type size: int.
|
||||||
:param full_cov: whether to return the full covariance matrix, or just the diagonal.
|
:returns: set of simulations
|
||||||
:type full_cov: bool.
|
:rtype: np.ndarray (Nnew x D x samples)
|
||||||
:returns: fsim: set of simulations
|
|
||||||
:rtype: np.ndarray (D x N x samples) (if D==1 we flatten out the first dimension)
|
|
||||||
"""
|
"""
|
||||||
m, v = self._raw_predict(X, full_cov=full_cov, **predict_kwargs)
|
m, v = self._raw_predict(X, full_cov=True, **predict_kwargs)
|
||||||
if self.normalizer is not None:
|
if self.normalizer is not None:
|
||||||
m, v = self.normalizer.inverse_mean(m), self.normalizer.inverse_variance(v)
|
m, v = self.normalizer.inverse_mean(m), self.normalizer.inverse_variance(v)
|
||||||
|
|
||||||
def sim_one_dim(m, v):
|
def sim_one_dim(m, v):
|
||||||
if not full_cov:
|
return np.random.multivariate_normal(m, v, size).T
|
||||||
return np.random.multivariate_normal(m.flatten(), np.diag(v.flatten()), size).T
|
|
||||||
else:
|
|
||||||
return np.random.multivariate_normal(m.flatten(), v, size).T
|
|
||||||
|
|
||||||
if self.output_dim == 1:
|
if self.output_dim == 1:
|
||||||
return sim_one_dim(m, v)
|
return sim_one_dim(m.flatten(), v)[:, np.newaxis, :]
|
||||||
else:
|
else:
|
||||||
fsim = np.empty((self.output_dim, X.shape[0], size))
|
fsim = np.empty((X.shape[0], self.output_dim, size))
|
||||||
for d in range(self.output_dim):
|
for d in range(self.output_dim):
|
||||||
if full_cov and v.ndim == 3:
|
if v.ndim == 3:
|
||||||
fsim[d] = sim_one_dim(m[:, d], v[:, :, d])
|
fsim[:, d, :] = sim_one_dim(m[:, d], v[:, :, d])
|
||||||
elif (not full_cov) and v.ndim == 2:
|
|
||||||
fsim[d] = sim_one_dim(m[:, d], v[:, d])
|
|
||||||
else:
|
else:
|
||||||
fsim[d] = sim_one_dim(m[:, d], v)
|
fsim[:, d, :] = sim_one_dim(m[:, d], v)
|
||||||
return fsim
|
return fsim
|
||||||
|
|
||||||
def posterior_samples(self, X, size=10, full_cov=False, Y_metadata=None, likelihood=None, **predict_kwargs):
|
def posterior_samples(self, X, size=10, Y_metadata=None, likelihood=None, **predict_kwargs):
|
||||||
"""
|
"""
|
||||||
Samples the posterior GP at the points X.
|
Samples the posterior GP at the points X.
|
||||||
|
|
||||||
|
|
@ -622,19 +615,17 @@ class GP(Model):
|
||||||
:type X: np.ndarray (Nnew x self.input_dim.)
|
:type X: np.ndarray (Nnew x self.input_dim.)
|
||||||
:param size: the number of a posteriori samples.
|
:param size: the number of a posteriori samples.
|
||||||
:type size: int.
|
:type size: int.
|
||||||
:param full_cov: whether to return the full covariance matrix, or just the diagonal.
|
|
||||||
:type full_cov: bool.
|
|
||||||
:param noise_model: for mixed noise likelihood, the noise model to use in the samples.
|
:param noise_model: for mixed noise likelihood, the noise model to use in the samples.
|
||||||
:type noise_model: integer.
|
:type noise_model: integer.
|
||||||
:returns: Ysim: set of simulations,
|
:returns: Ysim: set of simulations,
|
||||||
:rtype: np.ndarray (D x N x samples) (if D==1 we flatten out the first dimension)
|
:rtype: np.ndarray (D x N x samples) (if D==1 we flatten out the first dimension)
|
||||||
"""
|
"""
|
||||||
fsim = self.posterior_samples_f(X, size, full_cov=full_cov, **predict_kwargs)
|
fsim = self.posterior_samples_f(X, size, **predict_kwargs)
|
||||||
if likelihood is None:
|
if likelihood is None:
|
||||||
likelihood = self.likelihood
|
likelihood = self.likelihood
|
||||||
if fsim.ndim == 3:
|
if fsim.ndim == 3:
|
||||||
for d in range(fsim.shape[0]):
|
for d in range(fsim.shape[1]):
|
||||||
fsim[d] = likelihood.samples(fsim[d], Y_metadata=Y_metadata)
|
fsim[:, d] = likelihood.samples(fsim[:, d], Y_metadata=Y_metadata)
|
||||||
else:
|
else:
|
||||||
fsim = likelihood.samples(fsim, Y_metadata=Y_metadata)
|
fsim = likelihood.samples(fsim, Y_metadata=Y_metadata)
|
||||||
return fsim
|
return fsim
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue