3

In GPflow 1.0, if I wanted to set hard bounds on a parameter like lengthscale (i.e. limiting the optimisation range for the parameter),

transforms.Logistic(a=4., b=6.)

would bound the parameter between 4 and 6.

GPflow 2.0's documentation says that transforms are handled by TensorFlow Probability's Bijector classes. Which Bijector class handles setting hard limits on parameters, and what is the proper way to implement it?

A similar question was asked here (Kernel's hyper-parameters; initialization and setting bounds) regarding GPflow 1.0. But since GPflow 1.0 did not involve use of Bijectors, I have opened a new question.

Rcameron
  • 116
  • 9

1 Answers1

2

This is fairly easy to do with the chain of bijectors:

In [35]: a = 3.0
    ...: b = 5.0
    ...: affine = tfp.bijectors.AffineScalar(shift=a, scale=(b - a))
    ...: sigmoid = tfp.bijectors.Sigmoid()
    ...: logistic = tfp.bijectors.Chain([affine, sigmoid])

In [36]: logistic.forward(logistic.inverse(3.1) + 0.0)
Out[36]: <tf.Tensor: id=222, shape=(), dtype=float32, numpy=3.1>

Now, you can pass logistic bijector to the Parameter constructor directly.

In [45]: p = gpflow.Parameter(3.1, transform=logistic, dtype=tf.float32)

In [46]: p
Out[46]: <tf.Tensor: id=307, shape=(), dtype=float32, numpy=3.1>

In [47]: p.unconstrained_variable
Out[47]: <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=-2.9444401>
Artem Artemev
  • 516
  • 3
  • 8
  • Sorry to keep asking questions here, but I must not understand how this custom logistic bijector functions. I tried to implement your suggestion, but found that even if I created a kernel with lengthscale equal to p (in your above answer), I could still optimize the kernel to a value far outside of [a,b]. My hope was to find a way to bound a parameter like lengthscale such that it cannot optimize beyond certain values. Is there a way to modify the code such that it works in that way? – Rcameron Nov 29 '19 at 04:57
  • @Rcameron, that sounds like a bug, for that you need to post your MWE. – Artem Artemev Dec 04 '19 at 11:12
  • @[Artem Artemev], I have posted a MWE here: https://stackoverflow.com/questions/59504125/bounding-hyperparameter-optimization-with-tensorflow-bijector-chain-in-gpflow-2 Thanks for your continued help with this! – Rcameron Dec 27 '19 at 17:33