Transformed variables with non-elementwise bijectors

29 views
Skip to first unread message

Paul Welle

unread,
Mar 24, 2021, 1:57:34 PM3/24/21
to TensorFlow Probability
Hi folks -

Trying to understand how 'Transformed Variables' work with bijectors that DON'T operate elementwise. My understanding how how TransformedVariables work comes from the docs, which state `Variable tracking object which applies a bijector upon convert_to_tensor.` Great, that's what I'm looking for.

So for example, with `FillTriangular` I see that this works:

x = [1, 1, 1, 1, 1, 1]
b = tfb.FillTriangular()
b.forward(x)

and returns 3 x 3 matrix with lower diagonal 1's.

however, this breaks:

x = [1, 1, 1, 1, 1, 1]
b = tfb.FillTriangular()
v = tfp.util.TransformedVariable(x, b)

with error `ValueError: Shape (6,) must have rank at least 2`.

It seems like TransformedVariable is looking for a 2 dimensional array, so I tried feeding:

b = tfb.FillTriangular()
new_x = tf.ones((3,3))
v = tfp.util.TransformedVariable(new_x, b)

The result for that code is:
2 0 0
2 2 0
1 1 1

Which I don't see how it's arriving at. Is there something I'm missing here?

Thanks for any help,
Paul

Pavel Sountsov

unread,
Mar 24, 2021, 3:04:41 PM3/24/21
to Paul Welle, TensorFlow Probability
In general, the `initial_value` argument to `TransformedVariable`'s constructor corresponds to the *transformed* output, i.e., if it is valid, then the following equality should hold `initial_value == tf.convert_to_tensor(TransformedVariable(initial_value, bijector))`. Internally, the underlying `tf.Variable` is initialized with `bijector.inverse(initial_value)`.

In your case, your initial value is not valid because it is not a (lower) triangular matrix, so the `FillTriangular.inverse` returns undefined output. If you already have a lower triangular matrix in mind, you can use it as `initial_value`. Otherwise, your first code snippet can be changed to:

```
x = [1, 1, 1, 1, 1, 1]
b = tfb.FillTriangular()
v = tfp.util.TransformedVariable(b(x), b)  # b(x) <=> b.forward(x)
```

We'll improve the documentation to make this clearer, thanks for bringing it up.


--
You received this message because you are subscribed to the Google Groups "TensorFlow Probability" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfprobabilit...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfprobability/04989257-dc01-4de1-9c83-3130a197165cn%40tensorflow.org.
Reply all
Reply to author
Forward
0 new messages