
    ni	                     v    S r SSKJr  SSKJr  SSKJr   SSKJs  Jr   " S S\5      rg! \	 a    SSK
r Nf = f)@Compute a streaming estimation of the mean of submitted tensors.    )absolute_import)division)print_functionNc                   J    \ rS rSrSrS r\S 5       r\S 5       rS r	S r
Srg	)
StreamingMean   r   c                    ^^ TU l         [        R                  " UU4S jS5      U l        [        R                  " S SS9U l        g)a   Specify the shape and dtype of the mean to be estimated.

Note that a float mean to zero submitted elements is NaN, while computing
the integer mean of zero elements raises a division by zero error.

Args:
  shape: Shape of the mean to compute.
  dtype: Data type of the mean to compute.
c                  2   > [         R                  " TT 5      $ )N)tfzeros)dtypeshapes   c/home/james-whalen/.local/lib/python3.13/site-packages/pybullet_envs/agents/tools/streaming_mean.py<lambda>(StreamingMean.__init__.<locals>.<lambda>'   s    BHHUE$:    Fc                      g)Nr    r   r   r   r   r   (   s    ar   )	trainableN)_dtyper   Variable_sum_count)selfr   r   s    ``r   __init__StreamingMean.__init__   s1     DK:EBDI++i59DKr   c                 r    U R                   [        R                  " U R                  U R                  5      -  $ )zThe current value of the mean.)r   r   castr   r   r   s    r   valueStreamingMean.value*   s&     99rwwt{{DKK888r   c                     U R                   $ )z The number of submitted samples.)r   r    s    r   countStreamingMean.count/   s     ;;r   c                 f   UR                   R                  U R                  R                   R                  :X  a  US   n[        R                  " U R                  R                  [        R                  " US5      5      U R                  R                  [        R                   " U5      S   5      5      $ )z=Submit a single or batch tensor to refine the streaming mean.)N.r   )r   ndimsr   r   group
assign_add
reduce_sumr   )r   r!   s     r   submitStreamingMean.submit4   s|     {{DIIOO111Ie88DII((ua)@AKK**288E?1+=>@ @r   c                    U R                   [        R                  " U R                  U R                  5      -  n[        R
                  " U/5         U R                   R                  [        R                  " U R                   5      5      nU R                  R                  S5      nSSS5        [        R
                  " WW/5         [        R                  " U5      sSSS5        $ ! , (       d  f       NF= f! , (       d  f       g= f)z<Return the mean estimate and reset the streaming statistics.r   N)	r   r   r   r   r   control_dependenciesassign
zeros_likeidentity)r   r!   reset_valuereset_counts       r   clearStreamingMean.clear<   s    IIT[[99E		 	 %	)II$$R]]499%=>kKK&&q)k 
* 
	 	 +{!;	<[[ 
=	< 
*	) 
=	<s   AC%C6%
C36
D)r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   propertyr!   r$   r+   r4   __static_attributes__r   r   r   r   r      s=    H: 9 9  @ r   r   )r:   
__future__r   r   r   tensorflow.compat.v1compatv1r   	Exception
tensorflowobjectr   r   r   r   <module>rD      s?    G &  %##
* F * 	  s   	+ 
88