netrd/reconstruction/convergent_cross_mapping.py
def nearest_neighbors(shadow, L):
    """
    Return time indices of the N+1 nearest neighbors for every point in the
    shadow data cloud and their corresponding Euclidean distances.

    Params
    ------
    shadow (np.ndarray): Array of the shadow data cloud.

    L (int): Number of observations in the time series.

    Returns
    -------
    nei (np.ndarray): $M \times (N+1)$ array of time indices of nearest
                      neighbors where $M$ is the number of points in the
                      shadow data cloud.

    dist (np.ndarray): $M \times (N+1)$ array of corresponding Euclidean
                       distance between the data point to the neighbors.

    Notes
    -----
    1. The nearest neighbors are ordered in increasing order of distances.

    2. If the length of time series is at a larger scale than the number of
       variables, specifically N + 2 < M/2, the implementation finds nearest
       neighbors using the Ball Tree data structure; otherwise the brute force
       method is applied.

    """
    M, N = shadow.shape
    k = N + 2  # Number of nearest neighbors to be found, including itself
    method = 'ball_tree' if k < M/2 else 'brute'
    nbrs = NearestNeighbors(n_neighbors=k, algorithm=method).fit(shadow)
    dist, nei = nbrs.kneighbors(shadow)

    # Remove the first column for both arrays, which stands for the data points
    # themselves
    nei = np.delete(nei, 0, axis=1)
    dist = np.delete(dist, 0, axis=1)

    # Modify the neighbors' indices to their time indices
    nei += (L - M)

    return nei, dist

    Return time indices of the N+1 nearest neighbors for every point in the
    shadow data cloud and their corresponding Euclidean distances.

    Params
    ------
    shadow (np.ndarray): Array of the shadow data cloud.

    L (int): Number of observations in the time series.

    Returns
    -------
    nei (np.ndarray): $M \times (N+1)$ array of time indices of nearest
                      neighbors where $M$ is the number of points in the
                      shadow data cloud.

    dist (np.ndarray): $M \times (N+1)$ array of corresponding Euclidean
                       distance between the data point to the neighbors.

    Notes
    -----
    1. The nearest neighbors are ordered in increasing order of distances.

    2. If the length of time series is at a larger scale than the number of
       variables, specifically N + 2 < M/2, the implementation finds nearest
       neighbors using the Ball Tree data structure; otherwise the brute force
       method is applied.

    
Return time indices of the N+1 nearest neighbors for every point in the
shadow data cloud and their corresponding Euclidean distances.

Params

shadow (np.ndarray): Array of the shadow data cloud.

L (int): Number of observations in the time series.

Returns

nei (np.ndarray): $M \times (N+1)$ array of time indices of nearest
neighbors where $M$ is the number of points in the
shadow data cloud.

dist (np.ndarray): $M \times (N+1)$ array of corresponding Euclidean
distance between the data point to the neighbors.

Notes

1. The nearest neighbors are ordered in increasing order of distances.

2. If the length of time series is at a larger scale than the number of
variables, specifically N + 2 < M/2, the implementation finds nearest
neighbors using the Ball Tree data structure; otherwise the brute force
method is applied.
Return time indices of the N + 1 nearest neighbors for every point in the shadow data cloud and their corresponding Euclidean distances . Params shadow ( np . ndarray ) : Array of the shadow data cloud . L ( int ) : Number of observations in the time series . Returns nei ( np . ndarray ) : $M \ times ( N + 1 ) $ array of time indices of nearest neighbors where $M$ is the number of points in the shadow data cloud . dist ( np . ndarray ) : $M \ times ( N + 1 ) $ array of corresponding Euclidean distance between the data point to the neighbors . Notes 1 . The nearest neighbors are ordered in increasing order of distances . 2 . If the length of time series is at a larger scale than the number of variables specifically N + 2 < M / 2 the implementation finds nearest neighbors using the Ball Tree data structure ; otherwise the brute force method is applied .
def nearest_neighbors(shadow, L):
    M, N = shadow.shape
    k = N + 2  
    method = 'ball_tree' if k < M/2 else 'brute'
    nbrs = NearestNeighbors(n_neighbors=k, algorithm=method).fit(shadow)
    dist, nei = nbrs.kneighbors(shadow)
    nei = np.delete(nei, 0, axis=1)
    dist = np.delete(dist, 0, axis=1)
    nei += (L - M)
    return nei, dist
def nearest_neighbors ( shadow , L ) : M , N = shadow . shape k = N + 2 method = 'ball_tree' if k < M / 2 else 'brute' nbrs = NearestNeighbors ( n_neighbors = k , algorithm = method ) . fit ( shadow ) dist , nei = nbrs . kneighbors ( shadow ) nei = np . delete ( nei , 0 , axis = 1 ) dist = np . delete ( dist , 0 , axis = 1 ) nei += ( L - M ) return nei , dist
Return time indices of the N+1 nearest neighbors for every point in the
shadow data cloud and their corresponding Euclidean distances.
Return time indices of the N + 1 nearest neighbors for every point in the shadow data cloud and their corresponding Euclidean distances .
"""
    Return time indices of the N+1 nearest neighbors for every point in the
    shadow data cloud and their corresponding Euclidean distances.

    Params
    ------
    shadow (np.ndarray): Array of the shadow data cloud.

    L (int): Number of observations in the time series.

    Returns
    -------
    nei (np.ndarray): $M \times (N+1)$ array of time indices of nearest
                      neighbors where $M$ is the number of points in the
                      shadow data cloud.

    dist (np.ndarray): $M \times (N+1)$ array of corresponding Euclidean
                       distance between the data point to the neighbors.

    Notes
    -----
    1. The nearest neighbors are ordered in increasing order of distances.

    2. If the length of time series is at a larger scale than the number of
       variables, specifically N + 2 < M/2, the implementation finds nearest
       neighbors using the Ball Tree data structure; otherwise the brute force
       method is applied.

    """ # Number of nearest neighbors to be found, including itself # Remove the first column for both arrays, which stands for the data points # themselves # Modify the neighbors' indices to their time indices
shadow
L