mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-06 18:42:39 +02:00
added a likelihood atom class
and also some import tidying in the EP.py file
This commit is contained in:
parent
7dfbcebb87
commit
346f9dd8bd
3 changed files with 41 additions and 9 deletions
|
|
@ -1,11 +1,9 @@
|
|||
import numpy as np
|
||||
import random
|
||||
from scipy import stats, linalg
|
||||
from ..core import model
|
||||
from ..util.linalg import pdinv,mdot,jitchol
|
||||
from ..util.plot import gpplot
|
||||
from likelihood import likelihood
|
||||
|
||||
class EP:
|
||||
class EP(likelihood):
|
||||
def __init__(self,data,likelihood_function,epsilon=1e-3,power_ep=[1.,1.]):
|
||||
"""
|
||||
Expectation Propagation
|
||||
|
|
@ -70,8 +68,7 @@ class EP:
|
|||
self.np1 = [self.tau_tilde.copy()]
|
||||
self.np2 = [self.v_tilde.copy()]
|
||||
while epsilon_np1 > self.epsilon or epsilon_np2 > self.epsilon:
|
||||
update_order = np.arange(self.N)
|
||||
random.shuffle(update_order)
|
||||
update_order = np.random.permutation(self.N)
|
||||
for i in update_order:
|
||||
#Cavity distribution parameters
|
||||
self.tau_[i] = 1./self.Sigma[i,i] - self.eta*self.tau_tilde[i]
|
||||
|
|
@ -243,8 +240,7 @@ class EP:
|
|||
self.np1 = [self.tau_tilde.copy()]
|
||||
self.np2 = [self.v_tilde.copy()]
|
||||
while epsilon_np1 > self.epsilon or epsilon_np2 > self.epsilon:
|
||||
update_order = np.arange(self.N)
|
||||
random.shuffle(update_order)
|
||||
update_order = np.random.permutation(self.N)
|
||||
for i in update_order:
|
||||
#Cavity distribution parameters
|
||||
self.tau_[i] = 1./self.Sigma_diag[i] - self.eta*self.tau_tilde[i]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import numpy as np
|
||||
from likelihood import likelihood
|
||||
|
||||
class Gaussian:
|
||||
class Gaussian(likelihood):
|
||||
def __init__(self,data,variance=1.,normalize=False):
|
||||
self.is_heteroscedastic = False
|
||||
self.data = data
|
||||
|
|
|
|||
35
GPy/likelihoods/likelihood.py
Normal file
35
GPy/likelihoods/likelihood.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import numpy as np
|
||||
|
||||
class likelihood:
|
||||
"""
|
||||
The atom for a likelihood class
|
||||
|
||||
This object interfaces the GP and the data. The most basic likelihood
|
||||
(Gaussian) inherits directly from this, as does the EP algorithm
|
||||
|
||||
Some things must be defined for this to work properly:
|
||||
self.Y : the effective Gaussian target of the GP
|
||||
self.N, self.D : Y.shape
|
||||
self.covariance_matrix : the effective (noise) covariance of the GP targets
|
||||
self.Z : a factor which gets added to the likelihood (0 for a Gaussian, Z_EP for EP)
|
||||
self.is_heteroscedastic : enables significant computational savings in GP
|
||||
self.precision : a scalar or vector representation of the effective target precision
|
||||
self.YYT : (optional) = np.dot(self.Y, self.Y.T) enables computational savings for D>N
|
||||
"""
|
||||
def __init__(self,data):
|
||||
raise ValueError, "this class is not to be instantiated"
|
||||
|
||||
def _get_params(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _get_param_names(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _set_params(self,x):
|
||||
raise NotImplementedError
|
||||
|
||||
def fit(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _gradients(self,partial):
|
||||
raise NotImplementedError
|
||||
Loading…
Add table
Add a link
Reference in a new issue