
    &`iy                         d dl Zd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ  e
            \  ZZZ G d derej        j        j        ne          ZdS )    N)deprecation_warning)get_activation_fn)TensorShape
TensorTypeget_variabletry_import_tf)log_oncec            	       d     e Zd ZdZ	 ddedededef fdZdefd	Z	d
e
de
fdZde
de
fdZ xZS )
NoisyLayera  A Layer that adds learnable Noise to some previous layer's outputs.

    Consists of:
    - a common dense layer: y = w^{T}x + b
    - a noisy layer: y = (w + \epsilon_w*\sigma_w)^{T}x +
        (b+\epsilon_b*\sigma_b)
    , where \epsilon are random variables sampled from factorized normal
    distributions and \sigma are trainable variables which are expected to
    vanish along the training procedure.
    reluprefixout_sizesigma0
activationc                     t                                                       || _        || _        || _        || _        d| _        d| _        d| _        d| _	        t          d          rt          d           dS dS )zInitializes a NoisyLayer object.

        Args:
            prefix:
            out_size: Output size for Noisy Layer
            sigma0: Initialization value for sigma_b (bias noise)
            non_linear: Non-linear activation for Noisy Layer
        Nnoisy_layerz!rllib.models.tf.layers.NoisyLayer)old)super__init__r   r   r   r   wbsigma_wsigma_br	   r   )selfr   r   r   r   	__class__s        z/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/models/tf/layers/noisy_layer.pyr   zNoisyLayer.__init__   s     	  $M"" 	7     	 	    input_shapec                    t          |d                   }t          t          j        j                            dt          j        t          |                    z  dt          j        t          |                    z            d| j	        dz   || j
        gt          j                  | _        t          t          j        j                            | j        t          j        t          |                    z            d| j	        dz   | j
        gt          j                  | _        t          t          j        j                                        | j	        d	z   d|| j
        gt          j        
          | _        t          t          j        j                                        | j	        dz   d| j
        gt          j        
          | _        d S )N   g      g      ?)minvalmaxvalT_sigma_w)value	trainabletf_nameshapedtype_sigma_b_fc_w)r$   r&   r%   r'   r(   _fc_b)intr   tfkerasinitializersRandomUniformnpsqrtfloatr   r   float32r   Constantr   r   GlorotUniformr   Zerosr   )r   r   in_sizes      r   buildzNoisyLayer.build9   s   k!n%%#('55bgeGnn555RWU7^^444 6   K*,DM**	
 	
 	
 $('00rwuW~~?V?V1VWWK*,=/*
 
 
 ('5577K')DM**
 
 
 ('--//K')=/*
 
 
r   inputsreturnc                 ~   t          |j        d                   }t          j                            |g          }t          j                            | j        g          }|                     |          }|                     |          }t                              t                              |d          t                              |d                    }|}t                              || j	        | j
        |z  z             | j        z   | j        |z  z   }t          | j        d          }| ||          }|S )Nr    )r'   r   )ar   r-   )	framework)r,   r'   r-   randomnormalr   
_f_epsilonmatmulexpand_dimsr   r   r   r   r   r   )	r   r:   r8   
epsilon_inepsilon_out	epsilon_w	epsilon_baction_activationfns	            r   callzNoisyLayer.call_   s   fl1o&&Y%%WI%66
i&&dm_&==__Z00
ook22IInnZ,,{A0N0N  
 
	  	 IIfdft|i'??@@flY&' 	 t$???> "#4 5 5  r   xc                     t           j                            |          t           j                            t           j                            |                    z  S )N)r-   mathsignr2   abs)r   rL   s     r   rB   zNoisyLayer._f_epsilonu   s3    w||Abgkk!nn!=!===r   )r   )__name__
__module____qualname____doc__strr,   r3   r   r   r9   r   rK   rB   __classcell__)r   s   @r   r   r      s        	 	 LR %(27EH     :$
 $
 $
 $
 $
L!: !* ! ! ! !,>J >: > > > > > > > >r   r   )numpyr1   ray._common.deprecationr   ray.rllib.models.utilsr   ray.rllib.utils.frameworkr   r   r   r   ray.utilr	   tf1r-   tfvr.   layersLayerobjectr    r   r   <module>rb      s        7 7 7 7 7 7 4 4 4 4 4 4                 }Rf> f> f> f> f>"8&&& f> f> f> f> f>r   