Example #1
0
 def test_se(self,thr=1e-6):
     """ Test squared exponential covariance.
     """
     k = cov.se(ell=np.random.rand())
     self.run_verifications(k,thr)
     k = cov.se(ell=np.random.rand(self.D))
     self.run_verifications(k,thr)
 def test_se(self, thr=1e-6):
     """ Test squared exponential covariance.
     """
     k = cov.se(ell=np.random.rand())
     self.run_verifications(k, thr)
     k = cov.se(ell=np.random.rand(self.D))
     self.run_verifications(k, thr)
Example #3
0
 def test_prodsum(self,thr=3e-6):
     """ Test the product of sums of several covariance functions.
     """
     k1 = cov.se(ell=np.random.rand())
     k2 = cov.se(ell=np.random.rand(self.D))
     k3 = cov.se(ell=np.random.rand())
     k4 = cov.se(ell=np.random.rand(self.D))
     self.run_verifications((2.3+k1)*(k2+1.2)*(k3+k4),thr)
Example #4
0
 def test_sumprod(self,thr=1e-6):
     """ Test the sum of products of several covariance functions.
     """
     k1 = cov.se(ell=np.random.rand())
     k2 = cov.se(ell=np.random.rand(self.D))
     k3 = cov.se(ell=np.random.rand())
     k4 = cov.se(ell=np.random.rand(self.D))
     self.run_verifications(2.3*k1+k2*1.2+k3*k4,thr)
 def test_prodsum(self, thr=3e-6):
     """ Test the product of sums of several covariance functions.
     """
     k1 = cov.se(ell=np.random.rand())
     k2 = cov.se(ell=np.random.rand(self.D))
     k3 = cov.se(ell=np.random.rand())
     k4 = cov.se(ell=np.random.rand(self.D))
     self.run_verifications((2.3 + k1) * (k2 + 1.2) * (k3 + k4), thr)
 def test_sumprod(self, thr=1e-6):
     """ Test the sum of products of several covariance functions.
     """
     k1 = cov.se(ell=np.random.rand())
     k2 = cov.se(ell=np.random.rand(self.D))
     k3 = cov.se(ell=np.random.rand())
     k4 = cov.se(ell=np.random.rand(self.D))
     self.run_verifications(2.3 * k1 + k2 * 1.2 + k3 * k4, thr)
Example #7
0
 def test_prod(self,thr=1e-6):
     """ Test the product of several covariance functions.
     """
     n,m,D,X,Z = self.n,self.m,self.D,self.X,self.Z
     k1 = cov.se(ell=np.random.rand())
     k2 = cov.se(ell=np.random.rand(self.D))
     k = k1*k2*1.2
     d = np.linalg.norm( k1(X)*k2(X)*1.2 - k(X) )
     self.assertLessEqual(d,thr)
     self.run_verifications(k,thr)
 def test_prod(self, thr=1e-6):
     """ Test the product of several covariance functions.
     """
     n, m, D, X, Z = self.n, self.m, self.D, self.X, self.Z
     k1 = cov.se(ell=np.random.rand())
     k2 = cov.se(ell=np.random.rand(self.D))
     k = k1 * k2 * 1.2
     d = np.linalg.norm(k1(X) * k2(X) * 1.2 - k(X))
     self.assertLessEqual(d, thr)
     self.run_verifications(k, thr)
 def test_ep(self,thr=1e-4):
     """ Test expectation propagation approximate inference.
     """
     im = inf.ep
     cf,mf,lf = 1.1*cov.se(ell=0.8),mean.zero(),lik.erf()
     self.run_verifications(im,cf,mf,lf,thr)
     lf = lik.gauss(sn=0.2)
     self.run_verifications(im,cf,mf,lf,thr)
     mf = 2.3*mean.one()
     self.run_verifications(im,cf,mf,lf,thr)
     cf = 1.3*cov.se(ell=[0.8,0.7,0.3])
     self.run_verifications(im,cf,mf,lf,thr)
     mf = 1.3*mean.linear(a=[0.8,0.7,0.3])
     self.run_verifications(im,cf,mf,lf,thr)
Example #10
0
 def test_exact(self,thr=1e-4):
     """ Test exact inference.
     """
     im = inf.exact
     cf,mf,lf = 1.1*cov.se(ell=0.8),mean.zero(),lik.gauss(sn=1e-5)
     self.run_verifications(im,cf,mf,lf,thr)
     lf = lik.gauss(sn=0.2)
     self.run_verifications(im,cf,mf,lf,thr)
     mf = 2.3*mean.one()
     self.run_verifications(im,cf,mf,lf,thr)
     cf = 1.3*cov.se(ell=[0.8,0.7,0.3])
     self.run_verifications(im,cf,mf,lf,thr)
     mf = 1.3*mean.linear(a=[0.8,0.7,0.3])
     self.run_verifications(im,cf,mf,lf,thr)
Example #11
0
 def __init__(self,inf=exact,cov=1.0*se(ell=1.0),
                               mean=zero(),lik=gauss(sn=1.0),X=None,y=None):
     """ Set up a gp, perform inference if X and y are provided.
     """
     self.inf = inf                                       # inference method
     self.cov,self.mean,self.lik = cov,mean,lik # covariance,mean,likelihood
     self.post = None                         # init posterior approximation
     if X!=None and y!=None: self.post = self.inference(X,y)  # do inference
Example #12
0
 def __init__(self,
              inf=exact,
              cov=1.0 * se(ell=1.0),
              mean=zero(),
              lik=gauss(sn=1.0),
              X=None,
              y=None):
     """ Set up a gp, perform inference if X and y are provided.
     """
     self.inf = inf  # inference method
     self.cov, self.mean, self.lik = cov, mean, lik  # covariance,mean,likelihood
     self.post = None  # init posterior approximation
     if X != None and y != None:
         self.post = self.inference(X, y)  # do inference