xAI: Decision Boundary Analysis
The stride.xai.boundary subpackage provides tools for projecting high-dimensional feature spaces into 2D manifolds, rendering Supervised Decision Boundary Maps (SDBM), and characterizing boundary shifts using surrogate disagreement decision trees.
Overview
Boundary analysis tracks geometric deformations in classifier decision frontiers between reference and detection windows. It uses Self-Supervised Neighbor Projection (SSNP) for bi-directional dimensionality reduction and samples continuous latent grids to detect regions where models disagree.
Key Components
| Class / Function | Description |
|---|---|
DecisionBoundaryDriftAnalyzer |
High-level orchestrator that projects windows, fits pre- and post-drift classifiers, computes grid predictions, and evaluates disagreement regions. |
compute_disagreement_analysis |
Identifies disagreement regions where \(f_{\text{pre}}(x) \neq f_{\text{post}}(x)\) and fits surrogate decision trees to extract bounding decision rules. |
SSNP |
Neural autoencoder mapping \(\mathbb{R}^D \leftrightarrow \mathbb{R}^2\) while preserving neighborhood distances (requires tensorflow>=2.15). |
API Specification
stride.xai.boundary
Decision boundary migration analysis, neural projections, and disagreement trees.
DecisionBoundaryDriftAnalyzer
Analyze decision boundary shifts between data stream windows.
Projects high-dimensional feature spaces \(\mathbb{R}^D\) into an interpretable 2D manifold \(\mathbb{R}^2\) using Self-Supervised Neighbor Projection (SSNP) or passthrough scaling. A single SSNP projection is trained on both windows together and shared by both decision maps. Evaluates classifiers trained before (\(f_{\text{pre}}\)) and after (\(f_{\text{post}}\)) drift, reconstructs dense decision grids, and trains Disagreement Decision Trees to extract geometric boundary shift explanations.
Attributes:
| Name | Type | Description |
|---|---|---|
random_state |
Pseudo-random generator seed. |
|
X_before |
Pre-drift feature array of shape |
|
y_before |
Pre-drift target labels. |
|
X_after |
Post-drift feature array. |
|
y_after |
Post-drift target labels. |
Initialize the decision boundary analyzer with window splits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_before
|
ndarray | DataFrame
|
Reference feature data before drift. |
required |
y_before
|
ndarray | Series
|
Reference target labels before drift. |
required |
X_after
|
ndarray | DataFrame
|
Detection feature data after drift. |
required |
y_after
|
ndarray | Series
|
Detection target labels after drift. |
required |
random_state
|
int
|
Random state used to ensure reproducible projections. |
42
|
Source code in src/stride/xai/boundary/analysis.py
analyze
analyze(
model_class=None,
model_params=None,
grid_size=300,
ssnp_epochs=10,
ssnp_patience=5,
feature_names=None,
)
Compute decision boundary shifts and disagreement explanation trees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
Any | None
|
Classifier class used to map decision boundaries. Defaults to |
None
|
model_params
|
dict[str, Any] | None
|
Initialization keyword arguments passed to |
None
|
grid_size
|
int
|
Number of sampling intervals along each axis of the 2D grid (\(N imes N\)). |
300
|
ssnp_epochs
|
int
|
Training epochs for SSNP autoencoder projection network. |
10
|
ssnp_patience
|
int
|
Early stopping patience epochs for SSNP training. |
5
|
feature_names
|
list[str] | None
|
Optional sequence of human-readable feature column names. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing: - 'pre': Pre-drift results dictionary with classifier, 2D coordinates, and grid surfaces. - 'post': Post-drift results dictionary. - 'ssnp_model': Fitted projection model instance. - 'grid_size': Evaluated grid dimension. - 'disagreement': Disagreement analysis report and decision tree rules. - 'is_2d': Whether input data was natively 2-dimensional. |
Raises:
| Type | Description |
|---|---|
OptionalDependencyError
|
If input dimension \(> 2\) and |
Source code in src/stride/xai/boundary/analysis.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
compute_disagreement_analysis
compute_disagreement_analysis(
clf_pre,
clf_post,
X_eval_raw,
X_eval_scaled,
X_grid_high_scaled=None,
feature_names=None,
scaler=None,
)
Computes disagreement using the Inverse-Projected Grid (SDBM approach) to ensure visual consistency between the table and the plot.