
    h                          S SK r " S S5      rg)    Nc                       \ rS rSrSS\S\\S4   4S jjrSS jrSS	 jr	S
\
R                  SS4S jrS\
R                  S\
R                  S\SS4S jrSrg)RunningMeanStd   epsilonshape.c                     [         R                  " U[         R                  5      U l        [         R                  " U[         R                  5      U l        Xl        g)z
Calculates the running mean and std of a data stream
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm

:param epsilon: helps with arithmetic issues
:param shape: the shape of the data stream's output
N)npzerosfloat64meanonesvarcount)selfr   r   s      c/home/james-whalen/.local/lib/python3.13/site-packages/stable_baselines3/common/running_mean_std.py__init__RunningMeanStd.__init__   s5     HHUBJJ/	775"**-
    returnc                     [        U R                  R                  S9nU R                  R                  5       Ul        U R                  R                  5       Ul        [        U R                  5      Ul        U$ )z/
:return: Return a copy of the current object.
)r   )r   r   r   copyr   floatr   )r   
new_objects     r   r   RunningMeanStd.copy   sP     $$))//:
))..*

 ,
r   Nc                 f    U R                  UR                  UR                  UR                  5        g)zh
Combine stats from another ``RunningMeanStd`` object.

:param other: The other object to combine with.
N)update_from_momentsr   r   r   )r   others     r   combineRunningMeanStd.combine   s"     	  UYYDr   arrc                     [         R                  " USS9n[         R                  " USS9nUR                  S   nU R	                  X#U5        g )Nr   )axis)r	   r   r   r   r   )r   r    
batch_mean	batch_varbatch_counts        r   updateRunningMeanStd.update#   s?    WWSq)
FF3Q'	iil  Dr   r#   r$   r%   c                 x   XR                   -
  nU R                  U-   nU R                   XC-  U-  -   nU R                  U R                  -  nX#-  nXx-   [        R                  " U5      U R                  -  U-  U R                  U-   -  -   n	XR                  U-   -  n
X0R                  -   nX`l         Xl        Xl        g )N)r   r   r   r	   square)r   r#   r$   r%   delta	tot_countnew_meanm_am_bm_2new_var	new_counts               r   r   "RunningMeanStd.update_from_moments)   s    YY&JJ,	99u2Y>>hh#%i"))E*TZZ7+EVaIabbk12**,		
r   )r   r   r   )g-C6? )r   r   )r   r   r   N)__name__
__module____qualname____firstlineno__r   tupleintr   r   r   r	   ndarrayr&   r   __static_attributes__r3   r   r   r   r      sm    
 
U38_ 
EE"** E Ebjj RZZ ^c hl r   r   )numpyr	   r   r3   r   r   <module>r=      s    3 3r   