Skip to content

API Reference

pydpc.Cluster(points, fraction=0.02, autoplot=True, **kwargs)

Bases: Graph

Density-peak clustering of a set of points.

Constructing a Cluster computes the pairwise distances, local density, and decision-graph quantities (density, delta) for points. Cluster centers are then chosen interactively by inspecting the decision graph and calling :meth:assign with density/delta thresholds that isolate the outlying points (the candidate centers).

Examples:

>>> clu = Cluster(points)
>>> clu.assign(min_density=20, min_delta=1.5)
>>> clu.membership  # cluster index for each point

Parameters:

Name Type Description Default
points ndarray of shape (n_points, n_dim)

Coordinates of the data points to cluster.

required
fraction float

Average fraction of all other points to treat as neighbours when estimating the density kernel size.

0.02
autoplot bool

If True, automatically draw the decision graph on construction and again (with the chosen thresholds indicated) whenever :meth:assign is called.

True
**kwargs

Additional keyword arguments forwarded to :class:Graph, e.g. a precomputed distances matrix or an explicit kernel_size.

{}

Attributes:

Name Type Description
density ndarray of shape (n_points,)

Local density of each data point.

delta ndarray of shape (n_points,)

Minimal distance of each point to a point of higher density.

clusters ndarray of int

Indices of the chosen cluster centers. Set by :meth:assign.

membership ndarray of shape (n_points,)

Cluster index assigned to each point. Set by :meth:assign.

halo_idx ndarray of int

Indices of points classified as halo (low-confidence) members. Set by :meth:assign.

core_idx ndarray of int

Indices of points classified as core (high-confidence) members. Set by :meth:assign.

assign(min_density, min_delta, border_only=False)

Choose cluster centers via decision-graph thresholds and assign points.

Points with density above min_density and delta above min_delta are taken as cluster centers; every other point is then assigned to the cluster of its nearest denser neighbour.

Parameters:

Name Type Description Default
min_density float

Minimum density for a point to be considered a cluster center.

required
min_delta float

Minimum delta for a point to be considered a cluster center.

required
border_only bool

If False (default), classify as halo any point whose density is below its cluster's border density (the original Rodriguez/Laio criterion). If True, only classify points as halo where they border a different cluster, which is less strict and keeps more points in the core.

False

Returns:

Type Description
None

Results are stored on the instance; see the clusters, membership, border_density, border_member, halo_idx, and core_idx attributes.

Raises:

Type Description
ValueError

If no point satisfies both thresholds, i.e. no cluster center is found.

draw_decision_graph(min_density=None, min_delta=None)

Plot the decision graph (density vs. delta) for all points.

Parameters:

Name Type Description Default
min_density float

If given together with min_delta, draw red threshold lines marking the region density > min_density and delta > min_delta.

None
min_delta float

See min_density.

None

Returns:

Name Type Description
fig Figure
ax Axes