
    &`i	                     D    d dl Zd dlmZ e G d d                      ZdS )    N)OldAPIStackc                   ^    e Zd ZdZdedefdZddZdefdZ	defd	Z
dej        fd
Zd ZdS )
WindowStata  Handles/stores incoming dataset and provides window-based statistics.

    .. testcode::
        :skipif: True

        win_stats = WindowStat("level", 3)
        win_stats.push(5.0)
        win_stats.push(7.0)
        win_stats.push(7.0)
        win_stats.push(10.0)
        # Expect 8.0 as the mean of the last 3 values: (7+7+10)/3=8.0
        print(win_stats.mean())

    .. testoutput::

        8.0
    namenc                 ^    || _         || _        dg| j         z  | _        d| _        d| _        dS )zInitializes a WindowStat instance.

        Args:
            name: The name of the stats to collect and return stats for.
            n: The window size. Statistics will be computed for the last n
                items received from the stream.
        Nr   )window_sizer   itemsidxcount)selfr   r   s      w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/utils/metrics/window_stat.py__init__zWindowStat.__init__   s6     	Vd..



    returnNc                     || j         | j        <   | xj        dz  c_        | xj        dz  c_        | xj        t          | j                   z  c_        dS )z/Pushes a new value/object into the data buffer.   N)r
   r   r   len)r   objs     r   pushzWindowStat.push-   sL      #
48A

a

C
OO#r   c                 h    t          t          j        | j        d| j                                     S )z<Returns the (NaN-)mean of the last `self.window_size` items.N)floatnpnanmeanr
   r   r   s    r   meanzWindowStat.mean8   s'    RZ
<TZ< 899:::r   c                 h    t          t          j        | j        d| j                                     S )z>Returns the (NaN)-stddev of the last `self.window_size` items.N)r   r   nanstdr
   r   r   s    r   stdzWindowStat.std<   s'    RYtz,DJ,788999r   c                     | j         s t          j        g t          j                  S t          j        | j        d| j                  g d                                          S )z8Returns ndarray with 0, 10, 50, 90, and 100 percentiles.)dtypeN)r   
   2   Z   d   )r   r   ndarrayfloat32nanpercentiler
   tolistr   s    r   	quantileszWindowStat.quantiles@   sZ    z 	:b
3333#
<TZ<(*>*>*> fhhr   c           	          | j         dz   t          | j                  | j         dz   |                                 | j         dz   |                                 | j         dz   |                                 iS )N_count_mean_std
_quantiles)r   intr   r   r   r*   r   s    r   statszWindowStat.statsI   s^    I #dj//II

I$dnn&6&6	
 	
r   )r   N)__name__
__module____qualname____doc__strr0   r   r   r   r   r   r   r&   r*   r1    r   r   r   r      s         $S S    &	$ 	$ 	$ 	$;e ; ; ; ;:U : : : :2:    
 
 
 
 
r   r   )numpyr   ray.rllib.utils.annotationsr   r   r7   r   r   <module>r:      sk        3 3 3 3 3 3 H
 H
 H
 H
 H
 H
 H
 H
 H
 H
r   