
    |h                         d Z ddlmc mZ ddlmZ ddlmZ ddl	m
Z
  e        e
dddg 	       G d
 dej                                      Zej                   j                  dej                        e_         y)z"Adadelta optimizer implementation.    N)	optimizer)register_keras_serializable)keras_exportzkeras.optimizers.Adadeltaz&keras.optimizers.experimental.Adadeltaz.keras.dtensor.experimental.optimizers.Adadelta)v1c                   V     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 TF-Keras optimizers.

    Args:
        learning_rate: Initial value for the learning rate: either a floating
            point value, or a
            `tf.keras.optimizers.schedules.LearningRateSchedule` instance.
            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 `Tensor` or a floating point value. The decay rate. Defaults to
            0.95.
        epsilon: Small floating point value used to maintain numerical
            stability. Defaults to 1e-7.
      {{base_optimizer_keyword_args}}

    Reference:
        - [Zeiler, 2012](http://arxiv.org/abs/1212.5701)
    c                     t        |   d||||||	|
||d	| | j                  |      | _        || _        || _        y )N)	weight_decayclipnorm	clipvalueglobal_clipnormuse_emaema_momentumema_overwrite_frequencyjit_compilename )super__init___build_learning_rate_learning_raterhoepsilon)selflearning_rater   r   r
   r   r   r   r   r   r   r   r   kwargs	__class__s                 _/var/www/html/test/engine/venv/lib/python3.12/site-packages/tf_keras/src/optimizers/adadelta.pyr   zAdadelta.__init__B   s_      	 	
%+%$;#	
 	
 #77F    c                 :   t         |   |       t        | d      r| j                  ry d| _        g | _        g | _        |D ]X  }| j                  j                  | j                  |d             | j
                  j                  | j                  |d             Z y )N_builtTaccumulated_gradaccumulated_delta_var)r   buildhasattrr!   _accumulated_grads_accumulated_delta_varsappendadd_variable_from_reference)r   var_listvarr   s      r   r$   zAdadelta.buildb   s    h4"t{{"$')$ 	C##**006HI ((//006MN		r   c                 R    t        j                   j                  |j                        } j	                  |      } j
                  } j                   j                  |      } j                   j                  |      } fd}t        |t         j                        r|j                  |dz
  |z         |j                  t        j                  d|z
  t        j                  |j                        z  |j                                ||       |z   ||      z  }	|j!                  ||z  d|z
  |	z  |	z  z          nU|j!                  ||z  d|z
  |z  |z  z           ||       |z   ||      z  }	|j!                  ||z  d|z
  |	z  |	z  z          |j                  ||	z         y)z=Update step given gradient and the associated model variable.c                 H    t        j                  | j                  z         S )N)tfsqrtr   )xr   s    r   rmsz!Adadelta.update_step.<locals>.rms|   s    771t||+,,r      N)r.   castr   dtype_var_keyr   r&   _index_dictr'   
isinstanceIndexedSlices
assign_addscatter_addsquarevaluesindicesassign)
r   gradvariablelrvar_keyr   r"   r#   r1   	delta_vars
   `         r   update_stepzAdadelta.update_stepq   s   WWT''8--)hh2243C3CG3LM $ < <W%!
	- dB,,-''q4D(DE((  W		$++ 66 *++d2S9I5JJ  "((++q3w).Ci.OO
 ##&&!c'T)9D)@@ *++d2S9I5JJ  "((++q3w).Ci.OO 	BN+r   c                     t         |          }|j                  | j                  | j                        | j
                  | j                  d       |S )N)r   r   r   )r   
get_configupdate_serialize_hyperparameterr   r   r   )r   configr   s     r   rF   zAdadelta.get_config   sO    #%!%!?!?''" xx<<	
 r   )gMbP?gffffff?gHz>NNNNFgGz?NTr   )	__name__
__module____qualname____doc__r   r$   rD   rF   __classcell__)r   s   @r   r   r      sJ    D  $@',R r   r   z{{base_optimizer_keyword_args}})rM   tensorflow.compat.v2compatv2r.   tf_keras.src.optimizersr   'tf_keras.src.saving.object_registrationr    tensorflow.python.util.tf_exportr   	Optimizerr   replacebase_optimizer_keyword_argsr   r   r   <module>rX      s    ) ! ! - O : ,4		Ey"" E EP ##++%y'L'L r   