format on save

This commit is contained in:
Martin Bubel 2023-10-10 19:47:30 +02:00
parent aac3fb1c44
commit 4e5a4fc605

View file

@ -5,6 +5,7 @@ import unittest
import numpy as np import numpy as np
import GPy import GPy
class PriorTests(unittest.TestCase): class PriorTests(unittest.TestCase):
def test_studentT(self): def test_studentT(self):
xmin, xmax = 1, 2.5 * np.pi xmin, xmax = 1, 2.5 * np.pi
@ -23,7 +24,7 @@ class PriorTests(unittest.TestCase):
self.assertRaises(AssertionError, m.rbf.set_prior, studentT) self.assertRaises(AssertionError, m.rbf.set_prior, studentT)
# The gradients need to be checked # The gradients need to be checked
self.assertTrue(m.checkgrad()) assert m.checkgrad()
# Check the singleton pattern: # Check the singleton pattern:
self.assertIs(studentT, GPy.priors.StudentT(1, 2, 4)) self.assertIs(studentT, GPy.priors.StudentT(1, 2, 4))
@ -40,7 +41,7 @@ class PriorTests(unittest.TestCase):
lognormal = GPy.priors.LogGaussian(1, 2) lognormal = GPy.priors.LogGaussian(1, 2)
m.rbf.set_prior(lognormal) m.rbf.set_prior(lognormal)
m.randomize() m.randomize()
self.assertTrue(m.checkgrad()) assert m.checkgrad()
def test_Gamma(self): def test_Gamma(self):
xmin, xmax = 1, 2.5 * np.pi xmin, xmax = 1, 2.5 * np.pi
@ -53,7 +54,7 @@ class PriorTests(unittest.TestCase):
Gamma = GPy.priors.Gamma(1, 1) Gamma = GPy.priors.Gamma(1, 1)
m.rbf.set_prior(Gamma) m.rbf.set_prior(Gamma)
m.randomize() m.randomize()
self.assertTrue(m.checkgrad()) assert m.checkgrad()
def test_InverseGamma(self): def test_InverseGamma(self):
# Test that this prior object can be instantiated and performs its basic functions # Test that this prior object can be instantiated and performs its basic functions
@ -68,7 +69,7 @@ class PriorTests(unittest.TestCase):
InverseGamma = GPy.priors.InverseGamma(1, 1) InverseGamma = GPy.priors.InverseGamma(1, 1)
m.rbf.set_prior(InverseGamma) m.rbf.set_prior(InverseGamma)
m.randomize() m.randomize()
self.assertTrue(m.checkgrad()) assert m.checkgrad()
def test_incompatibility(self): def test_incompatibility(self):
xmin, xmax = 1, 2.5 * np.pi xmin, xmax = 1, 2.5 * np.pi
@ -109,23 +110,23 @@ class PriorTests(unittest.TestCase):
uniform = GPy.priors.Uniform(0, 2) uniform = GPy.priors.Uniform(0, 2)
m.rbf.set_prior(uniform) m.rbf.set_prior(uniform)
m.randomize() m.randomize()
self.assertTrue(m.checkgrad()) assert m.checkgrad()
m.Z.set_prior(uniform) m.Z.set_prior(uniform)
m.randomize() m.randomize()
self.assertTrue(m.checkgrad()) assert m.checkgrad()
m.Z.unconstrain() m.Z.unconstrain()
uniform = GPy.priors.Uniform(-1, 10) uniform = GPy.priors.Uniform(-1, 10)
m.Z.set_prior(uniform) m.Z.set_prior(uniform)
m.randomize() m.randomize()
self.assertTrue(m.checkgrad()) assert m.checkgrad()
m.Z.constrain_negative() m.Z.constrain_negative()
uniform = GPy.priors.Uniform(-1, 0) uniform = GPy.priors.Uniform(-1, 0)
m.Z.set_prior(uniform) m.Z.set_prior(uniform)
m.randomize() m.randomize()
self.assertTrue(m.checkgrad()) assert m.checkgrad()
def test_set_gaussian_for_reals(self): def test_set_gaussian_for_reals(self):
xmin, xmax = 1, 2.5 * np.pi xmin, xmax = 1, 2.5 * np.pi
@ -141,8 +142,7 @@ class PriorTests(unittest.TestCase):
# setting a Gaussian prior on non-negative parameters # setting a Gaussian prior on non-negative parameters
# should raise an assertionerror. # should raise an assertionerror.
# self.assertRaises(AssertionError, m.Z.set_prior, gaussian) # self.assertRaises(AssertionError, m.Z.set_prior, gaussian)
self.assertTrue(m.checkgrad()) assert m.checkgrad()
def test_fixed_domain_check(self): def test_fixed_domain_check(self):
xmin, xmax = 1, 2.5 * np.pi xmin, xmax = 1, 2.5 * np.pi
@ -174,6 +174,7 @@ 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()