使用双射器链很容易做到这一点:
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>
现在,您可以logistic
直接将 bijector 传递给 Parameter 构造函数。
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>