
    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S/S9 " S	 S
\
R                  5      5       rg)z"Adadelta optimizer implementation.    N)backend_config)optimizer_v2)keras_exportz keras.optimizers.legacy.Adadeltazkeras.optimizers.Adadelta)v1c                   z   ^  \ rS rSrSrSr    SU 4S jjrS rU 4S jrU 4S jr	SS jr
SS	 jrU 4S
 jrSrU =r$ )Adadelta   a  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.
    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.
    Defaults to `0.001`.
  rho: A `Tensor` or a floating point value. The decay rate.
  epsilon: Small floating point value used to maintain numerical stability.
  name: Optional name prefix for the operations created when applying
    gradients.  Defaults to `"Adadelta"`.
  **kwargs: keyword arguments. Allowed arguments are `clipvalue`,
    `clipnorm`, `global_clipnorm`.
    If `clipvalue` (float) is set, the gradient of each weight
    is clipped to be no higher than this value.
    If `clipnorm` (float) is set, the gradient of each weight
    is individually clipped so that its norm is no higher than this value.
    If `global_clipnorm` (float) is set the gradient of all weights is
    clipped so that their global norm is no higher than this value.

Reference:
  - [Zeiler, 2012](http://arxiv.org/abs/1212.5701)
Tc                   > [         TU ]  " U40 UD6  U R                  SUR                  SU5      5        U R                  SU R                  5        U R                  SU5        U=(       d    [
        R                  " 5       U l        g )Nlearning_ratelrdecayrho)super__init__
_set_hyperget_initial_decayr   epsilon)selfr   r   r   namekwargs	__class__s         a/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/optimizers/legacy/adadelta.pyr   Adadelta.__init__J   sg     	((D-)HI!4!45s#:."8"8":    c                 p    U H  nU R                  US5        M     U H  nU R                  US5        M     g )N
accum_grad	accum_var)add_slot)r   var_listvs      r   _create_slotsAdadelta._create_slotsX   s2    AMM!\* AMM![) r   c                    > [         TU ]  XU5        X1U4   R                  [        [        R
                  " U R                  U5      [        R                  " U R                  SU5      5      S95        g )Nr   )r   r   )	r   _prepare_localupdatedicttfconvert_to_tensorr   identity
_get_hyper)r   
var_device	var_dtypeapply_stater   s       r   r%   Adadelta._prepare_local_   s[    zkB+,33,,T\\9EKKy AB	
r   c                    > U R                   n[        U5      [        U5      S-   :X  a  [        R                  " S5      /U-   n[        TU ]  U5        g )N   r   )weightslennparrayr   set_weights)r   r2   paramsr   s      r   r6   Adadelta.set_weightsh   sD     v;#g,**xx{mg-GG$r   c                    UR                   UR                  R                  pTU=(       d    0 R                  XE45      =(       d    U R	                  XE5      nU R                  US5      nU R                  US5      n[        R                  R                  UR                  UR                  UR                  US   US   US   UU R                  S9$ )Nr   r   lr_tr   r   )varaccumaccum_updater   r   r   graduse_locking)devicedtype
base_dtyper   _fallback_apply_stateget_slotr(   raw_opsResourceApplyAdadeltahandle_use_locking)	r   r>   r;   r.   r,   r-   coefficientsr   r   s	            r   _resource_apply_denseAdadelta._resource_apply_denseq   s     #

CII,@,@I#)r..#
 ?''
> 	 ]]35
MM#{3	zz//

##"))F#U# +)) 0 	
 		
r   c                    UR                   UR                  R                  peU=(       d    0 R                  XV45      =(       d    U R	                  XV5      nU R                  US5      nU R                  US5      n	[        R                  R                  UR                  UR                  U	R                  US   US   US   UUU R                  S9	$ )Nr   r   r:   r   r   )	r;   r<   r=   r   r   r   r>   indicesr?   )r@   rA   rB   r   rC   rD   r(   rE   ResourceSparseApplyAdadeltarG   rH   )
r   r>   r;   rM   r.   r,   r-   rI   r   r   s
             r   _resource_apply_sparseAdadelta._resource_apply_sparse   s     #

CII,@,@I#)r..#
 ?''
> 	 ]]35
MM#{3	zz55

##"))F#U# +)) 6 

 
	
r   c                    > [         TU ]  5       nUR                  U R                  S5      U R                  U R                  S5      U R
                  S.5        U$ )Nr   r   )r   r   r   r   )r   
get_configr&   _serialize_hyperparameterr   r   )r   configr   s     r   rR   Adadelta.get_config   sY    #%!%!?!?#" ,,55e<<<		
 r   )r   )gMbP?gffffff?gHz>r   )N)__name__
__module____qualname____firstlineno____doc___HAS_AGGREGATE_GRADr   r"   r%   r6   rJ   rO   rR   __static_attributes____classcell__)r   s   @r   r   r      sG    
&P  ;*
%
&
( r   r   )rZ   numpyr4   tensorflow.compat.v2compatv2r(   tf_keras.srcr   tf_keras.src.optimizers.legacyr    tensorflow.python.util.tf_exportr   OptimizerV2r    r   r   <module>rg      sS    )  ! ! ' 7 : &#%GHE|'' E	Er   