def _core_dist(point, neighbors, dist_function):
"""
Computes the core distance of a point.
Core distance is the inverse density of an object.
Args:
point (np.array): array of dimensions (n_features,)
point to compute core distance of
neighbors (np.ndarray): array of dimensions (n_neighbors, n_features):
array of all other points in object class
dist_dunction (func): function to determine distance between objects
func args must be [np.array, np.array] where each array is a point
Returns: core_dist (float)
inverse density of point
"""
n_features = np.shape(point)[0]
n_neighbors = np.shape(neighbors)[1]
numerator = 0
for row in neighbors:
if not np.array_equal(point, row):
numerator += (1/dist_function(point, row))**n_features
core_dist = (numerator / (n_neighbors)) ** (-1/n_features)
return core_dist
评论列表
文章目录