MCPcopy
hub / github.com/mne-tools/mne-python / _compute_nearest

Function _compute_nearest

mne/surface.py:618–646  ·  view source on GitHub ↗

Find nearest neighbors. Parameters ---------- xhs : array, shape=(n_samples, n_dim) Points of data set. rr : array, shape=(n_query, n_dim) Points to find nearest neighbors for. method : str The query method. If scikit-learn and scipy<1.0 are installed,

(xhs, rr, method="BallTree", return_dists=False)

Source from the content-addressed store, hash-verified

616
617
618def _compute_nearest(xhs, rr, method="BallTree", return_dists=False):
619 """Find nearest neighbors.
620
621 Parameters
622 ----------
623 xhs : array, shape=(n_samples, n_dim)
624 Points of data set.
625 rr : array, shape=(n_query, n_dim)
626 Points to find nearest neighbors for.
627 method : str
628 The query method. If scikit-learn and scipy<1.0 are installed,
629 it will fall back to the slow brute-force search.
630 return_dists : bool
631 If True, return associated distances.
632
633 Returns
634 -------
635 nearest : array, shape=(n_query,)
636 Index of nearest neighbor in xhs for every point in rr.
637 distances : array, shape=(n_query,)
638 The distances. Only returned if return_dists is True.
639 """
640 if xhs.size == 0 or rr.size == 0:
641 if return_dists:
642 return np.array([], int), np.array([])
643 return np.array([], int)
644 tree = _DistanceQuery(xhs, method=method)
645 out = tree.query(rr)
646 return out[::-1] if return_dists else out[1]
647
648
649def _safe_query(rr, func, reduce=False, **kwargs):

Callers 15

test_compute_nearestFunction · 0.90
_compute_depthFunction · 0.90
_nearest_vol_indFunction · 0.90
_get_ico_mapFunction · 0.85
_check_thicknessesFunction · 0.85
distance_to_bemFunction · 0.85
_make_morph_map_hemiFunction · 0.85
_project_onto_surfaceFunction · 0.85
_create_surf_spacingFunction · 0.85
_decimate_surface_sphereFunction · 0.85
dig_mri_distancesFunction · 0.85
_surface_constraintFunction · 0.85

Calls 2

_DistanceQueryClass · 0.85
queryMethod · 0.45

Tested by 3

test_compute_nearestFunction · 0.72
_compute_depthFunction · 0.72
_nearest_vol_indFunction · 0.72