def _friends_leaveoneout_radius(points, ftype):
"""Internal method used to compute the radius (half-side-length) for each
ball (cube) used in :class:`RadFriends` (:class:`SupFriends`) using
leave-one-out (LOO) cross-validation."""
# Construct KDTree to enable quick nearest-neighbor lookup for
# our resampled objects.
kdtree = spatial.KDTree(points)
if ftype == 'balls':
# Compute radius to two nearest neighbors (self + neighbor).
dists, ids = kdtree.query(points, k=2, eps=0, p=2)
elif ftype == 'cubes':
# Compute half-side-length to two nearest neighbors (self + neighbor).
dists, ids = kdtree.query(points, k=2, eps=0, p=np.inf)
dist = dists[:, 1] # distances to LOO nearest neighbor
return dist
评论列表
文章目录