Knowledge-Guided Local-to-Global Anomaly Learning for Longitudinal Medication Trajectories
Authors: Wendi Ji
Organizations: Department of Intelligent Science and Information Law, East China University of Political Science and Law, 555 Longyuan Road, Songjiang University Town, Shanghai, 201620, China
Detecting suspicious deviations in longitudinal medication trajectories requires distinguishing knowledge-consistent treatment variations from anomalous changes and linking local deviations to account-level decisions. We propose a knowledge-guided local-to-global (L2G) anomaly learning framework that addresses both challenges. It constructs proxy supervision at three granularities: medication occurrences, treatment episodes, and contiguous visit segments. Knowledge-consistent medication and episode replacements provide plausible negatives, while cross-category and cross-account perturbations provide suspicious proxies. A medication-multiset encoder and causal visit-sequence encoder feed a shared scoring head that produces visit-level anomaly logits. Top-α aggregation derives account-level scores from these logits, while account-level classification and class-balanced visit-localization objectives jointly optimize the same visit-level evidence. Experiments on two city cohorts compare L2G with native and proxy-adapted anomaly methods. On City-A, L2G outperforms the strongest comparators. Cross-city results show more consistent gains in localization than in account-level detection.
Figures & tables
Figure 1: Overview of the proposed knowledge-guided proxy anomaly construction and local-to-global anomaly learning framework. Knowledge-guided operators construct plausible and suspicious medication deviations at the medication-occurrence, treatment-episode, and contiguous-segment levels. The model learns visit-level anomaly evidence and selectively aggregates high-scoring visits through Top- α aggregation to obtain account-level anomaly logits. Account-level and visit-level objectives jointly supervise the same visit-level anomaly logits, coupling local anomaly localization with global account-level detection.
Component
K1: Sparse Replacement
K2: Semantic Episode Replacement
K3: Segment Injection
Perturbation granularity
Medication occurrence
Treatment episode
Contiguous visit segment
Replacement source
Drug KG-grounded medication candidate
Real treatment episode
Real segment from another account
Core constraints
Medication semantics
Treatment semantics and structural matching
Cross-account and segment constraints
Introduced deviation
Medication-level semantic variation
Treatment-process-level variation
Trajectory-level contextual inconsistency
Table 1: Overview of the three proxy perturbation mechanisms.
Method
K1 AP
K2 AP
K3 AP
Macro AP
Macro AUROC
Loc. Macro AP
Native anomaly methods
Deep SVDD-Native
0.5070
0.5130
0.5184
0.5128
0.5208
0.3462
NCAD-Native
0.5017
0.5523
0.5472
0.5338
0.5334
0.3501
AnomalyBERT-Native
0.5091
0.5839
0.5628
0.5519
0.5606
0.3745
TranAD-Native
0.4969
0.5231
0.5479
0.5226
0.5352
0.3528
CAT-Native
0.5000
0.5000
0.5000
0.5000
0.5000
0.3689
Table 2: Overall performance on the City-A test set. Macro metrics are unweighted averages across K1, K2, and K3. Best results are shown in bold and second-best results are underlined ; rankings are determined using unrounded scores. “–” indicates that a method does not provide a native visit-level anomaly score.
Figure 2: Effect of plausible-negative supervision on City-A. Bars show the metric difference between the full L2G-Joint model and the ablation trained without K1-Same and K2-Same. Plausible negatives consistently improve operator-specific and Macro AP, while producing negligible changes in Macro AUROC and Localization Macro AP.
Figure 3: Training-consistent sensitivity to the Top- α aggregation ratio on City-A. Each point corresponds to an independently trained L2G-Joint model using the same α during training, validation, and testing. The validation-selected α=0.20 is retained as the formal setting.
Aggregation
K1 AP
K2 AP
K3 AP
Macro AP
Macro AUROC
Loc. Macro AP
Mean
0.7997
0.7698
0.7486
0.7727
0.7588
0.7257
Max
0.8111
0.7765
0.7470
0.7782
0.7628
0.7304
Top-20%
0.7981
0.7882
0.7669
0.7844
0.7707
0.7215
Table 3: Training-consistent comparison of local-to-global aggregation mechanisms on the City-A test set. Best results are shown in bold.
Method
K1 AP
K2 AP
K3 AP
Macro AP
Macro AUROC
Loc. Macro AP
Native anomaly methods
Deep SVDD
0.5264
0.5321
0.5522
0.5369
0.5239
0.3207
NCAD-Native
0.5479
0.6080
0.6763
0.6107
0.5863
0.3692
AnomalyBERT-Native
0.5413
0.5558
0.5401
0.5457
0.5287
0.3931
TranAD-Native
0.5331
0.5296
0.5236
0.5288
0.5125
0.3203
CAT-Native
0.5098
0.5513
0.5132
0.5247
0.5049
0.3001
Table 4: Burden-controlled five-fold out-of-fold evaluation on City-B. All methods use the same outer folds and held-out proxy samples, with model configurations and training durations frozen from City-A. Metrics are first computed within each held-out fold and then aggregated for each operator using the number of matched account pairs as weights; raw scores from independently trained folds are not pooled. The evaluation contains 140, 43, and 121 held-out matched accounts for K1, K2, and K3, respectively. Best and second-best results are shown in bold and underlined, respectively.
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.
Appendix
Group
Method
Main characteristics
Native
Deep SVDD [ 17 ]
One-class normality modeling
NCAD [ 35 ]
Contextual anomaly detection with local temporal context
AnomalyBERT [ 36 ]
Self-supervised Transformer anomaly detection
TranAD [ 20 ]
Transformer-based reconstruction and anomaly scoring
CAT [ 25 ]
Content-aware event sequence anomaly detection
OC4Seq [ 24 ]
Multi-scale one-class discrete sequence modeling
Appendix
Table 5: Summary of baseline methods, original formulations, and adaptation strategies used in our experiments.