
    2Vh)                     `    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y)	    )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).
    c                    t        |   di | d|cxk  rdk  sn t        d|       || _        || _        || _        |dkD  r$t        j                  j                  |      | _	        d| _
        | j                          y )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_build_at_init)selfr   r   r   kwargs	__class__s        ]/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/layers/regularization/alpha_dropout.pyr   zAlphaDropout.__init__#   s    "6"D~A~""&) 
 		&!8")..">">t"DD $    c                    |r| j                   dkD  r| j                  || j                        }d}d}| |z  }t        j                  t        j
                  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.call4   s    		A88((K 6E5EfunG((

"";T5H5H"I		H xx&,,7H dii-A		GQJ(>$>?DHAWtyy(A !Gq8|$<<Aq519r   c                     |S Nr   )r   input_shapes     r   compute_output_shapez!AlphaDropout.compute_output_shapeM   s    r   c                     |t        j                  |      S t        j                  |      }g }t        |      D ]  \  }}|j                  |||   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_shapeP   si    99V$$ #		& 1!!+. 	HAu '',1M%a(u	 $#r   c                 t    t         |          }| j                  | j                  | j                  d}i ||S )N)r   r   r   )r   
get_configr   r   r   )r   base_configconfigr   s      r   r:   zAlphaDropout.get_config\   s@    g(*IIII++

 )+(((r   )NN)F)
__name__
__module____qualname____doc__r   r,   r0   r   r:   __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>rE      s5      - ( )*[)5 [) +[)r   