示例#1
0
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()
示例#2
0
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
示例#3
0
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
示例#4
0
def test_sparse_variational_model_attribute() -> None:
    model = svgp_model(*mock_data())
    sv = SparseVariational(model)
    assert sv.model is model
示例#5
0
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])