
    &VfN                         d dl mZ 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	        
                    dej                  e_	        d	S )
    )initializers)ops)keras_export)	optimizerzkeras.optimizers.Adagradc                   X     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 d fd		Z fd
Zd Z fdZ xZS )Adagradaq  Optimizer that implements the Adagrad algorithm.

    Adagrad is an optimizer with parameter-specific learning rates,
    which are adapted relative to how frequently a parameter gets
    updated during training. The more updates a parameter receives,
    the smaller the updates.

    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 `Adagrad`
            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`.
        initial_accumulator_value: Floating point value. Starting value for the
            accumulators (per-parameter momentum values). Must be non-negative.
        epsilon: Small floating point value for maintaining numerical stability.
        {{base_optimizer_keyword_args}}

    Reference:

    - [Duchi et al., 2011](
        http://www.jmlr.org/papers/volume12/duchi11a/duchi11a.pdf).
    MbP?皙?Hz>NFGz?adagradc                 n     t                      j        d|||||||	|
|||d| || _        || _        d S )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__initial_accumulator_valueepsilon)selfr   r   r   r   r   r   r   r   r   r   r   r   r   kwargs	__class__s                  Y/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/optimizers/adagrad.pyr   zAdagrad.__init__#   sk    " 	 	
'%+%$;/(C	
 	
 	
 	
 	
 *C&    c           	         | j         rd S t                                          |           g | _        t	          j        | j                  }|D ]=}| j                            |                     |j	        ||j
        d                     >d S )Naccumulator)shapeinitializerdtyper   )builtr   build_accumulatorsr   Constantr   appendadd_variabler&   r(   )r   var_listr'   varr!   s       r"   r*   zAdagrad.buildE   s    : 	Fh"+D,JKK 	 	C%%!!) +)&	 "     	 	r#   c                    t          j        ||j                  }t          j        ||j                  }| j        |                     |                   }|                     |t          j        |                     |                     |t          j        t          j	        ||          t          j
        t          j        || j                                                 dS )z=Update step given gradient and the associated model variable.N)r   castr(   r+   _get_variable_index
assign_addsquare
assign_subdividemultiplysqrtaddr   )r   gradientvariabler   lrr%   s         r"   update_stepzAdagrad.update_stepU   s    XmX^448Hhn55()A)A()K)KLSZ%9%9:::JR**dl;;<< 	
 	
 	
 	
 	
r#   c                     t                                                      }|                    | j        | j        d           |S )N)r   r   )r   
get_configupdater   r   )r   configr!   s     r"   r@   zAdagrad.get_confige   sJ    ##%%-1-K< 	
 	
 	
 r#   )r	   r
   r   NNNNFr   NNNr   )	__name__
__module____qualname____doc__r   r*   r>   r@   __classcell__)r!   s   @r"   r   r      s         8 "% $$(           D     
 
 
 	 	 	 	 	 	 	 	 	r#   r   z{{base_optimizer_keyword_args}}N)	keras.srcr   r   keras.src.api_exportr   keras.src.optimizersr   	Optimizerr   rF   replacebase_optimizer_keyword_argsr   r#   r"   <module>rN      s    " " " " " "       - - - - - - * * * * * * )*++f f f f fi! f f ,+fR /))%y'L r#   