
    &`iY                     X    d dl Zd dlZd dlmZ e G d dej                              ZdS )    N)	PublicAPIc                   V     e Zd ZdZdej        f fd	Zd Zd Zd Z	d Z
d Zd	 Z xZS )
Simplexa  Represents a d - 1 dimensional Simplex in R^d.

    That is, all coordinates are in [0, 1] and sum to 1.
    The dimension d of the simplex is assumed to be shape[-1].

    Additionally one can specify the underlying distribution of
    the simplex as a Dirichlet distribution by providing concentration
    parameters. By default, sampling is uniform, i.e. concentration is
    all 1s.

    Example usage:
    self.action_space = spaces.Simplex(shape=(3, 4))
        --> 3 independent 4d Dirichlet with uniform concentration
    Nc                 v   t          |          t          t          fv sJ t                                          ||           | j        d         | _        |@|j        d         |d         k    s J |j        d          d|d                      || _        d S t          j	        dg| j        z            | _        d S )Nr   z vs    )
typetuplelistsuper__init__shapedimconcentrationnparray)selfr   r   dtype	__class__s       r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/utils/spaces/simplex.pyr   zSimplex.__init__   s    E{{udm++++&&&:b>$#A&%)333%a(99eBi99 433!.D!#1#.!9!9D    c                     t           j                            | j        | j        d d                                       | j                  S )Nr   )size)r   random	dirichletr   r   astyper   r   s    r   samplezSimplex.sample&   sA    y""4#5DJssO"LLSSJ
 
 	
r   c                     |j         | j         k    o@t          j        t          j        |d          t          j        |d                             S )Nr   )axis).r   )r   r   allclosesum	ones_like)r   xs     r   containszSimplex.contains+   sH    w$*$ 
F12QvY 7 7*
 *
 	
r   c                 N    t          j        |                                          S N)r   r   tolistr   sample_ns     r   to_jsonablezSimplex.to_jsonable0   s    x!!((***r   c                     d |D             S )Nc                 6    g | ]}t          j        |          S  )r   asarray).0r   s     r   
<listcomp>z)Simplex.from_jsonable.<locals>.<listcomp>4   s"    :::v
6"":::r   r.   r)   s     r   from_jsonablezSimplex.from_jsonable3   s    ::::::r   c                 B    d                     | j        | j                  S )NzSimplex({}; {}))formatr   r   r   s    r   __repr__zSimplex.__repr__6   s     ''
D4FGGGr   c                 `    t          j        | j        |j                  o| j        |j        k    S r'   )r   r!   r   r   )r   others     r   __eq__zSimplex.__eq__9   s-    K*E,?@@ *
ek)	
r   )__name__
__module____qualname____doc__r   float32r   r   r%   r+   r2   r5   r8   __classcell__)r   s   @r   r   r      s          -1
 : : : : : :
 
 


 
 

+ + +; ; ;H H H
 
 
 
 
 
 
r   r   )	gymnasiumgymnumpyr   ray.rllib.utils.annotationsr   Spacer   r.   r   r   <module>rD      sq            1 1 1 1 1 1 5
 5
 5
 5
 5
ci 5
 5
 5
 5
 5
r   