'Computes the (weighted) graph of Neighbors for points in X
Neighborhoods are restricted the points at a distance lower than
radius.
Parameters
X : array-like, shape = [n_samples, n_features], optional
The query point or points.
If not provided, neighbors of each indexed point are returned.
In this case, the query point is not considered its own neighbor.
radius : float
Radius of neighborhoods.
(default is the value passed to the constructor).
mode : {\'connectivity\', \'distance\'}, optional
Type of returned matrix: \'connectivity\' will return the
connectivity matrix with ones and zeros, in \'distance\' the
edges are Euclidean distance between points.
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.
Examples
>>> X = [[0], [3], [1]]
>>> from sklearn.neighbors import NearestNeighbors
>>> neigh = NearestNeighbors(radius=1.5)
>>> neigh.fit(X) # doctest: +ELLIPSIS
NearestNeighbors(algorithm=\'auto\', leaf_size=30, ...)
>>> A = neigh.radius_neighbors_graph(X)
>>> A.toarray()
array([[ 1.,  0.,  1.],
[ 0.,  1.,  0.],
[ 1.,  0.,  1.]])
See also
kneighbors_graph'

def radius_neighbors_graph(self, X=None, radius=None, mode='connectivity'):

    if (X is not None):
        X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
    n_samples2 = self._fit_X.shape[0]
    if (radius is None):
        radius = self.radius
    if (mode == 'connectivity'):
        A_ind = self.radius_neighbors(X, radius, return_distance=False)
        A_data = None
    elif (mode == 'distance'):
        (dist, A_ind) = self.radius_neighbors(X, radius, return_distance=True)
        A_data = np.concatenate(list(dist))
    else:
        raise ValueError(('Unsupported    mode,    must    be    one    of    "connectivity",    or    "distance"    but    got    %s    instead' % mode))
    n_samples1 = A_ind.shape[0]
    n_neighbors = np.array([len(a) for a in A_ind])
    A_ind = np.concatenate(list(A_ind))
    if (A_data is None):
        A_data = np.ones(len(A_ind))
    A_indptr = np.concatenate((np.zeros(1, dtype=int), np.cumsum(n_neighbors)))
    return csr_matrix((A_data, A_ind, A_indptr), shape=(n_samples1, n_samples2))
