Skip to content

Sequences, streaming data, robotics, and scientific extensions · Entry index · SEQ004 · Algorithm

DenStream

A density-based stream-clustering algorithm using fading micro-clusters to summarize evolving data and separate potential clusters from outliers.

Runs in CodeSplash Component demo, not a trained model CodeSplash's own run

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's own run
CodeSplash's run
Verified in Python and R through discover.stream_clusters. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, but on a different version of the code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

A density-based stream-clustering algorithm using fading micro-clusters to summarize evolving data and separate potential clusters from outliers. It addresses bounded-memory online updates and later cluster extraction, rather than repeatedly applying batch DBSCAN to all historical observations.

Question / hypotheses

Which dense groups persist or emerge in a changing stream when older observations lose relevance? This is unsupervised clustering, not a significance test; cluster validity and detection delay need separately chosen evaluation criteria.

Architecture / computational structure

Online steps try to absorb observations into eligible summaries, create outlier summaries when necessary, promote sufficiently dense summaries, and prune stale ones. An offline phase connects potential micro-clusters into larger groups. This differs from ordinary mini-batch centroid updates.

Assumptions

Distance and feature scaling must reflect meaningful similarity. Time decay assumes older evidence should matter less. A micro-cluster summary loses historical detail, and irregular arrival rates can change effective evidence unless time units and update conventions are carefully defined.

Formula / computational definition

An observation at tit_i has fading weight 2−λ(t−ti)2^{-\lambda(t-t_i)}. A micro-cluster maintains decayed count and first/second feature sums, giving a center and radius. Density thresholds separate potential and outlier micro-clusters; periodic pruning and offline density connectivity complete the algorithm.

Parameters and notation

Estimated state: micro-cluster centers, radii, weighted counts, and membership/connectivity. No neural weights are learned. Hyperparameters include decay lambda, neighborhood radius epsilon, density thresholds, initialization, and pruning schedule. Faster decay adapts sooner but can erase low-frequency legitimate clusters.

Fitting, fine-tuning, and adaptation

Initialize from a representative initial stream segment and update sufficient statistics chronologically. Adaptation occurs through fading and summary updates, not neural fine-tuning. Retuning radius or scaling can change existing summary meaning; document whether state is rebuilt or transformed after such changes.

How to use and calibrate

Evaluate prequential clustering quality where labels exist, memory/update cost, outlier behavior, cluster birth/death delay, and stability under changing arrival rates. Match cluster labels before comparing partitions over time; arbitrary label IDs are not persistent semantic identities.

Example application

Use drifting synthetic blobs with a new cluster appearing late, then graph effective weights, cluster centers, and adaptation delay.

Interpretation / pitfalls

Watch out

Python: an implementation verified against the original DenStream algorithm or custom micro-cluster maintenance. R: a validated stream-clustering implementation or reticulate; no native API is presumed. The code demonstrates exponential fading only and omits promotion, pruning, and density connectivity.

Python and R code examples (dependencies/validation)

Python uses NumPy and the shared mse helper when called; base R uses the shared helper when called. Validation: Python component executed; R companion reviewed, not executed. Scope: the specific component described above, not the full model or its training.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
import numpy as np

def mse(a,b):
    a,b=np.asarray(a),np.asarray(b)
    if a.shape!=b.shape or a.size==0:
        raise ValueError("MSE needs nonempty equal shapes")
    return float(np.mean((a-b)**2))
arrival=np.array([0.,2.,4.]); now=5.; decay=.5
weights=2**(-decay*(now-arrival))
result={"weights":weights,"effective_count":float(weights.sum())}
print(result)
R

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
mse <- function(a,b) {
  stopifnot(length(a)>0L, identical(dim(a),dim(b)), length(a)==length(b))
  mean((a-b)^2)
}
arrival <- c(0,2,4); now <- 5; decay <- .5
weights <- 2^(-decay*(now-arrival))
result <- list(weights=weights,effective_count=sum(weights))
print(result)

Sources

From the CodeSplash reference, entry SEQ004.