mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
very basic functionality is now working
This commit is contained in:
parent
bdc89170d4
commit
d077d28fd1
10 changed files with 88 additions and 284 deletions
|
|
@ -1,12 +1,9 @@
|
|||
import numpy as np
|
||||
import random
|
||||
import pylab as pb #TODO erase me
|
||||
from scipy import stats, linalg
|
||||
from .likelihoods import likelihood
|
||||
from ..core import model
|
||||
from ..util.linalg import pdinv,mdot,jitchol
|
||||
from ..util.plot import gpplot
|
||||
from .. import kern
|
||||
|
||||
class EP:
|
||||
def __init__(self,data,likelihood_function,epsilon=1e-3,power_ep=[1.,1.]):
|
||||
|
|
@ -15,12 +12,8 @@ class EP:
|
|||
|
||||
Arguments
|
||||
---------
|
||||
X : input observations
|
||||
likelihood : Output's likelihood (likelihood class)
|
||||
kernel : a GPy kernel (kern class)
|
||||
inducing : Either an array specifying the inducing points location or a sacalar defining their number. None value for using a non-sparse model is used.
|
||||
power_ep : Power-EP parameters (eta,delta) - 2x1 numpy array (floats)
|
||||
epsilon : Convergence criterion, maximum squared difference allowed between mean updates to stop iterations (float)
|
||||
likelihood_function : a likelihood function (see likelihood_functions.py)
|
||||
"""
|
||||
self.likelihood_function = likelihood_function
|
||||
self.epsilon = epsilon
|
||||
|
|
@ -48,7 +41,6 @@ class EP:
|
|||
For nomenclature see Rasmussen & Williams 2006.
|
||||
"""
|
||||
#Prior distribution parameters: p(f|X) = N(f|0,K)
|
||||
#self.K = self.kernel.K(self.X,self.X)
|
||||
|
||||
#Initial values - Posterior distribution parameters: q(f|X,Y) = N(f|mu,Sigma)
|
||||
self.mu = np.zeros(self.N)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,39 @@
|
|||
import numpy as np
|
||||
|
||||
class Gaussian:
|
||||
def __init__(self,data,variance=1.,normalise=False):
|
||||
def __init__(self,data,variance=1.,normalize=False):
|
||||
self.data = data
|
||||
if normalise:
|
||||
foo
|
||||
self._variance = variance
|
||||
self.N,D = data.shape
|
||||
self.Z = 0. # a correction factor which accounts for the approximation made
|
||||
|
||||
#normalisation
|
||||
if normalize:
|
||||
self._mean = data.mean(0)[None,:]
|
||||
self._std = data.std(0)[None,:]
|
||||
self.Y = (self.data - self._mean)/self._std
|
||||
else:
|
||||
self._mean = np.zeros((1,D))
|
||||
self._std = np.ones((1,D))
|
||||
self.Y = self.data
|
||||
|
||||
self.YYT = np.dot(self.Y,self.Y.T)
|
||||
self._set_params(np.asarray(variance))
|
||||
|
||||
def _get_params(self):
|
||||
return np.asarray(self.variance)
|
||||
return np.asarray(self._variance)
|
||||
|
||||
def _get_param_names(self):
|
||||
return ["noise variance"]
|
||||
|
||||
def _set_params(self,x):
|
||||
self._variance = x
|
||||
self.variance = np.eye(self.N)*self._variance
|
||||
|
||||
def fit(self):
|
||||
"""
|
||||
No approximations needed
|
||||
"""
|
||||
pass
|
||||
def _gradients(self,foo):
|
||||
return bar(foo)
|
||||
|
||||
def _gradients(self,partial):
|
||||
return np.sum(np.diag(partial))
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from EP import EP
|
||||
from Gaussian import Gaussian
|
||||
# TODO: from Laplace import Laplace
|
||||
import likelihood_functions as functions
|
||||
|
|
|
|||
|
|
@ -192,10 +192,10 @@ class poisson(likelihood):
|
|||
pb.plot(Z,Z*0+pb.ylim()[0],'k|',mew=1.5,markersize=12)
|
||||
|
||||
class gaussian(likelihood):
|
||||
"""
|
||||
Gaussian likelihood
|
||||
Y is expected to take values in (-inf,inf)
|
||||
"""
|
||||
"""
|
||||
Gaussian likelihood
|
||||
Y is expected to take values in (-inf,inf)
|
||||
"""
|
||||
def moments_match(self,i,tau_i,v_i):
|
||||
"""
|
||||
Moments match of the marginal approximation in EP algorithm
|
||||
|
|
@ -221,6 +221,3 @@ class gaussian(likelihood):
|
|||
|
||||
def _log_likelihood_gradients():
|
||||
raise NotImplementedError
|
||||
else:
|
||||
var = var[:,None] * np.square(self._Ystd)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue