← Back
Editing: _spectral.cpython-311.pyc
� d�c� � � � d Z ddlZddlZddlmZ ddlmZ ddlm Z m Z G d� de� � Z dd�Z dd�Zdd�Zd� Zd� ZdS )z, Spectral Algorithm for Nonlinear Equations � N)�OptimizeResult)�_check_unknown_options� )�_nonmonotone_line_search_cruz�_nonmonotone_line_search_chengc � � e Zd ZdS )�_NoConvergenceN)�__name__� __module__�__qualname__� � �:/usr/lib/python3/dist-packages/scipy/optimize/_spectral.pyr r s � � � � � ��Dr r r �:�0�yE>�Y��n��� F� 绽���|�=� �?�cruzc �4 �*�+�,� t |� � | dvrt d| �d�� � �d�,| ��*fd�} |��+�,fd�}�,fd�}d g}t | |||||� � \ }}}�+}}d }�+�*|} ||� � }t j �+g| � � }d }�*}d}d} ||� � }|rt d|||fz � � |� |||� � |||z |z k rd}d }�nt |� � d|z k rd|z t j |� � z }nt |� � |k r|}| |z } | |||� � } | dk rt ||||| �� � \ }!}"}#}$n#| dk rt |||�+||| �� � \ }!}"}#}$}}n# t $ r Y naw xY w|"|z }%|$|z }&t j |%|%� � t j |%|&� � z }|"}|$}|#�+| dk r|� |#� � |dz }��Mt |||�� � }'t ||� � }(t |'|||(|d |�� � })|)S )a� Solve nonlinear equation with the DF-SANE method Options ------- ftol : float, optional Relative norm tolerance. fatol : float, optional Absolute norm tolerance. Algorithm terminates when ``||func(x)|| < fatol + ftol ||func(x_0)||``. fnorm : callable, optional Norm to use in the convergence check. If None, 2-norm is used. maxfev : int, optional Maximum number of function evaluations. disp : bool, optional Whether to print convergence process to stdout. eta_strategy : callable, optional Choice of the ``eta_k`` parameter, which gives slack for growth of ``||F||**2``. Called as ``eta_k = eta_strategy(k, x, F)`` with `k` the iteration number, `x` the current iterate and `F` the current residual. Should satisfy ``eta_k > 0`` and ``sum(eta, k=0..inf) < inf``. Default: ``||F||**2 / (1 + k)**2``. sigma_eps : float, optional The spectral coefficient is constrained to ``sigma_eps < sigma < 1/sigma_eps``. Default: 1e-10 sigma_0 : float, optional Initial spectral coefficient. Default: 1.0 M : int, optional Number of iterates to include in the nonmonotonic line search. Default: 10 line_search : {'cruz', 'cheng'} Type of line search to employ. 'cruz' is the original one defined in [Martinez & Raydan. Math. Comp. 75, 1429 (2006)], 'cheng' is a modified search defined in [Cheng & Li. IMA J. Numer. Anal. 29, 814 (2009)]. Default: 'cruz' References ---------- .. [1] "Spectral residual method without gradient information for solving large-scale nonlinear systems of equations." W. La Cruz, J.M. Martinez, M. Raydan. Math. Comp. **75**, 1429 (2006). .. [2] W. La Cruz, Opt. Meth. Software, 29, 24 (2014). .. [3] W. Cheng, D.-H. Li. IMA J. Numer. Anal. **29**, 814 (2009). )�chengr zInvalid value z for 'line_search'� Nc � �� �d| z dz z S )Nr r r )�k�x�F�f_0s �r �eta_strategyz#_root_df_sane.<locals>.eta_strategyJ s �� ��!�a�%�!��#�#r c � �� �d�z z S )Nr r )r �f_k�nexps ��r �fnormz_root_df_sane.<locals>.fnormO s �� ���T��?�"r c �H �� t j � | � � �z S �N)�np�linalg�norm)r r"