MCPcopy
hub / github.com/ddbourgin/numpy-ml / test_gp_regression

Function test_gp_regression

numpy_ml/tests/test_nonparametric.py:87–119  ·  view source on GitHub ↗
(N=15)

Source from the content-addressed store, hash-verified

85
86
87def test_gp_regression(N=15):
88 np.random.seed(12345)
89
90 i = 0
91 while i < N:
92 alpha = np.random.rand()
93 N = np.random.randint(2, 100)
94 M = np.random.randint(2, 100)
95 K = np.random.randint(1, N)
96 J = np.random.randint(1, 3)
97
98 X = np.random.rand(N, M)
99 y = np.random.rand(N, J)
100 X_test = np.random.rand(K, M)
101
102 gp = GPRegression(kernel="RBFKernel(sigma=1)", alpha=alpha)
103 gold = GaussianProcessRegressor(
104 kernel=None, alpha=alpha, optimizer=None, normalize_y=False
105 )
106
107 gp.fit(X, y)
108 gold.fit(X, y)
109
110 preds, _ = gp.predict(X_test)
111 gold_preds = gold.predict(X_test)
112 np.testing.assert_almost_equal(preds, gold_preds)
113
114 mll = gp.marginal_log_likelihood()
115 gold_mll = gold.log_marginal_likelihood()
116 np.testing.assert_almost_equal(mll, gold_mll)
117
118 print("PASSED")
119 i += 1

Callers

nothing calls this directly

Calls 6

fitMethod · 0.95
predictMethod · 0.95
GPRegressionClass · 0.90
fitMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected