
    &Vfs                         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.RMSpropc                   \     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd
	Z fdZd Z fdZ xZS )RMSpropak  Optimizer that implements the RMSprop algorithm.

    The gist of RMSprop is to:

    - Maintain a moving (discounted) average of the square of gradients
    - Divide the gradient by the root of this average

    This implementation of RMSprop uses plain momentum, not Nesterov momentum.

    The centered version additionally maintains a moving average of the
    gradients, and uses that average to estimate the variance.

    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`.
        rho: float, defaults to 0.9. Discounting factor for the old gradients.
        momentum: float, defaults to 0.0. If not 0.0., the optimizer tracks the
            momentum value, with a decay rate equals to `1 - momentum`.
        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.
        centered: Boolean. If `True`, gradients are normalized by the estimated
            variance of the gradient; if False, by the uncentered second moment.
            Setting this to `True` may help with training, but is slightly more
            expensive in terms of computation and memory. Defaults to `False`.
        {{base_optimizer_keyword_args}}

    Example:

    >>> opt = keras.optimizers.RMSprop(learning_rate=0.1)
    >>> var1 = keras.backend.Variable(10.0)
    >>> loss = lambda: (var1 ** 2) / 2.0  # d(loss) / d(var1) = var1
    >>> opt.minimize(loss, [var1])
    >>> var1
    9.683772

    Reference:

    - [Hinton, 2012](
        http://www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf)
    MbP??        Hz>FNGz?rmspropc                      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__rhomomentumepsiloncentered)selfr   r   r   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/rmsprop.pyr   zRMSprop.__init__5   sw    & 	 	
'%+%$;/(C	
 	
 	
 	
 	
       c                    | j         rd S t                                          |           g | _        |D ]0}| j                            |                     |d                     1g | _        | j        dk    r3|D ]0}| j                            |                     |d                     1g | _        | j	        r3|D ]2}| j                            |                     |d                     1d S d S )Nvelocityr   r   average_gradient)
builtr   build_velocitiesappendadd_variable_from_reference
_momentumsr   _average_gradientsr    )r!   var_listvarr#   s      r$   r*   zRMSprop.build[   s4   : 	Fh 	 	C##00jAA    =1  &&44S*EE    #%= 	  '..44S:LMM   	 	 r%   c                    t          j        ||j                  }t          j        ||j                  }| j        |                     |                   }d}| j        dk    r | j        |                     |                   }d}| j        r | j        |                     |                   }| j	        }| 
                    |t          j        t          j        ||          t          j        d|z
  t          j        |                                         | j        rr| 
                    |t          j        t          j        ||          t          j        d|z
  |                               |t          j        |          z
  | j        z   }	nt          j        || j                  }	t          j        t          j        ||          t          j        |	                    }
| j        dk    rY| 
                    |t          j        t          j        | j        |          |
                     |                     ||           dS |                     ||
           dS )z=Update step given gradient and the associated model variable.Nr      )r   castdtyper+   _get_variable_indexr   r.   r    r/   r   assignaddmultiplysquarer   dividesqrt
assign_sub)r!   gradientvariabler   lrr'   r   average_gradr   denominator	increments              r$   update_stepzRMSprop.update_stepu   s(   XmX^448Hhn55#D$<$<X$F$FG=1t'?'?'I'IJH= 	2((22L hGS(++QWcj&:&:;; 	
 	
 	
 = 
	:KKLl33LS(33    #SZ%=%==LKK'(DL99KJLX&&(=(=
 
	 =1KKT]H==yII   OOHh/////OOHi00000r%   c                     t                                                      }|                    | j        | j        | j        | j        d           |S )N)r   r   r   r    )r   
get_configupdater   r   r   r    )r!   configr#   s     r$   rF   zRMSprop.get_config   sS    ##%%x M< M	 	
 	
 	
 r%   )r   r	   r
   r   FNNNNFr   NNNr   )	__name__
__module____qualname____doc__r   r*   rD   rF   __classcell__)r#   s   @r$   r   r      s        + +^  $$(!$! $! $! $! $! $!L    4-1 -1 -1^        r%   r   z{{base_optimizer_keyword_args}}N)	keras.srcr   keras.src.api_exportr   keras.src.optimizersr   	Optimizerr   rL   replacebase_optimizer_keyword_argsr   r%   r$   <module>rT      s          - - - - - - * * * * * * )*++h h h h hi! h h ,+hV /))%y'L r%   