
    &Vf                         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 )	    )ops)keras_export)	optimizerzkeras.optimizers.Adamc                   \     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd
	Z fdZd Z fdZ xZS )Adama  Optimizer that implements the Adam algorithm.

    Adam optimization is a stochastic gradient descent method that is based on
    adaptive estimation of first-order and second-order moments.

    According to
    [Kingma et al., 2014](http://arxiv.org/abs/1412.6980),
    the method is "*computationally
    efficient, has little memory requirement, invariant to diagonal rescaling of
    gradients, and is well suited for problems that are large in terms of
    data/parameters*".

    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`.
        beta_1: A float value or a constant float tensor, or a callable
            that takes no arguments and returns the actual value to use. The
            exponential decay rate for the 1st moment estimates. Defaults to
            `0.9`.
        beta_2: A float value or a constant float tensor, or a callable
            that takes no arguments and returns the actual value to use. The
            exponential decay rate for the 2nd moment estimates. Defaults to
            `0.999`.
        epsilon: A small constant for numerical stability. This epsilon is
            "epsilon hat" in the Kingma and Ba paper (in the formula just before
            Section 2.1), not the epsilon in Algorithm 1 of the paper. Defaults
            to `1e-7`.
        amsgrad: Boolean. Whether to apply AMSGrad variant of this algorithm
            from the paper "On the Convergence of Adam and beyond". Defaults
            to `False`.
        {{base_optimizer_keyword_args}}
    MbP??+?Hz>FNGz?adamc                      t                      j        d||||||	|
||||d| || _        || _        || _        || _        d S )N)learning_ratenameweight_decayclipnorm	clipvalueglobal_clipnormuse_emaema_momentumema_overwrite_frequencyloss_scale_factorgradient_accumulation_steps )super__init__beta_1beta_2epsilonamsgrad)selfr   r   r   r   r    r   r   r   r   r   r   r   r   r   r   kwargs	__class__s                    V/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/optimizers/adam.pyr   zAdam.__init__+   sw    & 	 	
'%+%$;/(C	
 	
 	
 	
 	
     c                    | j         rdS t                                          |           g | _        g | _        |D ]`}| j                            |                     |d                     | j                            |                     |d                     a| j        r;g | _        |D ]3}| j                            |                     |d                     2dS dS )a  Initialize optimizer variables.

        Adam optimizer has 3 types of variables: momentums, velocities and
        velocity_hat (only set when amsgrad is applied),

        Args:
            var_list: list of model variables to build Adam variables on.
        Nmomentum)reference_variabler   velocityvelocity_hat)	builtr   build
_momentums_velocitiesappendadd_variable_from_referencer    _velocity_hats)r!   var_listvarr#   s      r$   r,   z
Adam.buildQ   s2    : 	Fh 
	 
	CO""00'* 1    
 ##00'* 1     
 < 	"$D  #**44+.^ 5     	 	 r%   c                    t          j        ||j                  }t          j        ||j                  }t          j        | j        dz   |j                  }t          j        t          j        | j        |j                  |          }t          j        t          j        | j        |j                  |          }| j        |                     |                   }| j	        |                     |                   }	|t          j
        d|z
            z  d|z
  z  }
|                     |t          j        t          j        ||          d| j        z
                       |                     |	t          j        t          j        t          j        |          |	          d| j        z
                       | j        rK| 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   castdtype
iterationspowerr   r   r-   _get_variable_indexr.   sqrt
assign_addmultiplysubtractsquarer    r1   assignmaximum
assign_subdivideaddr   )r!   gradientvariabler   lr
local_stepbeta_1_powerbeta_2_powermvalphav_hats               r$   update_stepzAdam.update_steps   s   XmX^448Hhn55Xdo18>BB
yHT[(.11:
 
 yHT[(.11:
 
 OD44X>>?T55h??@SXa,.///1|3CDs|CL155q4;GG	
 	
 	
 	LSZ11155q4; 	
 	
 	
 < 	'(@(@(J(JKEKKs{5!44555AJQ&&T\(J(J 	
 	
 	
 	
 	
r%   c                     t                                                      }|                    | j        | j        | j        | j        d           |S )N)r   r   r   r    )r   
get_configupdater   r   r   r    )r!   configr#   s     r$   rQ   zAdam.get_config   sS    ##%%++<<	 	
 	
 	
 r%   )r   r	   r
   r   FNNNNFr   NNNr   )	__name__
__module____qualname____doc__r   r,   rO   rQ   __classcell__)r#   s   @r$   r   r      s        ! !J  $$(!$ $ $ $ $ $L         D#
 #
 #
J
 
 
 
 
 
 
 
 
r%   r   z{{base_optimizer_keyword_args}}N)	keras.srcr   keras.src.api_exportr   keras.src.optimizersr   	Optimizerr   rW   replacebase_optimizer_keyword_argsr   r%   r$   <module>r_      s          - - - - - - * * * * * * &'(([ [ [ [ [9 [ [ )([| |##%y'L r%   