SheffieldML / GPy

Gaussian processes framework in python
BSD 3-Clause "New" or "Revised" License
2.01k stars 557 forks source link

Constrain_bounded Parameter cannot update #593

Closed ssydasheng closed 6 years ago

ssydasheng commented 6 years ago
import GPy
import numpy as np
x = np.random.normal(size=[20, 10])
y = np.random.normal(size=[20, 1]) * 0.1

kern = GPy.kern.RBF(10)
model = GPy.models.GPRegression(x, y, kern)
model['Gaussian_noise.variance'].constrain_bounded(1e-5,1)
model.optimize()
print(model['Gaussian_noise.variance'])

kern = GPy.kern.RBF(10)
model = GPy.models.GPRegression(x, y, kern, noise_var=0.5)
model['Gaussian_noise.variance'].constrain_bounded(1e-5,1)
model.optimize()
print(model['Gaussian_noise.variance'])

The first prints 1, the second prints 0.00721777. It seems when the initialization is one of the bounds, it cannot be updated anymore.

mzwiessele commented 6 years ago

You are creating two different initializations, try to set the same initializations:

import GPy
import numpy as np
x = np.random.normal(size=[20, 10])
y = np.random.normal(size=[20, 1]) * 0.1

kern = GPy.kern.RBF(10)
model = GPy.models.GPRegression(x, y, kern)
model['Gaussian_noise.variance'].constrain_bounded(1e-5,1)
model.Gaussian_noise.variance = .5
model.optimize()
print(model['Gaussian_noise.variance'])

kern = GPy.kern.RBF(10)
model = GPy.models.GPRegression(x, y, kern, noise_var=0.5)
model['Gaussian_noise.variance'].constrain_bounded(1e-5,1)
model.optimize()
print(model['Gaussian_noise.variance'])