tfp.bijectors.tree_flatten
Stay organized with collections
Save and categorize content based on your preferences.
Returns a Bijector variant of tf.nest.flatten.
tfp.bijectors.tree_flatten(
example, name='restructure'
)
To make it a Bijector, it has to know how to "unflatten" as
well---unlike the real tf.nest.flatten
, this can only flatten or
unflatten a specific structure. The example
argument defines the
structure.
See also the Restructure
bijector for general rearrangements.
Args |
example
|
A Tensor or (potentially nested) collection of Tensors.
|
name
|
An optional Python string, inserted into names of TF ops
created by this bijector.
|
Returns |
flatten
|
A Bijector whose forward method flattens structures
parallel to example into a list of Tensors, and whose
inverse method packs a list of Tensors of the right length
into a structure parallel to example .
|
Example
x = tf.constant(1)
example = collections.OrderedDict([
('a', [x, x, x]),
('b', x)])
bij = tfb.tree_flatten(example)
ys = collections.OrderedDict([
('a', [1, 2, 3]),
('b', 4.)])
bij.forward(ys)
# Returns [1, 2, 3, 4.]
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-11-21 UTC.
[null,null,["Last updated 2023-11-21 UTC."],[],[],null,["# tfp.bijectors.tree_flatten\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/bijectors/restructure.py#L273-L310) |\n\nReturns a Bijector variant of tf.nest.flatten. \n\n tfp.bijectors.tree_flatten(\n example, name='restructure'\n )\n\nTo make it a Bijector, it has to know how to \"unflatten\" as\nwell---unlike the real [`tf.nest.flatten`](https://www.tensorflow.org/api_docs/python/tf/nest/flatten), this can only flatten or\nunflatten a specific structure. The `example` argument defines the\nstructure.\n\nSee also the `Restructure` bijector for general rearrangements.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|------------------------------------------------------------------------------------|\n| `example` | A Tensor or (potentially nested) collection of Tensors. |\n| `name` | An optional Python string, inserted into names of TF ops created by this bijector. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `flatten` | A Bijector whose `forward` method flattens structures parallel to `example` into a list of Tensors, and whose `inverse` method packs a list of Tensors of the right length into a structure parallel to `example`. |\n\n\u003cbr /\u003e\n\n#### Example\n\n x = tf.constant(1)\n example = collections.OrderedDict([\n ('a', [x, x, x]),\n ('b', x)])\n bij = tfb.tree_flatten(example)\n ys = collections.OrderedDict([\n ('a', [1, 2, 3]),\n ('b', 4.)])\n bij.forward(ys)\n # Returns [1, 2, 3, 4.]"]]