Ë
    ÷Q(h†"  ã                   óP   — d Z ddlZ G d„ d«      Z G d„ de«      Z G d„ de«      Zy)	z'Stochastic optimization methods for MLPé    Nc                   ó*   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zy)ÚBaseOptimizera9  Base (Stochastic) gradient descent optimizer

    Parameters
    ----------
    learning_rate_init : float, default=0.1
        The initial learning rate used. It controls the step-size in updating
        the weights

    Attributes
    ----------
    learning_rate : float
        the current learning rate
    c                 ó2   — || _         t        |«      | _        y ©N)Úlearning_rate_initÚfloatÚlearning_rate)Úselfr   s     úk/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/neural_network/_stochastic_optimizers.pyÚ__init__zBaseOptimizer.__init__   s   € Ø"4ˆÔÜ"Ð#5Ó6ˆÕó    c                 óf   — | j                  |«      }t        d„ |D «       |«      D ]
  \  }}||z  }Œ y)aâ  Update parameters with given gradients

        Parameters
        ----------
        params : list of length = len(coefs_) + len(intercepts_)
            The concatenated list containing coefs_ and intercepts_ in MLP
            model. Used for initializing velocities and updating params

        grads : list of length = len(params)
            Containing gradients with respect to coefs_ and intercepts_ in MLP
            model. So length should be aligned with params
        c              3   ó    K  — | ]  }|–— Œ y ­wr   © )Ú.0Úps     r   ú	<genexpr>z.BaseOptimizer.update_params.<locals>.<genexpr>*   s   è ø€ Ò!4¨¤!Ñ!4ùs   ‚N)Ú_get_updatesÚzip)r
   ÚparamsÚgradsÚupdatesÚparamÚupdates         r   Úupdate_paramszBaseOptimizer.update_params   s=   € ð ×#Ñ# EÓ*ˆÜ Ñ!4¨VÔ!4°gÓ>ò 	‰MˆE�6Ø�V‰O‰Eñ	r   c                  ó   — y)zhPerform update to learning rate and potentially other states at the
        end of an iteration
        Nr   ©r
   Ú	time_steps     r   Úiteration_endszBaseOptimizer.iteration_ends-   s   € ð 	r   c                 ó$   — |rt        |dz   «       y)aH  Decides whether it is time to stop training

        Parameters
        ----------
        msg : str
            Message passed in for verbose output

        verbose : bool
            Print message to stdin if True

        Returns
        -------
        is_stopping : bool
            True if training needs to stop
        ú
 Stopping.T)Úprint©r
   ÚmsgÚverboses      r   Útrigger_stoppingzBaseOptimizer.trigger_stopping3   s   € ñ  Ü�#˜Ñ$Ô%Ør   N)çš™™™™™¹?)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   r   r   r   r   r   	   s   „ ñó7òò"ór   r   c                   ó@   ‡ — e Zd ZdZ	 	 	 	 	 dˆ fd„	Zd„ Zd„ Zd„ Zˆ xZS )ÚSGDOptimizeraË  Stochastic gradient descent optimizer with momentum

    Parameters
    ----------
    params : list, length = len(coefs_) + len(intercepts_)
        The concatenated list containing coefs_ and intercepts_ in MLP model.
        Used for initializing velocities and updating params

    learning_rate_init : float, default=0.1
        The initial learning rate used. It controls the step-size in updating
        the weights

    lr_schedule : {'constant', 'adaptive', 'invscaling'}, default='constant'
        Learning rate schedule for weight updates.

        -'constant', is a constant learning rate given by
         'learning_rate_init'.

        -'invscaling' gradually decreases the learning rate 'learning_rate_' at
          each time step 't' using an inverse scaling exponent of 'power_t'.
          learning_rate_ = learning_rate_init / pow(t, power_t)

        -'adaptive', keeps the learning rate constant to
         'learning_rate_init' as long as the training keeps decreasing.
         Each time 2 consecutive epochs fail to decrease the training loss by
         tol, or fail to increase validation score by tol if 'early_stopping'
         is on, the current learning rate is divided by 5.

    momentum : float, default=0.9
        Value of momentum used, must be larger than or equal to 0

    nesterov : bool, default=True
        Whether to use nesterov's momentum or not. Use nesterov's if True

    power_t : float, default=0.5
        Power of time step 't' in inverse scaling. See `lr_schedule` for
        more details.

    Attributes
    ----------
    learning_rate : float
        the current learning rate

    velocities : list, length = len(params)
        velocities that are used to update params
    c                 ó¶   •— t         ‰| �  |«       || _        || _        || _        || _        |D �cg c]  }t        j                  |«      ‘Œ c}| _        y c c}w r   )	Úsuperr   Úlr_scheduleÚmomentumÚnesterovÚpower_tÚnpÚ
zeros_likeÚ
velocities)	r
   r   r   r0   r1   r2   r3   r   Ú	__class__s	           €r   r   zSGDOptimizer.__init__x   sN   ø€ ô 	‰ÑÐ+Ô,à&ˆÔØ ˆŒØ ˆŒØˆŒØ=CÖD°Eœ2Ÿ=™=¨Õ/ÒDˆ�ùÒDs   ±Ac                 ó~   — | j                   dk(  r.t        | j                  «      |dz   | j                  z  z  | _        yy)a  Perform updates to learning rate and potential other states at the
        end of an iteration

        Parameters
        ----------
        time_step : int
            number of training samples trained on so far, used to update
            learning rate for 'invscaling'
        Ú
invscalingé   N)r0   r   r   r3   r	   r   s     r   r   zSGDOptimizer.iteration_ends‰   s?   € ð ×Ñ˜|Ò+ä�d×-Ñ-Ó.°)¸a±-ÀDÇLÁLÑ1PÑPð Õð ,r   c                 óè   — | j                   dk7  r|rt        |dz   «       y| j                  dk  r|rt        |dz   «       y| xj                  dz  c_        |rt        |d| j                  z  z   «       y)	NÚadaptiver!   Tg�íµ ÷Æ°>z# Learning rate too small. Stopping.g      @z Setting learning rate to %fF)r0   r"   r	   r#   s      r   r&   zSGDOptimizer.trigger_stopping˜   su   € Ø×Ñ˜zÒ)ÙÜ�c˜LÑ(Ô)Øà×Ñ Ò%ÙÜ�cÐAÑAÔBØà×Ò˜cÑ!ÕÙÜ�#Ð6¸×9KÑ9KÑKÑKÔLØr   c                 óX  — t        | j                  |«      D ��cg c]$  \  }}| j                  |z  | j                  |z  z
  ‘Œ& }}}|| _        | j                  rEt        | j                  |«      D ��cg c]$  \  }}| j                  |z  | j                  |z  z
  ‘Œ& }}}|S c c}}w c c}}w )á¦  Get the values used to update params with given gradients

        Parameters
        ----------
        grads : list, length = len(coefs_) + len(intercepts_)
            Containing gradients with respect to coefs_ and intercepts_ in MLP
            model. So length should be aligned with params

        Returns
        -------
        updates : list, length = len(grads)
            The values to add to params
        )r   r6   r1   r	   r2   )r
   r   ÚvelocityÚgradr   s        r   r   zSGDOptimizer._get_updates¨   s±   € ô  #& d§o¡o°uÓ"=÷
á�˜$ð �M‰M˜HÑ$ t×'9Ñ'9¸DÑ'@Ó@ð
ˆñ 
ð "ˆŒà�=Š=ô '*¨$¯/©/¸5Ó&A÷á"�H˜dð —‘ Ñ(¨4×+=Ñ+=ÀÑ+DÓDðˆGñ ð
 ˆùó
ùós   š)B Á2)B&)r'   ÚconstantçÍÌÌÌÌÌì?Tg      à?)	r(   r)   r*   r+   r   r   r&   r   Ú__classcell__©r7   s   @r   r-   r-   H   s/   ø„ ñ-ðd ØØØØõEò"òö r   r-   c                   ó,   ‡ — e Zd ZdZ	 dˆ fd„	Zd„ Zˆ xZS )ÚAdamOptimizeraÊ  Stochastic gradient descent optimizer with Adam

    Note: All default values are from the original Adam paper

    Parameters
    ----------
    params : list, length = len(coefs_) + len(intercepts_)
        The concatenated list containing coefs_ and intercepts_ in MLP model.
        Used for initializing velocities and updating params

    learning_rate_init : float, default=0.001
        The initial learning rate used. It controls the step-size in updating
        the weights

    beta_1 : float, default=0.9
        Exponential decay rate for estimates of first moment vector, should be
        in [0, 1)

    beta_2 : float, default=0.999
        Exponential decay rate for estimates of second moment vector, should be
        in [0, 1)

    epsilon : float, default=1e-8
        Value for numerical stability

    Attributes
    ----------
    learning_rate : float
        The current learning rate

    t : int
        Timestep

    ms : list, length = len(params)
        First moment vectors

    vs : list, length = len(params)
        Second moment vectors

    References
    ----------
    :arxiv:`Kingma, Diederik, and Jimmy Ba (2014) "Adam: A method for
        stochastic optimization." <1412.6980>
    c                 ó  •— t         ‰| �  |«       || _        || _        || _        d| _        |D �cg c]  }t        j                  |«      ‘Œ c}| _        |D �cg c]  }t        j                  |«      ‘Œ c}| _	        y c c}w c c}w )Nr   )
r/   r   Úbeta_1Úbeta_2ÚepsilonÚtr4   r5   ÚmsÚvs)r
   r   r   rH   rI   rJ   r   r7   s          €r   r   zAdamOptimizer.__init__ó   sm   ø€ ô 	‰ÑÐ+Ô,àˆŒØˆŒØˆŒØˆŒØ5;Ö<¨E”2—=‘= Õ'Ò<ˆŒØ5;Ö<¨E”2—=‘= Õ'Ò<ˆ�ùò =ùÚ<s   ±A>ÁBc                 ó  — | xj                   dz  c_         t        | j                  |«      D ��cg c]'  \  }}| j                  |z  d| j                  z
  |z  z   ‘Œ) c}}| _        t        | j                  |«      D ��cg c]*  \  }}| j
                  |z  d| j
                  z
  |dz  z  z   ‘Œ, c}}| _        | j                  t        j                  d| j
                  | j                   z  z
  «      z  d| j                  | j                   z  z
  z  | _	        t        | j                  | j                  «      D ��cg c]8  \  }}| j                   |z  t        j                  |«      | j                  z   z  ‘Œ: }}}|S c c}}w c c}}w c c}}w )r>   r:   é   )rK   r   rL   rH   rM   rI   r   r4   Úsqrtr	   rJ   )r
   r   Úmr@   Úvr   s         r   r   zAdamOptimizer._get_updatesÿ   s[  € ð 	�Š�!‰�ô ˜tŸw™w¨Ó.÷
á��4ð �K‰K˜!‰O˜q 4§;¡;™°$Ñ6Ó6ó
ˆŒô ˜tŸw™w¨Ó.÷
á��4ð �K‰K˜!‰O˜q 4§;¡;™°4¸±7Ñ;Ó;ó
ˆŒð
 ×#Ñ#Ü�g‰g�a˜$Ÿ+™+ t§v¡vÑ-Ñ-Ó.ñ/à�4—;‘; §¡Ñ&Ñ&ñ(ð 	Ôô ˜DŸG™G T§W¡WÓ-÷
á��1ð ×ÑÐ !Ñ#¤r§w¡w¨q£z°D·L±LÑ'@ÓAð
ˆñ 
ð ˆùó#
ùó
ùó
s   ¯,E8Á=/E>Ä6=F)gü©ñÒMbP?rB   g+‡ÙÎ÷ï?g:Œ0âŽyE>)r(   r)   r*   r+   r   r   rC   rD   s   @r   rF   rF   Å   s   ø„ ñ+ð\ SWõ
=ö r   rF   )r+   Únumpyr4   r   r-   rF   r   r   r   ú<module>rT      s5   ðÙ -ó
 ÷<ñ <ô~z�=ô zôzZ�Mõ Zr   