xAI: Recurring Concepts & Memory
The stride.xai.recurrence subpackage provides tools for archiving stream window representations, computing pairwise structural distance matrices, and discovering recurring concept regimes using HDBSCAN density clustering.
Overview
Recurring concept detection addresses streams that alternate between distinct recurring distributions over time. By maintaining prototype vectors per window and clustering distance matrices with HDBSCAN, STRIDE recognizes when a previously seen concept re-emerges.
Key Components
| Class / Function | Description |
|---|---|
FullWindowStorage |
Archives window snapshots (features, labels, class prototypes, fitted explainers) and computes pairwise inter-window distance matrices. |
cluster_windows |
Clusters precomputed window distance matrices using HDBSCAN with optional noise outlier reassignment (fix_outliers=True). |
get_drift_from_clusters |
Identifies concept transition timestamps where the assigned active concept regime ID changes. |
API Specification
stride.xai.recurrence
Recurring concept memory, prototype trees, and historical window distance matrices.
FullWindowStorage
Stores data for every window during the stream, enabling distance computations.
Initialize storage for all windows.
Source code in src/stride/xai/recurrence/full_window_storage.py
compare_two_windows
compare_two_windows(
iter_a,
iter_b,
measure="centroid_displacement",
strategy="total",
distance="l2",
)
Compare two specific windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iter_a
|
int
|
First iteration number |
required |
iter_b
|
int
|
Second iteration number |
required |
measure
|
Literal['mutual_information', 'rand_index', 'completeness', 'fowlkes_mallows', 'centroid_displacement', 'minimal_distance', 'prototype_reassignment_impact']
|
Comparison metric to use |
'centroid_displacement'
|
strategy
|
Literal['class', 'total']
|
"class" for class-wise, "total" for overall |
'total'
|
distance
|
Literal['l2', 'tree']
|
"l2" for Euclidean, "tree" for tree-based distance |
'l2'
|
Returns:
| Type | Description |
|---|---|
float
|
Distance/similarity score between the two windows |
Source code in src/stride/xai/recurrence/full_window_storage.py
compare_window_to_all
compare_window_to_all(
target_iter,
measure="centroid_displacement",
strategy="total",
distance="l2",
)
Compare one window against all other stored windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_iter
|
int
|
Iteration number to compare |
required |
measure
|
Literal['mutual_information', 'rand_index', 'completeness', 'fowlkes_mallows', 'centroid_displacement', 'minimal_distance', 'prototype_reassignment_impact']
|
Comparison metric to use |
'centroid_displacement'
|
strategy
|
Literal['class', 'total']
|
"class" for class-wise, "total" for overall |
'total'
|
distance
|
Literal['l2', 'tree']
|
"l2" for Euclidean, "tree" for tree-based distance |
'l2'
|
Returns:
| Type | Description |
|---|---|
Series
|
Series with iteration numbers as index and distances as values |
Source code in src/stride/xai/recurrence/full_window_storage.py
compute_distance_matrix
compute_distance_matrix(
measure="centroid_displacement",
strategy="total",
distance="l2",
verbose=False,
)
Compute full distance matrix between all stored windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
Literal['mutual_information', 'rand_index', 'completeness', 'fowlkes_mallows', 'centroid_displacement', 'minimal_distance', 'prototype_reassignment_impact']
|
Comparison metric to use |
'centroid_displacement'
|
strategy
|
Literal['class', 'total']
|
"class" for class-wise, "total" for overall |
'total'
|
distance
|
Literal['l2', 'tree']
|
"l2" for Euclidean, "tree" for tree-based distance |
'l2'
|
verbose
|
bool
|
Whether to print progress during matrix calculation. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame where rows and columns are iteration numbers, values are distances |
Source code in src/stride/xai/recurrence/full_window_storage.py
get_all_iterations
get_window_data
Get all data for a specific window.
Returns:
| Type | Description |
|---|---|
tuple[TDataBatch, TTarget, TPrototypes, TExplainer]
|
Tuple of (x, y, prototypes, explainer) |
Source code in src/stride/xai/recurrence/full_window_storage.py
store_window
Store window data for a given iteration.