Allow calculation of full predictive covariance matrices with multiple outputs and normalization

This commit is contained in:
Mark Pullin 2018-02-05 11:21:02 +00:00
parent a6c154753d
commit ccfcfa1a85
4 changed files with 91 additions and 42 deletions

View file

@ -118,6 +118,24 @@ class MiscTests(unittest.TestCase):
from scipy.stats import norm
np.testing.assert_allclose((mu+(norm.ppf(qs/100.)*np.sqrt(var))).flatten(), np.array(q95).flatten())
def test_multioutput_regression_with_normalizer(self):
"""
Test that normalizing works in multi-output case
"""
# Create test inputs
X1 = (np.random.rand(50, 1) * 8)
Y1 = np.sin(X1) + np.random.randn(*X1.shape) * 0.05
Y2 = -np.sin(X1) + np.random.randn(*X1.shape) * 0.05
Y = np.hstack((Y1, Y2))
m = GPy.models.GPRegression(X1, Y, normalizer=True)
n_test_point = 10
mean, covaraince = m.predict(np.random.rand(n_test_point, 1),
full_cov=True)
self.assertTrue(covaraince.shape == (n_test_point, n_test_point, 2))
def check_jacobian(self):
try:
import autograd.numpy as np, autograd as ag, GPy, matplotlib.pyplot as plt

View file

@ -28,7 +28,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#===============================================================================
import unittest, numpy as np
import unittest
import numpy as np
import GPy
class TestDebug(unittest.TestCase):
@ -225,3 +226,17 @@ class TestUnivariateGaussian(unittest.TestCase):
for i in range(len(pySols)):
diff += abs(derivLogCdfNormal(self.zz[i]) - pySols[i])
self.assertTrue(diff < 1e-8)
class TestStandardize(unittest.TestCase):
def setUp(self):
self.normalizer = GPy.util.normalizer.Standardize()
y = np.stack([np.random.randn(10), 2*np.random.randn(10)], axis=1)
self.normalizer.scale_by(y)
def test_inverse_covariance(self):
"""
Test inverse covariance outputs correct size
"""
covariance = np.random.rand(100, 100)
output = self.normalizer.inverse_covariance(covariance)
self.assertTrue(output.shape == (100, 100, 2))