Search code examples
tensorflow2.0gaussiangpflow

Does GPflow 2.0 support putting priors on (hyper)parameters of GPs?


I would like to put some prior on the (hyper)parameters of the GP models in GPflow, but I cannot find any module (like gpflow.priors) or doc about this issue.

Besides, I noticed that prior is one of the arguments of the class parameter, together with a question.


Solution

  • GPflow 2.0 uses tensorflow_probability distributions objects for the priors, e.g.

    model.kernel.lengthscales.prior = tensorflow_probability.distributions.Gamma(
        gpflow.utilities.to_default_float(1.0), gpflow.utilities.to_default_float(1.0)
    )
    

    (or pass the distribution object as the prior argument of the gpflow.Parameter class). Note that TensorFlow by default uses float32, whereas with GPs we typically want to work in float64 - hence the calls to to_default_float.

    This is mentioned in the documentation, both in the notebook on understanding models and discussed in depth in the notebook on how to use MCMC with GPflow.