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])
| 289 | |
| 290 | @pytest.mark.parametrize("model_class", _model_classes) |
| 291 | def 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, |
nothing calls this directly
no test coverage detected
searching dependent graphs…