mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
cmu_mocap() example mostly working except some fiddling with axes for visualization. Also changes to naming of scaling and offset parameters in GP.py and deal with the case where the scale parameter is zero.
This commit is contained in:
parent
d7ac1d025b
commit
ac842d51e6
6 changed files with 202 additions and 98 deletions
|
|
@ -2,19 +2,30 @@ import numpy as np
|
|||
from likelihood import likelihood
|
||||
|
||||
class Gaussian(likelihood):
|
||||
"""
|
||||
Likelihood class for doing Expectation propagation
|
||||
|
||||
:param Y: observed output (Nx1 numpy.darray)
|
||||
..Note:: Y values allowed depend on the likelihood_function used
|
||||
:param variance :
|
||||
:param normalize: whether to normalize the data before computing (predictions will be in original scales)
|
||||
:type normalize: False|True
|
||||
"""
|
||||
def __init__(self,data,variance=1.,normalize=False):
|
||||
self.is_heteroscedastic = False
|
||||
self.Nparams = 1
|
||||
self.Z = 0. # a correction factor which accounts for the approximation made
|
||||
N, self.D = data.shape
|
||||
|
||||
#normaliztion
|
||||
#normalization
|
||||
if normalize:
|
||||
self._mean = data.mean(0)[None,:]
|
||||
self._std = data.std(0)[None,:]
|
||||
self._bias = data.mean(0)[None,:]
|
||||
self._scale = data.std(0)[None,:]
|
||||
# Don't scale outputs which have zero variance to zero.
|
||||
self._scale[np.nonzero(self._scale==0.)] = 1.0e-3
|
||||
else:
|
||||
self._mean = np.zeros((1,self.D))
|
||||
self._std = np.ones((1,self.D))
|
||||
self._bias = np.zeros((1,self.D))
|
||||
self._scale = np.ones((1,self.D))
|
||||
|
||||
self.set_data(data)
|
||||
|
||||
|
|
@ -24,7 +35,7 @@ class Gaussian(likelihood):
|
|||
self.data = data
|
||||
self.N,D = data.shape
|
||||
assert D == self.D
|
||||
self.Y = (self.data - self._mean)/self._std
|
||||
self.Y = (self.data - self._bias)/self._scale
|
||||
if D > self.N:
|
||||
self.YYT = np.dot(self.Y,self.Y.T)
|
||||
self.trYYT = np.trace(self.YYT)
|
||||
|
|
@ -47,19 +58,19 @@ class Gaussian(likelihood):
|
|||
"""
|
||||
Un-normalize the prediction and add the likelihood variance, then return the 5%, 95% interval
|
||||
"""
|
||||
mean = mu*self._std + self._mean
|
||||
mean = mu*self._scale + self._bias
|
||||
if full_cov:
|
||||
if self.D >1:
|
||||
raise NotImplementedError, "TODO"
|
||||
#Note. for D>1, we need to re-normalise all the outputs independently.
|
||||
# This will mess up computations of diag(true_var), below.
|
||||
#note that the upper, lower quantiles should be the same shape as mean
|
||||
true_var = (var + np.eye(var.shape[0])*self._variance)*self._std**2
|
||||
_5pc = mean + - 2.*np.sqrt(np.diag(true_var))
|
||||
true_var = (var + np.eye(var.shape[0])*self._variance)*self._scale**2
|
||||
_5pc = mean - 2.*np.sqrt(np.diag(true_var))
|
||||
_95pc = mean + 2.*np.sqrt(np.diag(true_var))
|
||||
else:
|
||||
true_var = (var + self._variance)*self._std**2
|
||||
_5pc = mean + - 2.*np.sqrt(true_var)
|
||||
true_var = (var + self._variance)*self._scale**2
|
||||
_5pc = mean - 2.*np.sqrt(true_var)
|
||||
_95pc = mean + 2.*np.sqrt(true_var)
|
||||
return mean, true_var, _5pc, _95pc
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue