§
    é&Vf‹#  ã                   óÊ   — 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.Ftrlc                   ó`   ‡ — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd
„	Zˆ fd„Zd„ Zˆ fd„Zˆ xZS )ÚFtrlaÁ
  Optimizer that implements the FTRL algorithm.

    "Follow The Regularized Leader" (FTRL) is an optimization algorithm
    developed at Google for click-through rate prediction in the early 2010s. It
    is most suitable for shallow models with large and sparse feature spaces.
    The algorithm is described by
    [McMahan et al., 2013](https://research.google.com/pubs/archive/41159.pdf).
    The Keras version has support for both online L2 regularization
    (the L2 regularization described in the paper
    above) and shrinkage-type L2 regularization
    (which is the addition of an L2 penalty to the loss function).

    Initialization:

    ```python
    n = 0
    sigma = 0
    z = 0
    ```

    Update rule for one variable `w`:

    ```python
    prev_n = n
    n = n + g ** 2
    sigma = (n ** -lr_power - prev_n ** -lr_power) / lr
    z = z + g - sigma * w
    if abs(z) < lambda_1:
      w = 0
    else:
      w = (sgn(z) * lambda_1 - z) / ((beta + sqrt(n)) / alpha + lambda_2)
    ```

    Notation:

    - `lr` is the learning rate
    - `g` is the gradient for the variable
    - `lambda_1` is the L1 regularization strength
    - `lambda_2` is the L2 regularization strength
    - `lr_power` is the power to scale n.

    Check the documentation for the `l2_shrinkage_regularization_strength`
    parameter for more details when shrinkage is enabled, in which case gradient
    is replaced with a gradient with shrinkage.

    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`.
        learning_rate_power: A float value, must be less or equal to zero.
            Controls how the learning rate decreases during training. Use zero
            for a fixed learning rate.
        initial_accumulator_value: The starting value for accumulators. Only
            zero or positive values are allowed.
        l1_regularization_strength: A float value, must be greater than or equal
            to zero. Defaults to `0.0`.
        l2_regularization_strength: A float value, must be greater than or equal
            to zero. Defaults to `0.0`.
        l2_shrinkage_regularization_strength: A float value, must be greater
            than or equal to zero. This differs from L2 above in that the L2
            above is a stabilization penalty, whereas this L2 shrinkage is a
            magnitude penalty. When input is sparse shrinkage will only happen
            on the active weights.
        beta: A float value, representing the beta value from the paper.
            Defaults to `0.0`.
        {{base_optimizer_keyword_args}}
    çü©ñÒMbP?ç      à¿çš™™™™™¹?ç        NFç®Gáz®ï?Úftrlc                 ó   •—  t          ¦   «         j        d	||||	|
||||||dœ|¤Ž |dk     rt          d|› d¦  «        ‚|dk    rt          d|› d¦  «        ‚|dk     rt          d|› d¦  «        ‚|dk     rt          d|› d¦  «        ‚|dk     rt          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_stepsr   z^`initial_accumulator_value` needs to be positive or zero. Received: initial_accumulator_value=ú.zR`learning_rate_power` needs to be negative or zero. Received: learning_rate_power=z``l1_regularization_strength` needs to be positive or zero. Received: l1_regularization_strength=z``l2_regularization_strength` needs to be positive or zero. Received: l2_regularization_strength=zt`l2_shrinkage_regularization_strength` needs to be positive or zero. Received: l2_shrinkage_regularization_strength=© )	ÚsuperÚ__init__Ú
ValueErrorÚlearning_rate_powerÚinitial_accumulator_valueÚl1_regularization_strengthÚl2_regularization_strengthÚ$l2_shrinkage_regularization_strengthÚbeta)Úselfr   r    r!   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/ftrl.pyr   zFtrl.__init__N   s  ø€ ð* 	‰ŒÔð 	
Ø'ØØ%ØØØ+ØØ%Ø$;Ø/Ø(Cð	
ð 	
ð ð	
ð 	
ð 	
ð % sÒ*Ð*Ýð0à,ð0ð 0ð 0ñô ð ð
  Ò$Ð$Ýð>Ø':ð>ð >ð >ñô ð ð &¨Ò+Ð+Ýð1à-ð1ð 1ð 1ñô ð ð
 &¨Ò+Ð+Ýð1à-ð1ð 1ð 1ñô ð ð
 0°#Ò5Ð5Ýð<à8ð<ð <ð <ñô ð ð $7ˆÔ Ø)BˆÔ&Ø*DˆÔ'Ø*DˆÔ'à0ð 	Ô1ð ˆŒ	ˆ	ˆ	ó    c                 ó„  •— | j         rdS t          ¦   «                              |¦  «         g | _        g | _        |D ]ƒ}| j                             |                      |j        |j        dt          j
        | j        ¦  «        ¬¦  «        ¦  «         | j                             |                      |d¬¦  «        ¦  «         Œ„dS )zInitialize optimizer variables.

        Args:
            var_list: list of model variables to build Ftrl variables on.
        NÚaccumulator)ÚshapeÚdtyper   ÚinitializerÚlinear)Úreference_variabler   )Úbuiltr   ÚbuildÚ_accumulatorsÚ_linearsÚappendÚadd_variabler-   r.   r   ÚConstantr!   Úadd_variable_from_reference)r&   Úvar_listÚvarr(   s      €r)   r3   z
Ftrl.build™   sæ   ø€ ð Œ:ð 	ØˆFÝ‰ŒŠhÑÔÐØˆÔØˆŒØð 	ð 	ˆCØÔ×%Ò%Ø×!Ò!Øœ)Øœ)Ø&Ý ,Ô 5ØÔ6ñ!ô !ð	 "ñ ô ñ	ô 	ð 	ð ŒM× Ò Ø×0Ò0Ø'*°ð 1ñ ô ñô ð ð ð	ð 	r*   c                 óP  — t          j        ||j        ¦  «        }t          j        ||j        ¦  «        }| j        |                      |¦  «                 }| j        |                      |¦  «                 }| j        }| j        }|| j        d|z  z  z   }t          j	        |t          j
        d| j        z  |¦  «        ¦  «        }	t          j	        |t          j        |¦  «        ¦  «        }
|                      |t          j        |	t          j
        t          j        t          j        t          j        |
| ¦  «        t          j        || ¦  «        ¦  «        |¦  «        |¦  «        ¦  «        ¦  «         t          j	        t          j        t          j        |
| ¦  «        |¦  «        d|z  ¦  «        }t          j        || j         | j        ¦  «        }|                      |t          j        t          j        ||¦  «        |¦  «        ¦  «         |                      ||
¦  «         dS )z=Update step given gradient and the associated model variable.g       @é   N)r   Úcastr.   r4   Ú_get_variable_indexr5   r    r#   r%   ÚaddÚmultiplyr$   ÚsquareÚ
assign_addÚsubtractÚdivideÚpowerÚclipr"   Úassign)r&   ÚgradientÚvariabler   ÚlrÚaccumr0   Úlr_powerÚl2_regÚgrad_to_useÚ	new_accumÚ	quadraticÚlinear_clippeds                r)   Úupdate_stepzFtrl.update_stepµ   s  € õ ŒXm X¤^Ñ4Ô4ˆÝ”8˜H h¤nÑ5Ô5ˆàÔ" 4×#;Ò#;¸HÑ#EÔ#EÔFˆØ”˜t×7Ò7¸ÑAÔAÔBˆàÔ+ˆØÔ0ˆØ˜$œ) s¨R¡xÑ0Ñ0ˆå”gØÝŒLØDÔ=Ñ=¸xñô ñ
ô 
ˆõ ”G˜E¥3¤:¨hÑ#7Ô#7Ñ8Ô8ˆ	ØŠØÝŒLØÝ”Ý”JÝœÝœI i°(°Ñ;Ô;ÝœI e¨h¨YÑ7Ô7ñô ð ñô ð ñ	ô 	ñô ñ	
ô 	
ð 	
õ  ”GÝŒJ•s”y ¨h¨YÑ8Ô8¸"Ñ=Ô=¸qÀ6¹zñ
ô 
ˆ	õ œØØÔ,Ð,ØÔ+ñ
ô 
ˆð
 	ŠØÝŒJ•s”| N°FÑ;Ô;¸YÑGÔGñ	
ô 	
ð 	
ð 	ŠE˜9Ñ%Ô%Ð%Ð%Ð%r*   c           	      ó¼   •— t          ¦   «                              ¦   «         }|                     | j        | j        | j        | j        | j        | j        dœ¦  «         |S )N)r    r!   r"   r#   r$   r%   )	r   Ú
get_configÚupdater    r!   r"   r#   r$   r%   )r&   Úconfigr(   s     €r)   rU   zFtrl.get_configç   sb   ø€ Ý‘”×#Ò#Ñ%Ô%ˆàŠà'+Ô'?Ø-1Ô-KØ.2Ô.MØ.2Ô.MØ8<Ô8aØœ	ðð ñ		
ô 		
ð 		
ð ˆr*   )r	   r
   r   r   r   r   r   NNNNFr   NNNr   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r3   rS   rU   Ú__classcell__)r(   s   @r)   r   r      sÈ   ø€ € € € € ðCð CðN Ø Ø"%Ø#&Ø#&Ø-0ØØØØØØØØ $ØØ$(Øð%Ið Ið Ið Ið Ið IðVð ð ð ð ð80&ð 0&ð 0&ðdð ð ð ð ð ð ð ð r*   r   z{{base_optimizer_keyword_args}}N)Ú	keras.srcr   r   Úkeras.src.api_exportr   Úkeras.src.optimizersr   Ú	Optimizerr   r[   ÚreplaceÚbase_optimizer_keyword_argsr   r*   r)   ú<module>rc      sÅ   ðØ "Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -Ø *Ð *Ð *Ð *Ð *Ð *ð €Ð&Ð'Ñ(Ô(ðlð lð lð lð lˆ9Ôñ lô lñ )Ô(ðlð^ Œ|×#Ò#Ø% yÔ'Lñô €„€€r*   