Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support p values other than 2 for minkowski #637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions hdbscan/hdbscan_.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ def _hdbscan_prims_kdtree(
# The Cython routines used require contiguous arrays
if not X.flags["C_CONTIGUOUS"]:
X = np.array(X, dtype=np.double, order="C")


if p!= 2 and 'p' not in kwargs:
kwargs['p'] = p

tree = KDTree(X, metric=metric, leaf_size=leaf_size, **kwargs)

# TO DO: Deal with p for minkowski appropriately

dist_metric = DistanceMetric.get_metric(metric, **kwargs)

# Get distance to kth nearest neighbour
Expand Down Expand Up @@ -292,7 +294,10 @@ def _hdbscan_prims_balltree(
# The Cython routines used require contiguous arrays
if not X.flags["C_CONTIGUOUS"]:
X = np.array(X, dtype=np.double, order="C")


if p!= 2 and 'p' not in kwargs:
kwargs['p'] = p

tree = BallTree(X, metric=metric, leaf_size=leaf_size, **kwargs)

dist_metric = DistanceMetric.get_metric(metric, **kwargs)
Expand Down Expand Up @@ -335,7 +340,10 @@ def _hdbscan_boruvka_kdtree(

if X.dtype != np.float64:
X = X.astype(np.float64)


if p!= 2 and 'p' not in kwargs:
kwargs['p'] = p

tree = KDTree(X, metric=metric, leaf_size=leaf_size, **kwargs)
alg = KDTreeBoruvkaAlgorithm(
tree,
Expand Down Expand Up @@ -379,7 +387,10 @@ def _hdbscan_boruvka_balltree(

if X.dtype != np.float64:
X = X.astype(np.float64)


if p!= 2 and 'p' not in kwargs:
kwargs['p'] = p

tree = BallTree(X, metric=metric, leaf_size=leaf_size, **kwargs)
alg = BallTreeBoruvkaAlgorithm(
tree,
Expand Down Expand Up @@ -1137,7 +1148,10 @@ def __init__(
self.prediction_data = prediction_data

self._metric_kwargs = kwargs


if p is not None:
self._metric_kwargs['p'] = p

self._condensed_tree = None
self._single_linkage_tree = None
self._min_spanning_tree = None
Expand Down