mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-24 14:15:14 +02:00
Merge branch 'SheffieldML:devel' into devel
This commit is contained in:
commit
06f60715a9
3 changed files with 23 additions and 16 deletions
|
|
@ -371,24 +371,17 @@ class InverseGamma(Gamma):
|
|||
"""
|
||||
domain = _POSITIVE
|
||||
_instances = []
|
||||
def __new__(cls, a=1, b=.5): # Singleton:
|
||||
if cls._instances:
|
||||
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
||||
for instance in cls._instances:
|
||||
if instance().a == a and instance().b == b:
|
||||
return instance()
|
||||
o = super(Prior, cls).__new__(cls, a, b)
|
||||
cls._instances.append(weakref.ref(o))
|
||||
return cls._instances[-1]()
|
||||
|
||||
def __init__(self, a, b):
|
||||
self._a = float(a)
|
||||
self._b = float(b)
|
||||
self.constant = -gammaln(self.a) + a * np.log(b)
|
||||
|
||||
def __str__(self):
|
||||
return "iGa({:.2g}, {:.2g})".format(self.a, self.b)
|
||||
|
||||
def summary(self):
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def from_EV(E, V):
|
||||
raise NotImplementedError
|
||||
|
||||
def lnpdf(self, x):
|
||||
return self.constant - (self.a + 1) * np.log(x) - self.b / x
|
||||
|
||||
|
|
@ -398,7 +391,6 @@ class InverseGamma(Gamma):
|
|||
def rvs(self, n):
|
||||
return 1. / np.random.gamma(scale=1. / self.b, shape=self.a, size=n)
|
||||
|
||||
|
||||
class DGPLVM_KFDA(Prior):
|
||||
"""
|
||||
Implementation of the Discriminative Gaussian Process Latent Variable function using
|
||||
|
|
|
|||
|
|
@ -55,6 +55,21 @@ class PriorTests(unittest.TestCase):
|
|||
m.randomize()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
def test_InverseGamma(self):
|
||||
# Test that this prior object can be instantiated and performs its basic functions
|
||||
# in integration.
|
||||
xmin, xmax = 1, 2.5*np.pi
|
||||
b, C, SNR = 1, 0, 0.1
|
||||
X = np.linspace(xmin, xmax, 500)
|
||||
y = b*X + C + 1*np.sin(X)
|
||||
y += 0.05*np.random.randn(len(X))
|
||||
X, y = X[:, None], y[:, None]
|
||||
m = GPy.models.GPRegression(X, y)
|
||||
InverseGamma = GPy.priors.InverseGamma(1, 1)
|
||||
m.rbf.set_prior(InverseGamma)
|
||||
m.randomize()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
def test_incompatibility(self):
|
||||
xmin, xmax = 1, 2.5*np.pi
|
||||
b, C, SNR = 1, 0, 0.1
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ We will see in this tutorial how to create new kernels in GPy. We will also give
|
|||
Structure of a kernel in GPy
|
||||
============================
|
||||
|
||||
In GPy a kernel object is made of a list of kernpart objects, which correspond to symetric positive definite functions. More precisely, the kernel should be understood as the sum of the kernparts. In order to implement a new covariance, the following steps must be followed
|
||||
In GPy a kernel object is made of a list of kernpart objects, which correspond to symmetric positive definite functions. More precisely, the kernel should be understood as the sum of the kernparts. In order to implement a new covariance, the following steps must be followed
|
||||
|
||||
1. implement the new covariance as a :py:class:`GPy.kern.src.kern.Kern` object
|
||||
2. update the :py:mod:`GPy.kern.src` file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue