问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/58903446/setting-hyperparameter-optimization-bounds-in-gpflow-2-0