Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
sklearn
/
manifold
/
__pycache__
/
File Content:
locally_linear.cpython-35.opt-1.pyc
(�(X e � @ s6 d 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 m Z d d l m Z m Z d d l m Z d d l m Z d d l m Z d d l m Z d d d � Z d d d d � Z d d d d d d d � Z d d d d d d d d d d d � Z Gd d � d e e � Z d S)zLocally Linear Embedding� N)�eigh�svd�qr�solve)�eye� csr_matrix� )� BaseEstimator�TransformerMixin)�check_random_state�check_array)�eigsh)�check_is_fitted)�FLOAT_DTYPES)�NearestNeighborsg����MbP?c C s\ t | d t �} t | d t d d �} | j d | j d } } t j | | f d | j �} t j | d | j �} x� t | j d d d � � D]� \ } } | j | | } t j | | j � } t j | � } | d k r� | | } n | } | j d d | j d d � | 7<t | | d d �} | t j | � | | d d � f <q� W| S) aa Compute barycenter weights of X from Y along the first axis We estimate the weights to assign to each point in Y[i] to recover the point X[i]. The barycenter weights sum to 1. Parameters ---------- X : array-like, shape (n_samples, n_dim) Z : array-like, shape (n_samples, n_neighbors, n_dim) reg: float, optional 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. �dtypeZallow_ndTr � r NZsym_pos)r r �shape�np�emptyr �ones� enumerate� transpose�T�dot�trace�flatr �sum)�X�Z�reg� n_samples�n_neighbors�B�v�i�A�C�Gr �R�w� r+ �/locally_linear.py�barycenter_weights s ( %'r- r c C s� t | d d | �j | � } | j } | j d } | j | d d �d d � d d � f } t | | | d | �} t j d | | d | � } t | j � | j � | f d | | f �S) a Computes the barycenter weighted graph of k-Neighbors for points in X Parameters ---------- X : {array-like, sparse matrix, BallTree, KDTree, NearestNeighbors} Sample data, shape = (n_samples, n_features), in the form of a numpy array, sparse array, precomputed tree, or NearestNeighbors object. n_neighbors : int Number of neighbors for each sample. reg : float, optional Amount of regularization when solving the least-squares problem. Only relevant if mode='barycenter'. If None, use the default. n_jobs : int, optional (default = 1) The number of parallel jobs to run for neighbors search. If ``-1``, then the number of jobs is set to the number of CPU cores. 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 �n_jobsr �return_distanceFNr r ) r �fit�_fit_Xr � kneighborsr- r Zaranger Zravel) r r"