
    &Vf
                     t    d dl mZ d dl mZ d dlmZ d dlmZ  ed           G d de                      ZdS )	    )backend)ops)keras_export)Layerzkeras.layers.AlphaDropoutc                   B     e Zd ZdZd	 fd	Zd
dZd Zd Z fdZ xZ	S )AlphaDropouta  Applies Alpha Dropout to the input.

    Alpha Dropout is a `Dropout` that keeps mean and variance of inputs
    to their original values, in order to ensure the self-normalizing property
    even after this dropout.
    Alpha Dropout fits well to Scaled Exponential Linear Units (SELU) by
    randomly setting activations to the negative saturation value.

    Args:
        rate: Float between 0 and 1. The multiplicative noise will have
            standard deviation `sqrt(rate / (1 - rate))`.
        noise_shape: 1D integer tensor representing the shape of the
            binary alpha dropout mask that will be multiplied with the input.
            For instance, if your inputs have shape
            `(batch_size, timesteps, features)` and
            you want the alpha dropout mask to be the same for all timesteps,
            you can use `noise_shape=(batch_size, 1, features)`.
        seed: A Python integer to use as random seed.

    Call arguments:
        inputs: Input tensor (of any rank).
        training: Python boolean indicating whether the layer should behave in
            training mode (adding alpha dropout) or in inference mode
            (doing nothing).
    Nc                     t                      j        di | d|cxk    rdk    sn t          d|           || _        || _        || _        |dk    r$t          j                            |          | _	        d| _
        d S )Nr      zcInvalid value received for argument `rate`. Expected a float value between 0 and 1. Received: rate=T )super__init__
ValueErrorrateseednoise_shaper   randomSeedGeneratorseed_generatorsupports_masking)selfr   r   r   kwargs	__class__s        j/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/layers/regularization/alpha_dropout.pyr   zAlphaDropout.__init__#   s    ""6"""D~~~~A~~~~)"&) )  
 		&!88").">">t"D"DD $    Fc                    |r| j         dk    r|                     || j                  }d}d}| |z  }t          j        t          j                            || j                  | j                   }t          j        ||j	                  }d| j         z
  d| j         |dz  z  z   z  dz  }| |z  | j         z  }	||z  |d|z
  z  z   }
||
z  |	z   S |S )Nr   g,x?g2֫?)r   r
      g      )
r   _get_concrete_noise_shaper   r   greater_equalr   uniformr   castdtype)r   inputstrainingr   alphascalealpha_pkept_idxabxs              r   callzAlphaDropout.call2   s     		A88( K 6E5EfunG(
"";T5H"II	 H x&,77H di-A	GQJ(>$>?DHAWty(A !Gq8|$<<Aq519r   c                     |S Nr   )r   input_shapes     r   compute_output_shapez!AlphaDropout.compute_output_shapeK   s    r   c                     |t          j        |          S t          j        |          }g }t          |          D ]$\  }}|                    |||         n|           %|S r-   )r   shape	enumerateappend)r   r"   r   concrete_inputs_shapeconcrete_noise_shapeivalues          r   r   z&AlphaDropout._get_concrete_noise_shapeN   s    9V$$$ #	& 1 1!!+.. 	 	HAu '',1M%a((u    $#r   c                 z    t                                                      }| j        | j        | j        d}i ||S )N)r   r   r   )r   
get_configr   r   r   )r   base_configconfigr   s      r   r9   zAlphaDropout.get_configZ   sF    gg((**II+
 

 )+(((r   )NN)F)
__name__
__module____qualname____doc__r   r+   r/   r   r9   __classcell__)r   s   @r   r   r      s         4% % % % % %   2  
$ 
$ 
$) ) ) ) ) ) ) ) )r   r   N)	keras.srcr   r   keras.src.api_exportr   keras.src.layers.layerr   r   r   r   r   <module>rD      s                - - - - - - ( ( ( ( ( ( )**Y) Y) Y) Y) Y)5 Y) Y) +*Y) Y) Y)r   