(X, time_delay, dimension, stride=1)
return n_false_neighbors
Calculate the number of false nearest neighbours in a certain
    embedding dimension, based on heuristics.
Calculate the number of false nearest neighbours in a certain
    embedding dimension, based on heuristics.
Calculate the number of false nearest neighbours in a certain embedding dimension based on heuristics .
def _false_nearest_neighbors(X, time_delay, dimension, stride=1):
    """Calculate the number of false nearest neighbours in a certain
    embedding dimension, based on heuristics."""
    X_embedded = _time_delay_embedding(X, time_delay=time_delay,
                                       dimension=dimension, stride=stride)

    neighbor = \
        NearestNeighbors(n_neighbors=2, algorithm='auto').fit(X_embedded)
    distances, indices = neighbor.kneighbors(X_embedded)
    distance = distances[:, 1]
    X_first_nbhrs = X[indices[:, 1]]

    epsilon = 2. * np.std(X)
    tolerance = 10

    neg_dim_delay = - dimension * time_delay
    distance_slice = distance[:neg_dim_delay]
    X_rolled = np.roll(X, neg_dim_delay)
    X_rolled_slice = slice(len(X) - len(X_embedded), neg_dim_delay)
    X_first_nbhrs_rolled = np.roll(X_first_nbhrs, neg_dim_delay)

    neighbor_abs_diff = np.abs(
        X_rolled[X_rolled_slice] - X_first_nbhrs_rolled[:neg_dim_delay]
        )

    false_neighbor_ratio = np.divide(
        neighbor_abs_diff, distance_slice,
        out=np.zeros_like(neighbor_abs_diff, dtype=float),
        where=(distance_slice != 0)
        )
    false_neighbor_criteria = false_neighbor_ratio > tolerance

    limited_dataset_criteria = distance_slice < epsilon

    n_false_neighbors = \
        np.sum(false_neighbor_criteria * limited_dataset_criteria)
    return n_false_neighbors
def _false_nearest_neighbors ( X , time_delay , dimension , stride = 1 ) : X_embedded = _time_delay_embedding ( X , time_delay = time_delay , dimension = dimension , stride = stride ) neighbor = NearestNeighbors ( n_neighbors = 2 , algorithm = 'auto' ) . fit ( X_embedded ) distances , indices = neighbor . kneighbors ( X_embedded ) distance = distances [ : , 1 ] X_first_nbhrs = X [ indices [ : , 1 ] ] epsilon = 2. * np . std ( X ) tolerance = 10 neg_dim_delay = - dimension * time_delay distance_slice = distance [ : neg_dim_delay ] X_rolled = np . roll ( X , neg_dim_delay ) X_rolled_slice = slice ( len ( X ) - len ( X_embedded ) , neg_dim_delay ) X_first_nbhrs_rolled = np . roll ( X_first_nbhrs , neg_dim_delay ) neighbor_abs_diff = np . abs ( X_rolled [ X_rolled_slice ] - X_first_nbhrs_rolled [ : neg_dim_delay ] ) false_neighbor_ratio = np . divide ( neighbor_abs_diff , distance_slice , out = np . zeros_like ( neighbor_abs_diff , dtype = float ) , where = ( distance_slice != 0 ) ) false_neighbor_criteria = false_neighbor_ratio > tolerance limited_dataset_criteria = distance_slice < epsilon n_false_neighbors = np . sum ( false_neighbor_criteria * limited_dataset_criteria ) return n_false_neighbors