swh:1:snp:00bd25be6ef59fb8210ef6a4c842086902e04451
Tip revision: 816a41f081fb5f8d1c33aaf7b7866fcf393b0898 authored by thevincentadam on 02 February 2020, 21:14:05 UTC
update models and parse
update models and parse
Tip revision: 816a41f
test_model.py
# Copyright 2019 the GPflow authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import gpflow
import numpy as np
import pytest
from gpflow.utilities import set_trainable
rng = np.random.RandomState(0)
class Data:
N = 10
D = 1
X = rng.rand(N, D)
Y = rng.rand(N, 1)
ls = 2.0
var = 1.0
# ------------------------------------------
# Fixtures
# ------------------------------------------
@pytest.fixture
def model():
return gpflow.models.GPR(
(Data.X, Data.Y),
kernel=gpflow.kernels.SquaredExponential(lengthscale=Data.ls, variance=Data.var),
)
def test_non_trainable_model_objective(model):
"""
Checks that we can still compute the objective of a model that has no
trainable parameters whatsoever (regression test for bug in log_prior()).
In this case we have no priors, so log_prior should be zero to add no
contribution to the objective.
"""
set_trainable(model, False)
_ = model.log_marginal_likelihood()
assert model.log_prior() == 0.0