
    {Kg-w                     2   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 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% 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)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_fittedMbP?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                   d/home/alanp/www/video.onchill/myenv/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    r3   n_jobsF)return_distanceNr1   r   )r$   )
r   fit_fit_Xn_samples_fit_
kneighborsr>   r%   aranger	   ravel)	r.   r3   r1   rB   knnr2   r7   dataindptrs	            r=   barycenter_kneighbors_graphrN   S   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Xr?   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_solverrX   max_iterrandom_staterZ   eigen_valueseigen_vectorseindexs               r=   
null_spacerm   }   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)rR   standard-C6?-q=)	r1   rf   rX   rg   methodhessian_tolmodified_tolrh   rB   c          	         t        |dz   |      }|j                  |        |j                  } | j                  \  }}||kD  rt	        d      ||k\  rt	        d||fz        |dk7  }|dk(  rt        ||||      }|rAt        |j                  d|j                  i|z
  }|j                  |z  j                         }n|j                  |z  |j                  z
  |z
  j                         }|j                  d d |j                  d	   dz   xx   dz  cc<   nM|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<   t        j                   ||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 |r*t7        |      }n|dk(  r||k  rt	        d      |j                  | |dz   d      }|d d dd f   }t        j                   |||f      }"t9        ||      }#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(                  |"j;                  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@              }.tC        |$d      }/|/d d dd f   |/d d d df   z  dz
  }0t#        |      D ]#  }t        jD                  |0|d d df   |-      |.|<   % |.||#z
  z  }.t        j                   ||ft        j                        }t#        |      D ]  }|.|   }1|"|d d ||1z
  d f   }2t        jF                  jI                  |2j/                  d	            t        jJ                  |1      z  }3t        jL                  |1|3      t        j(                  |2j                  t        j<                  |            z
  }4t        jF                  jI                  |4      }5|5|	k  r|4d	z  }4n|4|5z  }4|2dt        jN                  t        j(                  |2|4      |4      z  z
  d|3z
  |+|d d d f   z  z   }6t        j4                  ||   ||         \  } }!|| |!fxx   t        j(                  |6|6j                        z  cc<   |6j/                  d      }7||||   fxx   |7z  cc<   |||   |fxx   |7z  cc<   |||fxx   |1z  cc<    |rzt7        |      }nm|dk(  rg|j                  | |dz   d      }|d d dd f   }t        j                   ||f      }||kD  }t#        |      D ]  }| ||      }8|8|8j%                  d	      z  }8|rt'        |8d      d	   }9n8t        j(                  |8|8j                        }t+        |      d   d d d d df   }9t        j                   ||dz   f      }|9d d d |f   |d d dd f<   dt        jJ                  |      z  |d d d	f<   t        j(                  ||j                        }:t        j4                  ||   ||         \  } }!|| |!fxx   |:z  cc<   |||   ||   fxx   dz  cc<    tQ        |d||||
      S )Nr    rA   z>output dimension must be less than or equal to input dimensionzHExpected n_neighbors <= n_samples,  but n_samples = %d, n_neighbors = %drV   rn   )r3   r1   rB   formatr   hessianr   z^for method='hessian', n_neighbors must be greater than [n_components * (n_components + 3) / 2]Fr3   rC   r   )full_matricesmodifiedz1modified LLE requires n_neighbors >= n_componentsTr   ltsag      ?)re   rf   rX   rg   rh   ))r   rE   rF   r$   r_   rN   r
   ru   r*   tocsrr[   r,   rH   r%   r&   float64zerosrangemeanr   r)   r   r   r-   whererb   meshgridr	   min	transposer'   medianr#   r   searchsortedlinalgnormsqrtfullouterrm   );r.   r3   n_componentsr1   rf   rX   rg   rq   rr   rs   rh   rB   nbrsNd_inM_sparseWrc   dp	neighborsYiuse_svdr6   GiUCijrd   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Xir5   GiGiTs;                                                              r=   _locally_linear_embeddingr      s	    aGDHHQKAggGAtdL
 	
 aV+
 	

 w&H'ks6
 QWW.QXX.2Aq!Aq133"++-AFF$aggaj1n$%*%	9	\A-.!3,++:  OO;?E $ 
	 ae$	XX{A$4r$9:"**M1a4HHaV2::.$qA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 : 1A	:	%PQQOO;?E $ 
	 ae$	
 HHak23$$!S" $1X9Q<1Q4/$'d$C!!eAh  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A1dd7);SAGAJ ;$$ HHaV2::.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lAo')adGsNGI L 1A	6	OO;?E $ 
	 ae$	HHaV$q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()Q.)' * 	!! r?   z
array-likeleftclosed>   rR   rV   rU   >   r{   rv   rz   rn   rh   r.   r3   r   r1   rf   rX   rg   rq   rr   rs   rh   rB   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 %
!!!! r?   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   >   rR   rV   rU   >   r{   rv   rz   rn   >   rR   brutekd_tree	ball_treerh   )r3   r   r1   rf   rX   rg   rq   rr   rs   neighbors_algorithmrh   rB   _parameter_constraints   r   r   rR   rO   rP   rn   ro   rp   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        || _	        |
| _
        || _        y N)r3   r   r1   rf   rX   rg   rq   rr   rs   rh   r   rB   )selfr3   r   r1   rf   rX   rg   rq   rr   rs   r   rh   rB   s                r=   __init__zLocallyLinearEmbedding.__init__  s_      '(( &((#6 r?   c                 T   t        | j                  | j                  | j                        | _        t        | j                        }| j                  |t              }| j                  j                  |       t        | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                  || j$                  | j                        \  | _        | _        | j&                  j*                  d   | _        y )N)r3   	algorithmrB   r   )r.   r3   r   rf   rX   rg   rq   rr   rs   rh   r1   rB   r    )r   r3   r   rB   nbrs_r   rh   _validate_datafloatrE   r   r   rf   rX   rg   rq   rr   rs   r1   
embedding_reconstruction_error_r$   _n_features_out)r   r.   rh   s      r=   _fit_transformz%LocallyLinearEmbedding._fit_transform  s    %((..;;

 *$*;*;</

q6Ojj((****]];;((**%;;7
33  $44Q7r?   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   r.   ys      r=   rE   zLocallyLinearEmbedding.fit+  s    " 	Ar?   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r?   c                    t        |        | j                  |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)resetrw   rD   r   )r   r   r   rH   r3   r>   rF   r1   r%   r&   r$   r   r   r)   r   r*   )r   r.   r7   weightsX_newr6   s         r=   	transformz LocallyLinearEmbedding.transformS  s    & 	/jj##4++U $ 
 %Q

(9(93DHHM!''!*d&7&789qwwqz"Avvdooc!f577DE!H #r?   r   )__name__
__module____qualname____doc__r   r   r   r   r   dict__annotations__r   r   r   rE   r   r    r?   r=   r   r   [  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&r?   r   )r   )r   N)r    rU   rO   rP   N),r   numbersr   r   numpyr%   scipy.linalgr   r   r   r   scipy.sparser	   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>   rN   rm   r   r   r   r   r?   r=   <module>r      s~    #  - - ( %  ) 3 + 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r?   