
    e!hOw                     :   d Z ddlmZmZ ddlZddlmZmZm	Z	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z' d(dZ(d)dZ)	 d*dZ*dddddddddd	dZ+ e!deg eeddd      g eeddd      g eeddd      g e h d      g eeddd      g eeddd      g e h d       g eeddd      g eeddd      gd!gdegd"d#$      dddddddddd	d%       Z, G d& d'eeee      Z-y)+zLocally Linear Embedding    )IntegralRealN)eighqrsolvesvd)
csr_matrixeye
lil_matrix)eigsh   )BaseEstimatorClassNamePrefixFeaturesOutMixinTransformerMixin_fit_context_UnstableArchMixin)NearestNeighbors)check_arraycheck_random_state)_init_arpack_v0)Interval
StrOptionsvalidate_params)stable_cumsum)FLOAT_DTYPEScheck_is_fittedvalidate_dataMbP?c                    t        | t              } t        |t              }t        |t              }|j                  \  }}| j                  d   |k(  sJ t	        j
                  ||f| j                        }t	        j                  || j                        }t        |      D ]  \  }}	||	   }
|
| |   z
  }t	        j                  ||j                        }t	        j                  |      }|dkD  r||z  }n|}|j                  dd|dz   xx   |z  cc<   t        ||d      }|t	        j                  |      z  ||ddf<    |S )a  Compute barycenter weights of X from Y along the first axis

    We estimate the weights to assign to each point in Y[indices] to recover
    the point X[i]. The barycenter weights sum to 1.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_dim)

    Y : array-like, shape (n_samples, n_dim)

    indices : array-like, shape (n_samples, n_dim)
            Indices of the points in Y used to compute the barycenter

    reg : float, default=1e-3
        Amount of regularization to add for the problem to be
        well-posed in the case of n_neighbors > n_dim

    Returns
    -------
    B : array-like, shape (n_samples, n_neighbors)

    Notes
    -----
    See developers note for more information.
    dtyper   N   pos)assume_a)r   r   intshapenpemptyr!   ones	enumeratedotTtraceflatr   sum)XYindicesreg	n_samplesn_neighborsBviindACGr-   Rws                   h/var/www/html/diagnosisapp-backend/venv/lib/python3.12/site-packages/sklearn/manifold/_locally_linear.pybarycenter_weightsr@      s*   6 	A\*AA\*A'-G$]]I{771:"""
)[)9A
177+A G$  3cF!HFF1accN19eAA	!+/!"a'"!Q'bffQi-!Q$  H    c                 \   t        |dz   |      j                  |       }|j                  } |j                  }|j	                  | d      ddddf   }t        | | ||      }t        j                  d||z  dz   |      }t        |j                         |j                         |f||f      S )	a-  Computes the barycenter weighted graph of k-Neighbors for points in X

    Parameters
    ----------
    X : {array-like, NearestNeighbors}
        Sample data, shape = (n_samples, n_features), in the form of a
        numpy array or a NearestNeighbors object.

    n_neighbors : int
        Number of neighbors for each sample.

    reg : float, default=1e-3
        Amount of regularization when solving the least-squares
        problem. Only relevant if mode='barycenter'. If None, use the
        default.

    n_jobs : int or None, default=None
        The number of parallel jobs to run for neighbors search.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    Returns
    -------
    A : sparse matrix in CSR format, shape = [n_samples, n_samples]
        A[i, j] is assigned the weight of edge that connects i to j.

    See Also
    --------
    sklearn.neighbors.kneighbors_graph
    sklearn.neighbors.radius_neighbors_graph
    r"   r5   n_jobsF)return_distanceNr3   r   r&   )
r   fit_fit_Xn_samples_fit_
kneighborsr@   r'   aranger	   ravel)	r0   r5   r3   rD   knnr4   r9   dataindptrs	            r?   barycenter_kneighbors_graphrQ   R   s    B {Qv
F
J
J1
MC

A""I
..E.
21ab5
9CaCS1DYYq)k1A5{CFtzz|SYY[&9)YAWXXrA   r"   ư>d   c                 X   |dk(  r| j                   d   dkD  r||z   dk  rd}nd}|dk(  rTt        | j                   d   |      }	 t        | ||z   d|||      \  }}	|	d
d
|d
f   t        j                  ||d
       fS |dk(  r{t        | d      r| j                         } t        | |||z   dz
  fd      \  }}	t        j                  t        j                  |            }|	d
d
|f   t        j                  |      fS t	        d|z        # t        $ r}
t	        d	|
z        |
d
}
~
ww xY w)a0  
    Find the null space of a matrix M.

    Parameters
    ----------
    M : {array, matrix, sparse matrix, LinearOperator}
        Input covariance matrix: should be symmetric positive semi-definite

    k : int
        Number of eigenvalues/vectors to return

    k_skip : int, default=1
        Number of low eigenvalues to skip.

    eigen_solver : {'auto', 'arpack', 'dense'}, default='arpack'
        auto : algorithm will attempt to choose the best method for input data
        arpack : use arnoldi iteration in shift-invert mode.
                    For this method, M may be a dense matrix, sparse matrix,
                    or general linear operator.
                    Warning: ARPACK can be unstable for some problems.  It is
                    best to try several random seeds in order to check results.
        dense  : use standard dense matrix operations for the eigenvalue
                    decomposition.  For this method, M must be an array
                    or matrix type.  This method should be avoided for
                    large problems.

    tol : float, default=1e-6
        Tolerance for 'arpack' method.
        Not used if eigen_solver=='dense'.

    max_iter : int, default=100
        Maximum number of iterations for 'arpack' method.
        Not used if eigen_solver=='dense'

    random_state : int, RandomState instance, default=None
        Determines the random number generator when ``solver`` == 'arpack'.
        Pass an int for reproducible results across multiple function calls.
        See :term:`Glossary <random_state>`.
    autor      
   arpackdenseg        )sigmatolmaxiterv0a	  Error in determining null-space with ARPACK. Error message: '%s'. Note that eigen_solver='arpack' can fail when the weight matrix is singular or otherwise ill-behaved. In that case, eigen_solver='dense' is recommended. See online documentation for more information.Ntoarrayr"   T)subset_by_indexoverwrite_azUnrecognized eigen_solver '%s')r&   r   r   RuntimeError
ValueErrorr'   r/   hasattrr^   r   argsortabs)Mkk_skipeigen_solverr[   max_iterrandom_stater]   eigen_valueseigen_vectorseindexs               r?   
null_spacerp   |   sT   T v771:F
R#L"LxQWWQZ6	*/1v:Sc8+'L- QZ("&&fg1F*GGG		 1i 		A&*F
Q7T'
#m 

266,/0QX&|(<<<9LHII'  	6 9:	: 	s   D 	D)D$$D)rU   standard-C6?-q=)	r3   ri   r[   rj   methodhessian_tolmodified_tolrk   rD   c          	         t        |dz   |      }|j                  |        |j                  } | j                  \  }}||kD  rt	        d      ||k\  rt	        d||fz        |dk7  }|rt
        nt        j                  }|dk(  rt        ||||      }|r3t        |j                  d|j                  i|z
  }|j                  |z  }n|j                  |z  |j                  z
  |z
  j                         }|j                  d d |j                  d	   dz   xx   dz  cc<   n/|d
k(  r||dz   z  dz  }|||z   k  rt	        d      |j                  | |dz   d      }|d d dd f   }t        j                  |d|z   |z   ft        j                         }d|d d d	f<    |||ft        j                         }||kD  }t#        |      D ]i  }| ||      }||j%                  d	      z  }|rt'        |d	      d	   }n8t        j(                  ||j                        }t+        |      d   d d d d df   }|d d d |f   |d d dd|z   f<   d|z   }t#        |      D ]3  }|d d ||dz   f   |d d ||f   z  |d d |||z   |z
  f<   |||z
  z  }5 t-        |      \  }}|d d |dz   d f   }|j/                  d	      } d| t        j0                  t3        |       |k        <   || z  }t        j4                  ||   ||         \  }!}"||!|"fxx   t        j(                  ||j                        z  cc<   l n|dk(  r||k  rt	        d      |j                  | |dz   d      }|d d dd f   }t        j                  |||f      }#t7        ||      }$t        j                  ||$g      }%||kD  }|r;t#        |      D ]'  }| ||      | |   z
  }&t'        |&d      \  |#|<   |%|<   }') |%dz  }%nft#        |      D ]X  }| ||      | |   z
  }&t        j(                  |&|&j                        }(t+        |(      \  })}*|)d d d   |%|<   |*d d d d df   |#|<   Z d|%j/                  d      z  }t        j(                  |#j9                  d	dd      t        j:                  |            }+|+d d d |$fxx   |%|d d d f   z   z  cc<   |+d d |$d fxx   |d d d f   z  cc<   t        j                  ||f      },t#        |      D ]!  }t        j(                  |#|   |+|         |,|<   # |,|,j/                  d      d d d f   z  },|%d d |d f   j/                  d      |%d d d |f   j/                  d      z  }-t        j<                  |-      }.t        j                  |t>              }/tA        |%d      }0|0d d dd f   |0d d d df   z  dz
  }1t#        |      D ]#  }t        jB                  |1|d d df   |.      |/|<   % |/||$z
  z  }/ |||ft        j                         }t#        |      D ]  }|/|   }2|#|d d ||2z
  d f   }3t        jD                  jG                  |3j/                  d	            t        jH                  |2      z  }4t        jJ                  |2|4      t        j(                  |3j                  t        j:                  |            z
  }5t        jD                  jG                  |5      }6|6|	k  r|5d	z  }5n|5|6z  }5|3dt        jL                  t        j(                  |3|5      |5      z  z
  d|4z
  |,|d d d f   z  z   }7t        j4                  ||   ||         \  }!}"||!|"fxx   t        j(                  |7|7j                        z  cc<   |7j/                  d      }8||||   fxx   |8z  cc<   |||   |gfxx   |8z  cc<   |||fxx   |2z  cc<    n|dk(  r~|j                  | |dz   d      }|d d dd f   } |||ft        j                         }||kD  }t#        |      D ].  }| ||      }9|9|9j%                  d	      z  }9|rt'        |9d      d	   }:n8t        j(                  |9|9j                        }t+        |      d   d d d d df   }:t        j                  ||dz   f      }|:d d d |f   |d d dd f<   dt        jH                  |      z  |d d d	f<   t        j(                  ||j                        };t        j4                  ||   ||         \  }!}"||!|"fxx   |;z  cc<   |||   ||   fxx   t        j:                  |      z  cc<   1 |rjO                         }tQ        |d||||
      S )Nr"   rC   z>output dimension must be less than or equal to input dimensionzHExpected n_neighbors <= n_samples,  but n_samples = %d, n_neighbors = %drY   rq   )r5   r3   rD   formatr   hessianr   z^for method='hessian', n_neighbors must be greater than [n_components * (n_components + 3) / 2]Fr5   rE   r    )full_matricesmodifiedz1modified LLE requires n_neighbors >= n_componentsTr   ltsag      ?rG   )rh   ri   r[   rj   rk   ))r   rH   rI   r&   rb   r   r'   zerosrQ   r
   rx   r,   r^   r.   rK   r(   float64rangemeanr   r+   r   r   r/   wherere   meshgridmin	transposer)   medianr%   r   searchsortedlinalgnormsqrtfulloutertocsrrp   )<r0   r5   n_componentsr3   ri   r[   rj   rt   ru   rv   rk   rD   nbrsNd_inM_sparseM_container_constructorWrf   dp	neighborsYiuse_svdr8   GiUCijrg   Qr=   r>   Snbrs_xnbrs_yVnevevalsX_nbrs_C_nbrsevivitmpw_regrhoetas_rangeevals_cumsum	eta_ranges_iVialpha_ihnorm_hWiWi_sum1Xir7   GiGiTs<                                                               r?   _locally_linear_embeddingr      s	    aGDHHQKAggGAtdL
 	
 aV+
 	

 w&H,4j"(('ks6
 QWW.QXX.2AaAq133"++-AFF$aggaj1n$%*%	9	\A-.!3,++:  OO;?E $ 
	 ae$	XX{A$4r$9:"**M1a4#QF"**=$q 	0A9Q<B"''!*B !,Q/VVB%HQK4R4(*+A}},<*=Bq!a,&&&'L A<( &23Aq1q5yL/Aa<FWDX2X1a!l*Q.../\A%%& b6DAq!\A%''(AaA01Abhhs1v+,-FA[[1y|DNFFffn133/7	0: 
:	%PQQOO;?E $ 
	 ae$	
 HHak23$$!S" $1X D9Q<1Q4/$'d$C!!eAhD aKE1X #9Q<1Q4/1v,Rtt9a!TrT'{!# UYYq\!ffQ[[Aq)277;+?@AttGAtG,,AstGAtG$![)*q 	,AvvadCF+E!H	,1ag&& A|}$%))!,uQ5E/F/J/J1/MMiin
 ((1C($UA. BC(<3B3+??!C	q 	BA1dd7);SAGAJ	B;$$ $QF"**=q $	A!*C 1as*,,-BiinnRVVAY/"''#,>G
 W%rttRWW[5I(JJAYY^^A&F$QV a"((266"a=!444GuQPQSWZGX7XXB  [[1y|DNFFffnBDD!11ffQiGa1o')ilQC G+ adGsNGI$	L 
6	OO;?E $ 
	 ae$	#QF"**=$q 	HA9Q<B"''!*B $/2VVB%HQK4R4(;q(89:B!]l]*+Bq!"uIRWW[11Bq!tHFF2rtt$E[[1y|DNFFffn&ilIaL()RWW;-GG))	H, GGI	!! rA   z
array-likeleftclosed>   rU   rY   rX   >   r~   ry   r}   rq   rk   r0   r5   r   r3   ri   r[   rj   rt   ru   rv   rk   rD   Tprefer_skip_nested_validationc                0    t        | |||||||||	|
|      S )a  Perform a Locally Linear Embedding analysis on the data.

    Read more in the :ref:`User Guide <locally_linear_embedding>`.

    Parameters
    ----------
    X : {array-like, NearestNeighbors}
        Sample data, shape = (n_samples, n_features), in the form of a
        numpy array or a NearestNeighbors object.

    n_neighbors : int
        Number of neighbors to consider for each point.

    n_components : int
        Number of coordinates for the manifold.

    reg : float, default=1e-3
        Regularization constant, multiplies the trace of the local covariance
        matrix of the distances.

    eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'
        auto : algorithm will attempt to choose the best method for input data

        arpack : use arnoldi iteration in shift-invert mode.
                    For this method, M may be a dense matrix, sparse matrix,
                    or general linear operator.
                    Warning: ARPACK can be unstable for some problems.  It is
                    best to try several random seeds in order to check results.

        dense  : use standard dense matrix operations for the eigenvalue
                    decomposition.  For this method, M must be an array
                    or matrix type.  This method should be avoided for
                    large problems.

    tol : float, default=1e-6
        Tolerance for 'arpack' method
        Not used if eigen_solver=='dense'.

    max_iter : int, default=100
        Maximum number of iterations for the arpack solver.

    method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'
        standard : use the standard locally linear embedding algorithm.
                   see reference [1]_
        hessian  : use the Hessian eigenmap method.  This method requires
                   n_neighbors > n_components * (1 + (n_components + 1) / 2.
                   see reference [2]_
        modified : use the modified locally linear embedding algorithm.
                   see reference [3]_
        ltsa     : use local tangent space alignment algorithm
                   see reference [4]_

    hessian_tol : float, default=1e-4
        Tolerance for Hessian eigenmapping method.
        Only used if method == 'hessian'.

    modified_tol : float, default=1e-12
        Tolerance for modified LLE method.
        Only used if method == 'modified'.

    random_state : int, RandomState instance, default=None
        Determines the random number generator when ``solver`` == 'arpack'.
        Pass an int for reproducible results across multiple function calls.
        See :term:`Glossary <random_state>`.

    n_jobs : int or None, default=None
        The number of parallel jobs to run for neighbors search.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    Returns
    -------
    Y : ndarray of shape (n_samples, n_components)
        Embedding vectors.

    squared_error : float
        Reconstruction error for the embedding vectors. Equivalent to
        ``norm(Y - W Y, 'fro')**2``, where W are the reconstruction weights.

    References
    ----------

    .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction
        by locally linear embedding.  Science 290:2323 (2000).
    .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally
        linear embedding techniques for high-dimensional data.
        Proc Natl Acad Sci U S A.  100:5591 (2003).
    .. [3] `Zhang, Z. & Wang, J. MLLE: Modified Locally Linear
        Embedding Using Multiple Weights.
        <https://citeseerx.ist.psu.edu/doc_view/pid/0b060fdbd92cbcc66b383bcaa9ba5e5e624d7ee3>`_
    .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear
        dimensionality reduction via tangent space alignment.
        Journal of Shanghai Univ.  8:406 (2004)

    Examples
    --------
    >>> from sklearn.datasets import load_digits
    >>> from sklearn.manifold import locally_linear_embedding
    >>> X, _ = load_digits(return_X_y=True)
    >>> X.shape
    (1797, 64)
    >>> embedding, _ = locally_linear_embedding(X[:100],n_neighbors=5, n_components=2)
    >>> embedding.shape
    (100, 2)
    r   )r   r   s               r?   locally_linear_embeddingr     s6    T %
!!!! rA   c                   ~   e Zd ZU dZ eeddd      g eeddd      g eeddd      g eh d      g eeddd      g eeddd      g eh d      g eeddd      g eeddd      g eh d	      gd
gdegdZe	e
d<   ddddddddddddddZd Z ed      dd       Z ed      dd       Zd Zy)LocallyLinearEmbeddinga  Locally Linear Embedding.

    Read more in the :ref:`User Guide <locally_linear_embedding>`.

    Parameters
    ----------
    n_neighbors : int, default=5
        Number of neighbors to consider for each point.

    n_components : int, default=2
        Number of coordinates for the manifold.

    reg : float, default=1e-3
        Regularization constant, multiplies the trace of the local covariance
        matrix of the distances.

    eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'
        The solver used to compute the eigenvectors. The available options are:

        - `'auto'` : algorithm will attempt to choose the best method for input
          data.
        - `'arpack'` : use arnoldi iteration in shift-invert mode. For this
          method, M may be a dense matrix, sparse matrix, or general linear
          operator.
        - `'dense'`  : use standard dense matrix operations for the eigenvalue
          decomposition. For this method, M must be an array or matrix type.
          This method should be avoided for large problems.

        .. warning::
           ARPACK can be unstable for some problems.  It is best to try several
           random seeds in order to check results.

    tol : float, default=1e-6
        Tolerance for 'arpack' method
        Not used if eigen_solver=='dense'.

    max_iter : int, default=100
        Maximum number of iterations for the arpack solver.
        Not used if eigen_solver=='dense'.

    method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'
        - `standard`: use the standard locally linear embedding algorithm. see
          reference [1]_
        - `hessian`: use the Hessian eigenmap method. This method requires
          ``n_neighbors > n_components * (1 + (n_components + 1) / 2``. see
          reference [2]_
        - `modified`: use the modified locally linear embedding algorithm.
          see reference [3]_
        - `ltsa`: use local tangent space alignment algorithm. see
          reference [4]_

    hessian_tol : float, default=1e-4
        Tolerance for Hessian eigenmapping method.
        Only used if ``method == 'hessian'``.

    modified_tol : float, default=1e-12
        Tolerance for modified LLE method.
        Only used if ``method == 'modified'``.

    neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'},                           default='auto'
        Algorithm to use for nearest neighbors search, passed to
        :class:`~sklearn.neighbors.NearestNeighbors` instance.

    random_state : int, RandomState instance, default=None
        Determines the random number generator when
        ``eigen_solver`` == 'arpack'. Pass an int for reproducible results
        across multiple function calls. See :term:`Glossary <random_state>`.

    n_jobs : int or None, default=None
        The number of parallel jobs to run.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    Attributes
    ----------
    embedding_ : array-like, shape [n_samples, n_components]
        Stores the embedding vectors

    reconstruction_error_ : float
        Reconstruction error associated with `embedding_`

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    nbrs_ : NearestNeighbors object
        Stores nearest neighbors instance, including BallTree or KDtree
        if applicable.

    See Also
    --------
    SpectralEmbedding : Spectral embedding for non-linear dimensionality
        reduction.
    TSNE : Distributed Stochastic Neighbor Embedding.

    References
    ----------

    .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction
        by locally linear embedding.  Science 290:2323 (2000).
    .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally
        linear embedding techniques for high-dimensional data.
        Proc Natl Acad Sci U S A.  100:5591 (2003).
    .. [3] `Zhang, Z. & Wang, J. MLLE: Modified Locally Linear
        Embedding Using Multiple Weights.
        <https://citeseerx.ist.psu.edu/doc_view/pid/0b060fdbd92cbcc66b383bcaa9ba5e5e624d7ee3>`_
    .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear
        dimensionality reduction via tangent space alignment.
        Journal of Shanghai Univ.  8:406 (2004)

    Examples
    --------
    >>> from sklearn.datasets import load_digits
    >>> from sklearn.manifold import LocallyLinearEmbedding
    >>> X, _ = load_digits(return_X_y=True)
    >>> X.shape
    (1797, 64)
    >>> embedding = LocallyLinearEmbedding(n_components=2)
    >>> X_transformed = embedding.fit_transform(X[:100])
    >>> X_transformed.shape
    (100, 2)
    r"   Nr   r   r   >   rU   rY   rX   >   r~   ry   r}   rq   >   rU   brutekd_tree	ball_treerk   )r5   r   r3   ri   r[   rj   rt   ru   rv   neighbors_algorithmrk   rD   _parameter_constraints   r   r   rU   rR   rS   rq   rr   rs   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        || _	        |
| _
        || _        y N)r5   r   r3   ri   r[   rj   rt   ru   rv   rk   r   rD   )selfr5   r   r3   ri   r[   rj   rt   ru   rv   r   rk   rD   s                r?   __init__zLocallyLinearEmbedding.__init__  s_      '(( &((#6 rA   c                 J   t        | j                  | j                  | j                        | _        t        | j                        }t        | |t              }| j                  j                  |       t        | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                  || j$                  | j                        \  | _        | _        | j&                  j*                  d   | _        y )N)r5   	algorithmrD   r    )r0   r5   r   ri   r[   rj   rt   ru   rv   rk   r3   rD   r"   )r   r5   r   rD   nbrs_r   rk   r   floatrH   r   r   ri   r[   rj   rt   ru   rv   r3   
embedding_reconstruction_error_r&   _n_features_out)r   r0   rk   s      r?   _fit_transformz%LocallyLinearEmbedding._fit_transform  s    %((..;;

 *$*;*;<$/

q6Ojj((****]];;((**%;;7
33  $44Q7rA   Tr   c                 (    | j                  |       | S )ay  Compute the embedding vectors for data X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training set.

        y : Ignored
            Not used, present here for API consistency by convention.

        Returns
        -------
        self : object
            Fitted `LocallyLinearEmbedding` class instance.
        )r   r   r0   ys      r?   rH   zLocallyLinearEmbedding.fit*  s    " 	ArA   c                 <    | j                  |       | j                  S )a  Compute the embedding vectors for data X and transform X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training set.

        y : Ignored
            Not used, present here for API consistency by convention.

        Returns
        -------
        X_new : array-like, shape (n_samples, n_components)
            Returns the instance itself.
        )r   r   r   s      r?   fit_transformz$LocallyLinearEmbedding.fit_transform>  s    " 	ArA   c                    t        |        t        | |d      }| j                  j                  || j                  d      }t        || j                  j                  || j                        }t        j                  |j                  d   | j                  f      }t        |j                  d         D ]8  }t        j                  | j                  ||      j                  ||         ||<   : |S )a  
        Transform new points into embedding space.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training set.

        Returns
        -------
        X_new : ndarray of shape (n_samples, n_components)
            Returns the instance itself.

        Notes
        -----
        Because of scaling performed by this method, it is discouraged to use
        it together with methods that are not scale-invariant (like SVMs).
        F)resetrz   rF   r   )r   r   r   rK   r5   r@   rI   r3   r'   r(   r&   r   r   r+   r   r,   )r   r0   r9   weightsX_newr8   s         r?   	transformz LocallyLinearEmbedding.transformR  s    & 	$/jj##4++U $ 
 %Q

(9(93DHHM!''!*d&7&789qwwqz" 	EAvvdooc!f577DE!H	ErA   r   )__name__
__module____qualname____doc__r   r   r   r   r   dict__annotations__r   r   r   rH   r   r    rA   r?   r   r   Z  s*   BJ !1d6BC!(AtFCDq$v67#$?@Aq$v67h4?@IJK q$v>?!$4?@ *+T UV'("$D $ ":84 5 6& 5 6&rA   r   )r   )r   N)r"   rX   rR   rS   N).r   numbersr   r   numpyr'   scipy.linalgr   r   r   r   scipy.sparser	   r
   r   scipy.sparse.linalgr   baser   r   r   r   r   r   r   utilsr   r   utils._arpackr   utils._param_validationr   r   r   utils.extmathr   utils.validationr   r   r   r@   rQ   rp   r   r   r   r   rA   r?   <module>r      s   
 #  - - 4 4 %  ) 3 + K K ) K K3l'YV QUIJb 	up ,- 1d6BC!(AtFCDq$v67#$?@Aq$v67h4?@IJK q$v>?!$4?@'(" #', 	F#"FRU#	UrA   