Improved Contrastive Predictive Coding for Time Series Out-Of-Distribution Detection Applied to Human Activity Data
Amirhossein Ahmadian, Fredrik Lindsten · Pattern Recognition Letters · 2025
Contrastive Predictive Coding (CPC) is a well-established self-supervised learning method that naturally fits time series data. This method has been recently leveraged to detect anomalous inputs, viewed as the task of classifying positive pairs of context-feature representations versus negative ones in order to employ classifier uncertainty measures. In this paper, by taking a different perspective, we propose a CPC-based Out-Of-Distribution (OOD) detection method for time series data that does not require any negative samples at test time and is theoretically related to a probabilistic type of uncertainty estimation in the latent representation space. Our method extends the standard CPC by using a radial (distance-based) score function both in the training loss and as the OOD measure, in addition to quantizing the context (replacing it by cluster prototypes) during inference. The proposed method is applied to detecting OOD human activities with smartphone sensors data and shows promising performance on two primary datasets without using activity labels in training. • We adapt Contrastive Predictive Coding to time series OOD/anomaly detection. • We propose to augment CPC with RBF kernel score and test-time context quantization. • We demonstrate advantages of RBF kernels over log-bilinear score in CPC OOD detection. • We apply our method to detecting OOD human activities via mobile sensors. • We connect the theory of our method to an invertible model interpretation of CPC.