
    6bi                         S r SSKrSSKJs  Jr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  \" S5       " S S	\	R                  5      5       rg)
zContains the Dropout layer.    N)backend)
base_layer)control_flow_util)keras_exportzkeras.layers.Dropoutc                   R   ^  \ rS rSrSrS	U 4S jjrS rS
S jrS rU 4S jr	Sr
U =r$ )Dropout   a  Applies Dropout to the input.

The Dropout layer randomly sets input units to 0 with a frequency of `rate`
at each step during training time, which helps prevent overfitting.
Inputs not set to 0 are scaled up by 1/(1 - rate) such that the sum over
all inputs is unchanged.

Note that the Dropout layer only applies when `training` is set to True
such that no values are dropped during inference. When using `model.fit`,
`training` will be appropriately set to True automatically, and in other
contexts, you can set the kwarg explicitly to True when calling the layer.

(This is in contrast to setting `trainable=False` for a Dropout layer.
`trainable` does not affect the layer's behavior, as Dropout does
not have any variables/weights that can be frozen during training.)

>>> tf.random.set_seed(0)
>>> layer = tf.keras.layers.Dropout(.2, input_shape=(2,))
>>> data = np.arange(10).reshape(5, 2).astype(np.float32)
>>> print(data)
[[0. 1.]
 [2. 3.]
 [4. 5.]
 [6. 7.]
 [8. 9.]]
>>> outputs = layer(data, training=True)
>>> print(outputs)
tf.Tensor(
[[ 0.    1.25]
 [ 2.5   3.75]
 [ 5.    6.25]
 [ 7.5   8.75]
 [10.    0.  ]], shape=(5, 2), dtype=float32)

Args:
  rate: Float between 0 and 1. Fraction of the input units to drop.
  noise_shape: 1D integer tensor representing the shape of the
    binary dropout mask that will be multiplied with the input.
    For instance, if your inputs have shape
    `(batch_size, timesteps, features)` and
    you want the 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 dropout) or in inference mode (doing nothing).
c                    > [         TU ]  " SSU0UD6  [        U[        [        45      (       a  SUs=::  a  S::  d  O  [        SU S35      eXl        X l        X0l        SU l	        g )Nseedr      zInvalid value z7 received for `rate`, expected a value between 0 and 1.T )
super__init__
isinstanceintfloat
ValueErrorratenoise_shaper   supports_masking)selfr   r   r   kwargs	__class__s        d/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/regularization/dropout.pyr   Dropout.__init__Q   sk    -d-f-dS%L))!t.q.  '< <  	&	 $    c                     U R                   c  g [        R                  " U5      n/ n[        U R                   5       H  u  pEUR	                  Uc  X$   OU5        M     [        R
                  " U5      $ N)r   tfshape	enumerateappendconvert_to_tensor)r   inputsconcrete_inputs_shaper   ivalues         r   _get_noise_shapeDropout._get_noise_shape]   sl     # " 0!$"2"23HA,1M%(u 4 ##K00r   c                   ^ ^ [        T R                  [        R                  5      (       a&  T R                  S:X  a  [        R
                  " T5      $ Uc  [        R                  " 5       nUU 4S jn[        R                  " X#U4S j5      nU$ )Nr   c                  l   > TR                   R                  T TR                  TR                  T 5      S9$ )N)r   )_random_generatordropoutr   r(   )r$   r   s   r   dropped_inputs$Dropout.call.<locals>.dropped_inputss   s7    ))11		t/D/DV/L 2  r   c                  0   > [         R                  " T 5      $ r   )r   identity)r$   s   r   <lambda>Dropout.call.<locals>.<lambda>y   s    bkk&.Ar   )
r   r   numbersRealr   r1   r   learning_phaser   
smart_cond)r   r$   trainingr.   outputs   ``   r   callDropout.calll   si    dii..499>;;v&&--/H	
 #--&A
 r   c                     U$ r   r   )r   input_shapes     r   compute_output_shapeDropout.compute_output_shape}   s    r   c                    > U R                   U R                  U R                  S.n[        TU ]  5       n[        [        UR                  5       5      [        UR                  5       5      -   5      $ )N)r   r   r   )r   r   r   r   
get_configdictlistitems)r   configbase_configr   s      r   rA   Dropout.get_config   sY    II++II

 g(*D**,-V\\^0DDEEr   )r   r   r   r   )NNr   )__name__
__module____qualname____firstlineno____doc__r   r(   r:   r>   rA   __static_attributes____classcell__)r   s   @r   r   r      s)    0d
%1"F Fr   r   )rL   r4   tensorflow.compat.v2compatv2r   tf_keras.srcr   tf_keras.src.enginer   tf_keras.src.utilsr    tensorflow.python.util.tf_exportr   BaseRandomLayerr   r   r   r   <module>rW      sN    "  ! !   * 0 : $%iFj(( iF &iFr   