MCPcopy
hub / github.com/GPflow/GPflow / test_models_with_mean_functions_changes

Function test_models_with_mean_functions_changes

tests/gpflow/test_functions.py:291–374  ·  view source on GitHub ↗

Simply check that all models have a higher prediction with a constant mean function than with a zero mean function. For compositions of mean functions check that multiplication/ addition of a constant results in a higher prediction, whereas addition of zero/ mutliplication with

(model_class: Type[Any])

Source from the content-addressed store, hash-verified

289
290@pytest.mark.parametrize("model_class", _model_classes)
291def test_models_with_mean_functions_changes(model_class: Type[Any]) -> None:
292 """
293 Simply check that all models have a higher prediction with a constant mean
294 function than with a zero mean function.
295
296 For compositions of mean functions check that multiplication/ addition of
297 a constant results in a higher prediction, whereas addition of zero/
298 mutliplication with one does not.
299 """
300 data = rng.randn(Datum.N, Datum.input_dim), rng.randn(Datum.N, 1)
301 Xnew = rng.randn(Datum.Ntest, Datum.input_dim)
302 inducing_variable = InducingPoints(Z=rng.randn(Datum.M, Datum.input_dim))
303 kernel = gpflow.kernels.Matern32()
304 likelihood = gpflow.likelihoods.Gaussian()
305 zero_mean = Zero()
306 non_zero_mean = Constant(c=np.ones(1) * 10)
307
308 if model_class in [gpflow.models.GPR]:
309 model_zero_mean = model_class(data, kernel=kernel, mean_function=zero_mean)
310 model_non_zero_mean = model_class(data, kernel=kernel, mean_function=non_zero_mean)
311 elif model_class in [gpflow.models.VGP]:
312 model_zero_mean = model_class(
313 data, likelihood=likelihood, kernel=kernel, mean_function=zero_mean
314 )
315 model_non_zero_mean = model_class(
316 data, likelihood=likelihood, kernel=kernel, mean_function=non_zero_mean
317 )
318 elif model_class in [gpflow.models.SVGP]:
319 model_zero_mean = model_class(
320 kernel=kernel,
321 likelihood=likelihood,
322 inducing_variable=inducing_variable,
323 mean_function=zero_mean,
324 )
325 model_non_zero_mean = model_class(
326 kernel=kernel,
327 likelihood=likelihood,
328 inducing_variable=inducing_variable,
329 mean_function=non_zero_mean,
330 )
331 elif model_class in [gpflow.models.SGPR, gpflow.models.GPRFITC]:
332 model_zero_mean = model_class(
333 data,
334 kernel=kernel,
335 inducing_variable=inducing_variable,
336 mean_function=zero_mean,
337 )
338 model_non_zero_mean = model_class(
339 data,
340 kernel=kernel,
341 inducing_variable=inducing_variable,
342 mean_function=non_zero_mean,
343 )
344 elif model_class in [gpflow.models.SGPMC]:
345 model_zero_mean = model_class(
346 data,
347 kernel=kernel,
348 likelihood=likelihood,

Callers

nothing calls this directly

Calls 5

InducingPointsClass · 0.90
ZeroClass · 0.90
ConstantClass · 0.90
allMethod · 0.80
predict_fMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…