View source on GitHub
|
Encapsulates tensor normalization and owns normalization variables.
tf_agents.utils.tensor_normalizer.TensorNormalizer(
tensor_spec, scope='normalize_tensor'
)
Example usage:
tensor_normalizer = StreamingTensorNormalizer(
tf.TensorSpec([], tf.float32))
observation_list = [list of float32 scalars or batches]
normalized_list = []
for o in observation_list:
normalized_list.append(tensor_normalizer.normalize(o))
tensor_normalizer.update(o)
For float64 inputs do:
tensor_normalizer = StreamingTensorNormalizer(
tf.TensorSpec([], tf.float64), dtype=tf.float64)
observation_list = [list of float64 scalars or batches]
for o in observation_list:
normalized_list.append(tensor_normalizer.normalize(o))
tensor_normalizer.update(o)
<!-- Tabular view -->
<table class="responsive fixed or>a<nge"><;
colgroupcol wid><th=><"214>p<x&><quot;col/colgr><oup
trth colspan=&q>uot;<2&q><uot><;h2> c<la>s<s=>"add-link<"Args/h2/th/t><r<>/span>
<tr
>t<d<>/span>
`tensor_spec`a id="tensor_spec"<;/a>
</td><
t>d<
T>he specs< of the tens><or>s< to> <no>rmalize.
/td
/trtr
td
`scope<`a >i<d=&>q<uot;sc>ope"/a
/td
<td
Scope for the ><`tf.>Module`.
</td
/><tr
>/t<able
## Methods
h3 id="map_dtype"codemap_dtype/code/h3
a target="_blank" class="external" href=">https://git<hu>b.<com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#>L<89-L>91"View source/a
<pre c><lass>=&quo<t;devsite-click-t><o-co>py pretty<print>< la>ng<-py tfo-signature-link"
codemap_dtype(
dtype
)
/code/pre
h3 id="normalize"codenormalize/code/h3
a target="_bl>ank" c<la>ss<="external" href="https://github.com/tensorflow/agents/bl>o<b/v0>.19.0/tf_agents/utils/tensor_normalizer.py#L134-L205"View source/a
pre class<=&quo><t;de>vsite-click-to-copy prettyprint lang-<py tfo-signature-li>nk<"
codenormalize(
tensor, cli>p<_value=5><.0, center_mean=T><rue><, varianc>e<_e><psilon=0.001
)>
/co<de/><pre>
<Ap>p<li>es normali<zat>i<on> to tensor.
!-- Tabu<lar> <vie><w<>/span> -<-<>/span>
table class=&<quo>t<;r>esponsive fixed orange"
colgroupcol width="214px"col/>colgroup
trth colspan="2"Args</th>/<tr
><
t>r<
t>d
`tensor`
/td
<td
>T<en>sor to normalize.
/td
/trtr
td
`clip_value`
/td
td
Cl<ips> <nor><ma>l<iz>ed observations betw<een> <+/>- this value if
clip_value 0, otherwise does not app<ly<>/span> c<lip>p<ing.
/>td
/<trtr
td
`center_mea>n`<
/td
td
If true, subtracts off mean f>r<om norma><lized tensor.
/td><
/t><rtr
td
`v>a<ri><ance_epsilon`
>/td
td
<Eps><ilo>n <to> <av>oid division by zero <in >n<or>malization.
/td
/tr
/table
!-- Tabu<lar> <vie>w< --
t>able< class="r><espo>nsive <fixed>< or>an<ge"
colgroupcol width="214px"col/colgroup
trth colspan="2"Returns/th/tr
tr
td
`normalized_tensor`
/td
td
Tensor >after apply<in>g <normalization.
/td
/tr
/table
h3 id="update"codeupdate/code>/<h3
>a target="_blank" class=&quo<t;ext><erna>l" href="https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L119-L132"View source/a
pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"
codeupdate(
tensor, outer_dims=(0,)
)
/code/pre
Updates tensor normalizer variables.
View source on GitHub