← Back
Editing: _nnls.cpython-311.pyc
� d�c� � �4 � d dl mZ ddlmZmZmZ dgZdd�ZdS )� )�__nnls� )�asarray_chkfinite�zeros�double�nnlsNc � � t t | |f� � \ } }t | j � � dk rt dd| j ��z � � �t |j � � dk rt dd|j ��z � � �| j \ }}||j d k r$t dd |�d |j d f��z � � �|�dnt |� � }t |ft � � � }t |ft � � � }t |ft � � � }t j | |||||||� � \ }} } | dk rt d� � �|| fS )a� Solve ``argmin_x || Ax - b ||_2`` for ``x>=0``. This is a wrapper for a FORTRAN non-negative least squares solver. Parameters ---------- A : ndarray Matrix ``A`` as shown above. b : ndarray Right-hand side vector. maxiter: int, optional Maximum number of iterations, optional. Default is ``3 * A.shape[1]``. Returns ------- x : ndarray Solution vector. rnorm : float The residual, ``|| Ax-b ||_2``. See Also -------- lsq_linear : Linear least squares with bounds on the variables Notes ----- The FORTRAN code was published in the book below. The algorithm is an active set method. It solves the KKT (Karush-Kuhn-Tucker) conditions for the non-negative least squares problem. References ---------- Lawson C., Hanson R.J., (1987) Solving Least Squares Problems, SIAM Examples -------- >>> import numpy as np >>> from scipy.optimize import nnls ... >>> A = np.array([[1, 0], [1, 0], [0, 1]]) >>> b = np.array([2, 1, 1]) >>> nnls(A, b) (array([1.5, 1. ]), 0.7071067811865475) >>> b = np.array([-1, -1, -1]) >>> nnls(A, b) (array([0., 0.]), 1.7320508075688772) � z)Expected a two-dimensional array (matrix)z, but the shape of A is r z)Expected a one-dimensional array (vector)z, but the shape of b is r z0Incompatible dimensions. The first dimension of zA is z, while the shape of b is N���)�dtypeztoo many iterations)�mapr �len�shape� ValueError�intr r r r �RuntimeError)�A�b�maxiter�m�n�w�zz�index�x�rnorm�modes �6/usr/lib/python3/dist-packages/scipy/optimize/_nnls.pyr r s� � �h � �1�a�&�)�)�D�A�q� �1�7�|�|�q����D�D�9:���C�D� E� E� E� �1�7�|�|�q����D�D�9:���C�D� E� E� E� �7�D�A�q��A�G�A�J����B�B�9:���Q�W�Q�Z�N�N�K�L�M� M� M� �O�b�b��W���G� �q�d�&�!�!�!�A� ��t�6� "� "� "�B��1�$�c�"�"�"�E��[��A�q�!�Q��E�7�C�C�N�A�u�d��q�y�y��0�1�1�1��e�8�O� )N)� r �numpyr r r �__all__r � r r �<module>r$ s` �� � � � � � � 2� 2� 2� 2� 2� 2� 2� 2� 2� 2��(��N� N� N� N� N� Nr
Save File
Cancel