
    2Vh                         d dl mZ d dlmZ d dlmZ  edg       G d dej                               Zej                  j                  dej                        e_        y)	    )ops)keras_export)	optimizerzkeras.optimizers.Adadeltac                   X     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z fdZd Z fdZ xZS )Adadeltaa  Optimizer that implements the Adadelta algorithm.

    Adadelta optimization is a stochastic gradient descent method that is based
    on adaptive learning rate per dimension to address two drawbacks:

    - The continual decay of learning rates throughout training.
    - The need for a manually selected global learning rate.

    Adadelta is a more robust extension of Adagrad that adapts learning rates
    based on a moving window of gradient updates, instead of accumulating all
    past gradients. This way, Adadelta continues learning even when many updates
    have been done. Compared to Adagrad, in the original version of Adadelta you
    don't have to set an initial learning rate. In this version, the initial
    learning rate can be set, as in most other Keras optimizers.

    Args:
        learning_rate: A float, a
            `keras.optimizers.schedules.LearningRateSchedule` instance, or
            a callable that takes no arguments and returns the actual value to
            use. The learning rate. Defaults to `0.001`. Note that `Adadelta`
            tends to benefit from higher initial learning rate values compared
            to other optimizers. To match the exact form in the original paper,
            use 1.0.
        rho: A floating point value. The decay rate. Defaults to `0.95`.
        epsilon: Small floating point value for maintaining numerical stability.
        {{base_optimizer_keyword_args}}

    Reference:

    - [Zeiler, 2012](http://arxiv.org/abs/1212.5701)
    c                 X    t        |   d|||||||	|
|||d| || _        || _        y )N)learning_rateweight_decayclipnorm	clipvalueglobal_clipnormuse_emaema_momentumema_overwrite_frequencyloss_scale_factorgradient_accumulation_stepsname )super__init__rhoepsilon)selfr	   r   r   r
   r   r   r   r   r   r   r   r   r   kwargs	__class__s                  M/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/optimizers/adadelta.pyr   zAdadelta.__init__(   sR    " 	 	
'%+%$;/(C	
 	
     c                     | j                   ry t        | 	  |       | j                  |ddg      \  | _        | _        y )Naccumulated_gradaccumulated_delta_var)builtr   buildadd_optimizer_variables_accumulated_grads_accumulated_delta_vars)r   var_listr   s     r   r"   zAdadelta.buildJ   sB    ::h((-/FG 	>!=r   c                 l    t        j                  ||j                        }t        j                  ||j                        } j                  } j                   j                  |         } j                   j                  |         } fd} j                  |t        j                  ||z  t        j                  d|z
  t        j                  |                         t        j                  t        j                  t        j                   ||      |       ||                  }	 j                  |t        j                  t        j                  ||      t        j                  d|z
  t        j                  |	                          j                  |t        j                  ||	             y)z=Update step given gradient and the associated model variable.c                 j    t        j                  t        j                  | j                              S )N)r   sqrtaddr   )xr   s    r   rmsz!Adadelta.update_step.<locals>.rmsa   s!    88CGGAt||455r      N)r   castdtyper   r$   _get_variable_indexr%   assignr*   multiplysquarenegativedivide
assign_add)
r   gradvariabler	   lrr   r   r    r,   	delta_vars
   `         r   update_stepzAdadelta.update_stepT   sT   XXmX^^4xxhnn-hh22$$X.
 !% < <$$X.!
	6 	GG&&QWcjj>N(O	
 LLJJS!67>$%
	 	!GGS"78QWcjj&;<	
 	#,,r9"=>r   c                 t    t         |          }|j                  | j                  | j                  d       |S )N)r   r   )r   
get_configupdater   r   )r   configr   s     r   r=   zAdadelta.get_configy   s6    #%xx<<	
 r   )gMbP?gffffff?gHz>NNNNFgGz?NNNadadelta)	__name__
__module____qualname____doc__r   r"   r;   r=   __classcell__)r   s   @r   r   r      sM    D  $$( D
#?J	 	r   r   z{{base_optimizer_keyword_args}}N)	keras.srcr   keras.src.api_exportr   keras.src.optimizersr   	Optimizerr   rD   replacebase_optimizer_keyword_argsr   r   r   <module>rL      sb     - * *+,{y"" { -{| ##++%y'L'L r   