Assigns constrained `value` to the unconstrained parameter's variable. It passes constrained value through parameter's transform first. Example:: a = Parameter(2.0, transform=tfp.bijectors.Softplus()) b = Parameter(3.0) a.assign(4.0)
(
self,
value: "TensorData",
use_locking: bool = False,
name: Optional[str] = None,
read_value: bool = True,
)
| 248 | return self.unconstrained_variable.trainable # type: ignore[no-any-return] |
| 249 | |
| 250 | def assign( |
| 251 | self, |
| 252 | value: "TensorData", |
| 253 | use_locking: bool = False, |
| 254 | name: Optional[str] = None, |
| 255 | read_value: bool = True, |
| 256 | ) -> tf.Tensor: |
| 257 | """ |
| 258 | Assigns constrained `value` to the unconstrained parameter's variable. |
| 259 | It passes constrained value through parameter's transform first. |
| 260 | |
| 261 | Example:: |
| 262 | |
| 263 | a = Parameter(2.0, transform=tfp.bijectors.Softplus()) |
| 264 | b = Parameter(3.0) |
| 265 | |
| 266 | a.assign(4.0) # `a` parameter to `2.0` value. |
| 267 | a.assign(tf.constant(5.0)) # `a` parameter to `5.0` value. |
| 268 | a.assign(b) # `a` parameter to constrained value of `b`. |
| 269 | |
| 270 | |
| 271 | :param value: Constrained tensor-like value. |
| 272 | :param use_locking: If `True`, use locking during the assignment. |
| 273 | :param name: The name of the operation to be created. |
| 274 | :param read_value: if True, will return something which evaluates to the new |
| 275 | value of the variable; if False will return the assign op. |
| 276 | """ |
| 277 | unconstrained_value = _validate_unconstrained_value(value, self.transform, self.dtype) |
| 278 | return self.unconstrained_variable.assign( |
| 279 | unconstrained_value, use_locking=use_locking, name=name, read_value=read_value |
| 280 | ) |
| 281 | |
| 282 | |
| 283 | # These types are defined after "Parameter" to avoid forward references that breaks our |