def testTwoSamples_low_covariance(seed): np_rng = npr.RandomState(seed) obs_inputs = np.array([1.3, -2.0, 0.0]) obs_outputs = np.array([5.0, 2.3, 8.0]) in_lo_cov = np.array([1.4, -20.0]) sigma = 2.1 l = 1.8 observations = OrderedDict(zip(obs_inputs, obs_outputs)) mean = gp.mean_const(0.) covariance = cov.scale(sigma**2, cov.se(l**2)) # Fix n = 200, not higher even if we are doing a long-running # inference quality test, because we're trying to show that a # Pearson r^2 test of independence will fail to reject the null # hypothesis that the GP at two points with low covariance are # simply independent. If we raised the number of samples # significantly higher, the test is likely to reject the null # hypothesis. n = 200 lo_cov_x = [] lo_cov_y = [] for i in range(n): x, y = gp._gp_sample(mean, covariance, observations, in_lo_cov, np_rng) lo_cov_x.append(x) lo_cov_y.append(y) return reportPearsonIndependence(lo_cov_x, lo_cov_y)
def testOneSample(seed): np_rng = npr.RandomState(seed) obs_inputs = np.array([1.3, -2.0, 0.0]) obs_outputs = np.array([5.0, 2.3, 8.0]) test_input = 1.4 expect_mu = 4.6307 expect_sig = 0.0027 sigma = 2.1 l = 1.8 observations = OrderedDict(zip(obs_inputs, obs_outputs)) mean = gp.mean_const(0.) covariance = cov.scale(sigma**2, cov.se(l**2)) # _gp_sample(..., test_input) should be normally distributed with # mean expect_mu. n = default_num_samples(4) def sample(): s = gp._gp_sample(mean, covariance, observations, [test_input], np_rng) return s[0] samples = np.array([sample() for _ in xrange(n)]) assert samples.shape == (n, ) return reportKnownGaussian(expect_mu, np.sqrt(expect_sig), samples)
def testNormalParameters(): obs_inputs = np.array([1.3, -2.0, 0.0]) obs_outputs = np.array([5.0, 2.3, 8.0]) test_inputs = np.array([1.4, -3.2]) expect_mu = np.array([4.6307, -0.9046]) expect_sig = np.array([[0.0027, -0.0231], [-0.0231, 1.1090]]) sigma = 2.1 l = 1.8 observations = OrderedDict(zip(obs_inputs, obs_outputs)) mean = gp.mean_const(0.) covariance = cov.scale(sigma**2, cov.se(l**2)) actual_mu, actual_sig = gp._gp_mvnormal(mean, covariance, observations, test_inputs) np.testing.assert_almost_equal(actual_mu, expect_mu, decimal=4) np.testing.assert_almost_equal(actual_sig, expect_sig, decimal=4)
def interpret_mean_kernel(ast): if ast[0]['value'] == 'gp_mean_const': c = ast[1]['value'] return gp.mean_const(c) else: assert False, ''