mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-14 14:32:37 +02:00
[prior] singleton tested
This commit is contained in:
parent
7b63a195b8
commit
77b4325934
1 changed files with 9 additions and 9 deletions
|
|
@ -13,21 +13,22 @@ class PriorTests(unittest.TestCase):
|
||||||
y = b*X + C + 1*np.sin(X)
|
y = b*X + C + 1*np.sin(X)
|
||||||
y += 0.05*np.random.randn(len(X))
|
y += 0.05*np.random.randn(len(X))
|
||||||
X, y = X[:, None], y[:, None]
|
X, y = X[:, None], y[:, None]
|
||||||
m = GPy.models.GPRegression(X, y)
|
|
||||||
studentT = GPy.priors.StudentT(1, 2, 4)
|
studentT = GPy.priors.StudentT(1, 2, 4)
|
||||||
|
|
||||||
|
m = GPy.models.SparseGPRegression(X, y)
|
||||||
|
m.Z.set_prior(studentT)
|
||||||
|
|
||||||
# setting a StudentT prior on non-negative parameters
|
# setting a StudentT prior on non-negative parameters
|
||||||
# should raise an assertionerror.
|
# should raise an assertionerror.
|
||||||
self.assertRaises(AssertionError, m.rbf.set_prior, studentT)
|
self.assertRaises(AssertionError, m.rbf.set_prior, studentT)
|
||||||
|
|
||||||
m = GPy.models.SparseGPRegression(X, y)
|
# The gradients need to be checked
|
||||||
|
|
||||||
gaussian = GPy.priors.Gaussian(1, 1)
|
|
||||||
m.Z.set_prior(studentT)
|
|
||||||
# setting a Gaussian prior on non-negative parameters
|
|
||||||
# should raise an assertionerror.
|
|
||||||
#self.assertRaises(AssertionError, m.Z.set_prior, gaussian)
|
|
||||||
self.assertTrue(m.checkgrad())
|
self.assertTrue(m.checkgrad())
|
||||||
|
|
||||||
|
# Check the singleton pattern:
|
||||||
|
self.assertIs(studentT, GPy.priors.StudentT(1,2,4))
|
||||||
|
self.assertIsNot(studentT, GPy.priors.StudentT(2,2,4))
|
||||||
|
|
||||||
def test_lognormal(self):
|
def test_lognormal(self):
|
||||||
xmin, xmax = 1, 2.5*np.pi
|
xmin, xmax = 1, 2.5*np.pi
|
||||||
b, C, SNR = 1, 0, 0.1
|
b, C, SNR = 1, 0, 0.1
|
||||||
|
|
@ -129,7 +130,6 @@ class PriorTests(unittest.TestCase):
|
||||||
# should raise an assertionerror.
|
# should raise an assertionerror.
|
||||||
self.assertRaises(AssertionError, m.rbf.set_prior, gaussian)
|
self.assertRaises(AssertionError, m.rbf.set_prior, gaussian)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Running unit tests, please be (very) patient...")
|
print("Running unit tests, please be (very) patient...")
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue