def test_gpflow_predictor_get_observation_noise_raises_for_likelihood_with_variance( gpflow_interface_factory: ModelFactoryType, ) -> None: data = mock_data() model, _ = gpflow_interface_factory(*data) model.model.likelihood = gpflow.likelihoods.Gaussian() # has variance attribute model.get_observation_noise() model.model.likelihood = gpflow.likelihoods.Bernoulli() # does not have variance attribute with pytest.raises(NotImplementedError): model.get_observation_noise()
def test_gaussian_process_regression_default_optimize( gpr_interface_factory: ModelFactoryType, ) -> None: data = mock_data() model, _ = gpr_interface_factory(*data) internal_model = model.model if isinstance(internal_model, SVGP): args = {"data": data} else: args = {} loss = internal_model.training_loss(**args) model.optimize(Dataset(*data)) assert internal_model.training_loss(**args) < loss
def test_gaussian_process_regression_optimize( optimizer: gpflow.optimizers.Scipy | tf.optimizers.Optimizer, gpflow_interface_factory: ModelFactoryType, compile: bool, ) -> None: data = mock_data() optimizer_wrapper = create_optimizer(optimizer, dict(compile=compile)) model, _ = gpflow_interface_factory(*data, optimizer=optimizer_wrapper) internal_model = model.model if isinstance(internal_model, SVGP): args = {"data": data} else: args = {} loss = internal_model.training_loss(**args) model.optimize(Dataset(*data)) assert internal_model.training_loss(**args) < loss
def test_sparse_variational_model_attribute() -> None: model = svgp_model(*mock_data()) sv = SparseVariational(model) assert sv.model is model
def test_sgpr_raises_for_covariance_between_points() -> None: data = mock_data() model = GaussianProcessRegression(sgpr_model(*data)) with pytest.raises(NotImplementedError): model.covariance_between_points(data[0], data[0])