U NSUPERVISED R EPRESENTATION L EARNING FOR T IME S ERIES WITH T EMPORAL N EIGHBORHOOD C OD -
ING
Anonymous authors
Paper under double-blind review
A BSTRACT
Time series are often complex and rich in information, but sparsely labeled and therefore challenging to model.
In this paper, we propose a self-supervised framework for learning robust and generalizable representations for time series.
Our approach, called Temporal Neighborhood Coding (TNC), takes advantage of the local smoothness of a signal’s generative process to deﬁne neighborhoods in time with stationary properties.
Using a debiased contrastive objective, our framework learns time series representations by ensuring that in the encoding space, the distribution of signals from within a neighborhood is distinguishable from the distribution of non-neighboring signals.
Our motivation stems from the medical ﬁeld, where the ability to model the dynamic nature of time series data is especially valuable for identifying, tracking, and predicting the underlying patients’ latent states in settings where labeling data is practically impossible.
We compare our method to recently developed unsupervised representation learning approaches and demonstrate superior performance on clustering and classiﬁcation tasks for multiple datasets.
I NTRODUCTION
Real world time-series data is high dimensional, complex, and has unique properties that bring about many challenges for data modeling (Yang & Wu, 2006).
In addition, these signals are often sparsely labeled which makes it even more challenging for supervised learning tasks.
Unsupervised representation learning can extract informative low-dimensional representations from raw time series by leveraging the inherent structure of the data, without the need for explicit supervision.
These representations are more generalizable and robust to variance in time, as they are less specialized for solving a single supervised task.
Unsupervised representation learning is well studied in domains such as vision (Donahue & Simonyan, 2019; Denton et al., 2017;
Radford et al., 2015) and natural language processing (Radford et al., 2017; Young et al., 2018; Mikolov et al., 2013), but has been underexplored in the literature for time series settings.
Frameworks designed for time series need to be efﬁcient and scalable, given that signals encountered in practice can be long, high dimensional and even high frequency.
Moreover, it should account for and be able to model dynamic changes that occur within samples, i.e. non-stationarity of signals.
The ability to model the dynamic nature of time series data is especially valuable in medicine.
Health care data is often organized as a time series, with multiple data types, collected from a variety of sources at different sampling frequencies, and riddled with artefacts and missing values.
Patients, throughout their stay at the hospital or within the disease progression period, transition gradually between distinct clinical states.
A particular challenge in medical time-series data is the lack of well-deﬁned or available labels that are needed for identifying the underlying clinical state or for training models aimed at extracting low-dimensional representations of these states.
For instance, in the context of critical-care, a patient’s stay in the critical care unit (CCU) is captured continuously via streaming physiological signals by the bedside monitor.
Obtaining labels for the patient’s state for extended periods of these signals is practically impossible as the underlying physiological state can be unknown even to the clinicians.
This further motivates the use of unsupervised representation learning in these contexts.
Learning low dimensional, rich, and robust unsupervised representations can be crucial in facilitating the tracking of disease progression, predicting the future trajectories of the patients, and tailoring treatments to these underlying states.
In this paper, we propose a self-supervised framework for learning representations for complex multivariate non-stationary time series.
This approach, called Temporal Neighborhood Coding (TNC), is designed for temporal settings where the latent distribution of the signals changes over time, and it aims to capture the progression of the underlying temporal dynamics.
TNC is efﬁcient, easily scalable to high dimensions, and can be used in different time series settings.
We assess the quality of the learned representations on multiple datasets and show that the representations are general and transferable to a number of downstream tasks such as classiﬁcation and clustering.
We further demonstrate that our method outperforms existing approaches for unsupervised representation learning, and it even performs closely to supervised techniques in classiﬁcation tasks.
Our contributions are three-fold:
We present a novel neighborhood-based unsupervised learning framework for non-stationary multivariate time series data.
We introduce the concept of a temporal neighborhood as the distribution of similar windows in time.
The neighborhood boundaries are determined automatically using the properties of the signal and statistical testing.
We incorporate concepts from Positive Unlabeled Learning, speciﬁcally, sample weight adjustment, to account for potential bias introduced in sampling negative examples for contrastive loss.
M ETHOD
We introduce a framework for learning low dimensional representations that encode the underlying state of a multivariate, non-stationary time series.
Our self-supervised approach, TNC, takes advantage of the local smoothness of the generative process of signals to learn generalizable representations for windows of time series.
This is done by ensuring that in the representation space, the distribution of signals proximal in time is distinguishable from the distribution of signals far away, i.e. proximity in time is identiﬁable in the encoding space.
We represent our multivariate time series signals as
X ∈ R D × T , where D is the number of features and T is the number of measurements in time.
[Equation]
represents a window of time series of length δ , centered around time t , that includes measurements of all features taken in the interval [ t − δ 2 , t + δ 2 ] .
Throughout the paper, we refer to this window as W t for notational simplicity.
We deﬁne the temporal neighborhood ( N t ) of a window W t as the set of all windows with centroids t ∗ , sampled from a normal distribution t ∗ ∼ N ( t, η · δ ) .
Where N is centered at t , δ is the size of the window, and η is the parameter that deﬁnes the range of the neighborhood.
The neighborhood distribution is characterized as a Gaussian to model the gradual transition in temporal data, and intuitively, approximates the distribution of samples that are similar to W t .
The η parameter determines the neighborhood range, and depends on the signal characteristics and how gradual the statistical properties of the time series change over time.
This can be set by domain experts based on prior knowledge of the signal behavior, or for a more robust estimation, it can be determined by analysing the stationarity properties of the signal, for every W t .
Since the neighborhood represents similar samples, the range should identify the approximate time span within which the signal remains stationary and the generative process does not change.
For this purpose, we use the Augmented
Dickey Fuller (ADF) statistical test to determine this region.
Proper estimation of the neighborhood range is an integral part of the TNC framework.
If η is too small, many samples from within a neighborhood would overlap, and therefor the encoder would only learn to encode the overlapping information.
On the other hand, if η is too big, the neighborhood would span over multiple underlying states and therefore the encoder would fail to distinguish such variations.
The ADF test allows us to adjust the neighborhood for every window, based on the signal behavior.
More details on this test and how it can be used to estimate η is described in section 2.
Now, assuming windows within a neighborhood possess similar properties, signals outside of this neighborhood, denoted as ¯ N t , are considered non-neighboring windows.
Samples from ¯ N t are likely to be different from W t , and can be considered as negative samples in a context of a contrastive learning framework.
However, this can suffer from the problem of sampling bias , common in most contrastive approaches (Chuang et al., 2020; Arora et al., 2019).
Drawing negative examples from the data distribution may result in negative samples that are actually similar to the reference, which is W t in our context.
This can signiﬁcantly impact the performance of the learning framework, but limited work has been done on addressing this issue (Chuang et al., 2020).
To alleviate this bias in the TNC framework, we consider samples from ¯ N t as unlabeled samples, as opposed to negative, and use ideas from Positive-Unlabeled (PU) learning to accurately measure the loss function.
In reality, even though samples within a neighborhood are all similar, we cannot make the assumption that samples outside this region are necessarily different.
For instance, in the presence of long term seasonalities, signals can exhibit similar properties at distant times.
In a healthcare context, this can be like a stable patient that undergoes a critical condition, but returns back to a stable state afterwards.
In PU learning, a classiﬁer is learned using labeled data (drawn from the positive class) and unlabeled data that is a mixture of positive and negative samples with a positive class prior π (Du Plessis et al., 2014;
Kiryo et al., 2017; Du Plessis & Sugiyama, 2014).
Existing PU methods fall under two categories based on how they handle the unlabeled data: 1) methods that identify negative samples from the unlabeled cohort (Li & Liu, 2003); 2) methods that treat the unlabeled data as negative samples with smaller weights (Lee & Liu, 2003; Elkan & Noto, 2008).
In the second category, unlabeled samples should be properly weighted in the loss term in order to train an unbiased classiﬁer.
Elkan & Noto (2008) introduces a simple and efﬁcient way of approximating the expectation of a loss function by assigning individual weights w to training examples from the unlabeled cohort.
This means each sample from the neighborhood is treated as a positive example with unit weight, while each sample from ¯ N is treated as a combination of a positive example with weight w and a negative example with complementary weight 1 − w .
In the original paper (Elkan & Noto, 2008), the weight is deﬁned as the probability of having a positive sample in the unlabeled set, i.e. w = p ( y = 1 | x ∈ U ) .
In the
TNC framework, this weight represents the probability of having samples similar to W t in ¯ N .
By incorporating weight adjustment into the TNC loss (Equation 1), we account for possible positive samples that occur in the non-neighboring distribution.
w can be approximated using heuristics or prior knowledge of the underlying state distribution, or tuned as a hyper parameter.
Appendix A. explains how the weight parameter is selected for our different experiments, and also demonstrates how adding this weight adjustment improves the performance for downstream tasks.
After deﬁning the neighborhood distribution, we train an objective function that encourages distinction between the representation of samples of the same neighborhood from the outside samples.
An ideal encoder, preserves the neighborhood properties in the encoding space, therefore representations Z l =
Enc ( W l ) of samples from a neighborhood W l ∈ N t , can be distinguished from representation Z k =
Enc ( W k ) of samples from outside the neighborhood W k ∈ ¯ N t .
TNC has two main components:
An Encoder Enc ( W t ) that maps a window W t ∈ R D × δ to a representation Z t ∈ R M , in a lower dimensional space ( M (cid:28) D × δ ), where D × δ is the total measurements in W t .
A Discriminator D ( Z t , Z ) that approximates the probability of Z being the representation of a window in N t .
More speciﬁcally, it receives two samples from the encoding space and predicts the probability of those samples being in the same temporal neighborhood.
However, TNC is a general framework, agnostic to the nature of the time series and the encoder architecture.
Therefore, the encoder can be modeled with any parametric model well-suited to the signal properties (Oord et al., 2016; Bai et al., 2018;
Fawaz et al., 2019).
The Discriminator D ( Z t , Z ) is a simple multi-headed binary classiﬁer that outputs 1 if Z and Z t are representation of neighbors in time, and 0 otherwise.
In the experiment section we describe the architectural details of the models used for our experiments in more depth.
Figure 1 provides a summary overview of the TNC framework.
We formalize the objective function of our unsupervised learning framework in Equation 1.
In essence, we would like the probability likelihood estimation of the Discriminator to be accurate, i.e. close to 1 for representation of neighboring samples, and close to 0 for windows far apart.
Samples from the non-neighboring region ( ¯ N ) are weight-adjusted using the w parameters, to account for positive samples in this distribution.
[Equation]
[Figure]
D a t a
[Figure]
We train the encoder and the discriminator hand in hand by optimizing for this objective.
Note that the
Discriminator is only part of training, and will not be used during inference.
Similar to the encoder, it can be approximated using any parametric model.
However, the more complex the discriminator, the harder it becomes to interpret the latent space, since it allows similarities to be mapped on nonlinear complex relationships.
Deﬁning the neighborhood parameters using the ADF test: As mentioned earlier, the neighborhood range can be speciﬁed using the characteristics of the data.
In non-stationary time series, the generative process of the signals changes over time, but we would like to deﬁne the temporal neighborhood such that the signal is stationary within it.
A signal may remain in an underlying state for an unknown amount of time, therefore the neighborhood range may vary in size and must be adjusted to signal behavior at every point.
To that end, we use the Augmented Dickey Fuller (ADF) statistical test to adjust the neighborhood range η .
The ADF test belongs to a category of tests called "Unit Root Test", and is a method for testing the stationarity of a time series.
For every W t , we want to ﬁnd the neighborhood range around that window that indicates a stationary region.
For that purpose, we gradually increase the neighborhood size η and measure the p -value from the test.
Once p -value is above a threshold (in our setting 0 . 01 ), it means that it fails to reject the null hypothesis and suggest that within this neighborhood regions, the signal is no longer stationary.
This way we ﬁnd the widest neighborhood within which the signal remains relatively stationary.
Note that the window size δ is constant throughout the experiment and during ADF testing, we only change the width of the neighborhood.
E XPERIMENTS
We evaluate the usability of our framework on multiple time series datasets with dynamic latent states that change over time.
We compare classiﬁcation performance and clusterability against two state-of-the-art approaches for unsupervised representation learning for time series: 1.
Contrastive
Predictive Coding (CPC)
(Oord et al., 2018) that uses principles of predictive coding to train the encoder on a probabilistic contrastive loss.
Triplet-Loss (T-Loss), introduced in (Franceschi et al., 2019), which employs time-based negative sampling and a triplet loss to learn representations for time series windows.
The triplet loss objective ensures similar time series have similar representations by minimizing the pairwise distance between positive samples (subseries) while maximizing it for negative ones.
(See Appendix A.2 for more details on each baseline and its implementation.)
For a fair comparison and to ensure that the difference in performance is not due to the differences in the architecture of the models, the same encoder network is used across all compared baselines.
Our objective is to compare the performance of the learning frameworks, agnostic to the choice of the encoder.
Therefore, we selected simple architectures to evaluate how each framework can use the limited capacity of a simple encoder to learn meaningful representations.
We assess the generalizability of the representations by: 1) evaluating clusterability in the encoding space and 2) using the representations for a downstream classiﬁcation task.
In addition to the above mentioned baselines, we also compare clusterability performance with unsupervised K-means, and classiﬁcation with a K-Nearest Neighbor classiﬁer, using Dynamic Time Warping (DTW) to measure time series distance.
All models are implemented using Pytorch 1 . 3 . 1 and trained on a machine with Quadro 400 GPU.
Below we describe each dataset in more details.
3. S IMULATED DATA
The simulated dataset is designed to replicate very long, high-frequency time series for which underlying dynamics changes over time.
Our generated time series consists of 2000 measurements for 3 features, generated from 4 different underlying states.
We use a hidden Markov Model to generate the random latent states over time, and in each state, the time series are generated from a different generative process, including Gaussian Processes (GPs) with different kernel functions and Nonlinear Auto-regressive Moving Average models with different sets of parameters ( α and β ).
In addition, for it to further resemble realistic (e.g. clinical) time series, two features are always correlated.
More details about this dataset is provided in the Appendix A.1.
For this experimental setup, we use a two-directional, single-layer recurrent neural network encoder that encodes multidimensional signal windows of δ = 50 into 10 dimensional representation vectors.
Overall, the window size should be selected such that it is long enough to contain information about the underlying state, and not too long to span over multiple underlying states.
More discussion on the choice of the window size is presented in Appendix A.4.
3. C LINICAL WAVEFORM DATA
For a real-world clinical experiment, we use the MIT-BIH Atrial Fibrillation dataset Moody (1983).
This dataset includes 25 long-term ECG recordings ( 10 hours in duration) of human subjects with atrial ﬁbrillation.
It consists of two ECG signals each sampled at 250 Hz with rhythm annotations of types: 1) Atrial ﬁbrillation, 2) Atrial ﬂutter, 3)
AV junctional rhythm, and 4) all other rhythms.
Our goal in this experiment is to identify the underlying type of arrhythmia over time, for each sample without any information about the annotations.
This dataset is an interesting experiment due to the following special properties:
• The underlying heart rhythm changes over time in each sample.
This is an opportunity to evaluate how different representation learning frameworks can handle alternating classes; • The dataset is highly imbalanced, with atrial ﬂutter and AV junctional rhythm being present in fewer than 0 .
1% of the measurements.
Data imbalance poses many challenges for downstream classiﬁcation, further motivating the use of unsupervised representation learning; • The dataset has samples from a small number of individuals, but over an extended period of time (around 5 million data points).
This realistic scenario, common in healthcare data, shows that our framework can even be used in settings with a limited number of samples.
A simple RNN encoder, used for other experiment setups is not able to model the high-frequency ECG measurements.
Therefore, inspired by state-of-the-art architectures for ECG classiﬁcation problems, the encoder Enc used in this experiment is a 2-channel, 1-dimensional strided convolutional neural network that runs directly on the ECG waveforms.
We use six convolutional layers with a total down-sampling factor of 16.
The window size is 2500 samples, meaning that each convolutional ﬁlter covers at least half a second of ECG recording, and the representations are summarized in a 64-dimensional vector.
3. H UMAN A CTIVITY R ECOGNITION (HAR) DATA
Human Activity Recognition (HAR) is the problem of predicting the type of an activity using temporal data from accelerometer and gyroscope measurements.
We use the HAR dataset from the
UCI Machine Learning Repository 1 that includes data collected from 30 individuals, using a smart recognition using watch.
Each person performs six activities: 1) walking, 2) walking upstairs, 3) walking downstairs, 4) sitting, 5) standing, and 6) laying.
The time series measurements are pre-processed to extractfeatures.
For our purpose, we concatenate the activity samples from every individual over time using the subject identiﬁer, in order to build the full time series for each subject, that includes continuous activity change.
Similar to the simulated data setting, we use a single-layer RNN encoder.
The selected window size is 4 , which represents about 15 seconds of recording, and the representations are encoded in a 10 -dimensional vector space.
R ESULTS
In this section we present performance results for clusterability and classiﬁcation on all datasets.
Clusterability indicates how well each method recovers appropriate states, and classiﬁcation assesses how informative our representations are for downstream tasks.
4. E VALUATION : C LUSTERABILITY
Many real-world time series data have underlying multi-category structure, naturally leading to representations with clustering properties.
Encoding such general priors is a property of a good representation (Bengio et al., 2013).
In this section, we assess the distribution of the representations in the encoding space.
If information of the latent state is properly learned and encoded by the framework, the representations of signals from the same underlying state should cluster together.
Figures 2a, 2b, and 2c show an example of this distribution for simulated data across compared approaches.
Each plot is a 2 dimensional t-SNE visualization of representations where each point in the scatter plot is an encoding Z ∈ R 10 that represents a window of δ = 50 of a simulated time series.
We can see that without any information about the hidden states, representations learned using TNC cluster windows from the same hidden state better than the alternatives.
Results show that CPC and
Triplet Loss have difﬁculty separating time series generated from non–linear auto-regressive moving average (NARMA) models with variable regression parameters.
[Figure]
To compare the consistency of the representation clusters formed for each baseline we use two very common cluster validity indices, namely, Silhouette score and Davies-Bouldin index.
We use
K-means clustering in the representation space to measure these clusterability scores.
The Silhouette score measures the similarity of each sample to its own cluster, compared to other clusters.
The values can range from − 1 to +1 , and a greater score implies better cohesion.
The Davies-Bouldin
Index measures intra-cluster similarity and inter-cluster differences.
This is a positive index score, where smaller values indicate low within-cluster scatter and large separation between clusters, i.e. a lower score is better (more details on the cluster validity scores can be found in Appendix A.5).
Table 1 summarizes the scores for all baselines and across all datasets, demonstrating that TNC is superior in learning representations that can distinguish the latent dynamics of time series.
CPC performs closely to T-loss on waveform data, but performs poorly on the simulated dataset, where signals are highly non-stationary and transitions are less predictable.
For the HAR dataset however,
[Table]
CPC clusters states very well, because most activities are recorded in a speciﬁc order, empowering predictive coding.
T-loss performs reasonably well in simulated setting, however it fails to distinguish states 0 and 2 , where signals come from autoregressive models with different parameters and thus have a rather similar generative process.
Performing K-means on the original time series does not generate coherent clusters, as demonstrated by the scores.
The performance is slightly better in time series like the ECG waveforms, where the signals are formed by consistent shapelets, therefore the
DTW measures similarity more accurately.
4. E VALUATION : C LASSIFICATION
We further evaluate the quality of the encodings using a classiﬁcation task.
We train a linear classiﬁer to evaluate how well the representations can be used to classify hidden states.
Performance is compared to a supervised classiﬁer, composed of an encoder and a classiﬁer with identical architectures to that of the unsupervised models, as well as a K-nearest neighbor classiﬁer using DTW metric.
Performance is reported as the prediction accuracy as well as the area under the precisionrecall curve (AUPRC) score, since AUPRC is a more accurate reﬂection of model performance for imbalance classiﬁcation settings like the waveform dataset.
[Table]
Table 2 demonstrates the classiﬁcation performance for all datasets.
The performance of classiﬁers that use TNC representations is closer to the end-to-end supervised model, in comparison to CPC and
Triplet Loss.
This provides further evidence that our encodings capture informative parts of the time series.
In datasets like the HAR, where an inherent ordering usually exists, CPC performs reasonably.
However, in datasets with increased non-stationarity, the performance drops.
Triplet-loss is also a powerful framework, but since it samples positive examples from overlapping windows of time series, it is vulnerable to only mapping the overlaps into the encoding and therefore failing to learn more general representations.
TNC on the other hand, samples similar windows from a wider distribution, deﬁned by the temporal neighborhood, where many of the neighboring signals do not necessarily overlap.
Lower performance of CPC and Triplet-Loss can also be partly due to the fact that none of these methods explicitly account for the potential sampling bias that happens when randomly selected negative examples are similar to the reference W t .
4. E VALUATION : T RAJECTORY
In this section we investigate the trajectories of our learnt encodings over time, to understand how the state transition is modeled in the representation space.
Figure 3 shows a sample from the simulated
[Figure]
dataset over time.
The top shows the signal measurements and the the underlying latent states.
The bottom panel illustrates the 10 -dimensional representation of a sliding window W t estimated over time.
From the bottom panel of Figure 3, we can see that the encoding pattern changes at state transitions and settle into a different pattern, corresponding to the new state.
This happens at every transition, and we can see the distinct patterns for all 4 underlying states in the representations.
This analysis of the trajectory of change could be very informative for the post analysis by the users; for instance in clinical applications, it could help clinicians visualize the evolution of the patient state over time and plan treatment based on the state progression.
R ELATED WORK
While integral for many applications, unsupervised representation learning has been far less studied in the time series (Längkvist et al., 2014), compared to other domains such as vision or natural language processing (Denton et al., 2017; Radford et al., 2015; Gutmann & Hyvärinen, 2012; Wang & Gupta, 2015).
One of the earliest approaches to unsupervised end-to-end representation learning in time series is the use of auto-encoders (Choi et al., 2016a; Amiriparian et al., 2017; Malhotra et al., 2017) and seq-to-seq models (Lyu et al., 2018), with the objective to train an encoder jointly with a decoder that reconstructs the input signal from its learned representation.
Using fully generative models like variational auto-encoders is also useful for imposing properties like disentanglement, that help with the interpretability of the representations (Dezfouli et al., 2019).
However, in many cases, like for high-frequency physiological signals, the reconstruction of complex time series can be challenging; therefore, more novel approaches are designed to avoid this step.
Contrastive Predictive
Coding (Oord et al., 2018; Löwe et al., 2019) learns representations by predicting the future in latent space, eliminating the need to reconstruct the full input.
The representations are such that the mutual information between the original signal and the concept vector is maximally preserve using a lower bound approximation and a contrastive loss.
Very similarly, in Time Contrastive Learning (Hyvarinen & Morioka, 2016), a contrastive loss is used to predict the segment-ID of multivariate time-series as a way to extract representation.
Franceschi et al.
(2019) employs time-based negative sampling and a triplet loss to learn scalable representations for multivariate time series.
Some approaches use inherent similarities in temporal data to learn representations without supervision.
For instance, in similarity-preserving representation learning (Lei et al., 2017), learned encodings are constrained to preserve the pairwise similarities that exist in the time domain, measured by DTW distance.
Another group of approaches combines reconstruction loss with clustering objectives in order to cluster similar temporal patterns in the encoding space (Ma et al., 2019; Madiraju et al., 2018).
In healthcare, learning representation of rich temporal medical data is extremely important for understanding patients’ underlying health conditions.
However, most of the existing approaches for learning representations are designed for speciﬁc downstream tasks and require labeling by experts (Choi et al., 2016b;c).
Some examples of similar works to representation learning in the ﬁeld of clinical ML include computational phenotyping for discovering subgroups of patients with similar underlying disease mechanisms from temporal clinical data (Lasko et al., 2013; Suresh et al., 2018;
Schulam et al., 2015).
Also, disease progression modeling, for learning the hidden vector of comorbidities representing a disease over time (Wang et al., 2014; Alaa & van der Schaar, 2018).
C ONCLUSION
In this paper we present a novel unsupervised representation learning framework for complex multivariate time series, called Temporal Neighborhood Coding (TNC).
This framework is designed to learn the underlying dynamics of non-stationary signals and to model the progression over time, by deﬁning a temporal neighborhood.
The problem is motivated from the medical ﬁeld where patients transition between distinct clinical states over time, and obtaining labels to deﬁne these underlying states is challenging.
We evaluate the performance of TNC on multiple datasets and show that our representations are generalizable and can easily be used for diverse tasks such as classiﬁcation and clustering.
We ﬁnally note that TNC is ﬂexible to be used with arbitrary encoder architectures, therefore the framework is applicable to many time series data domains.
Moreover, in addition to tasks presented in this paper, general representations can be used for a number of other downstream task such as anomaly detection, which is challenging in supervised learning settings for time series data in sparsely labeled contexts.
A. B ASELINE IMPLEMENTATION DETAILS
Implementation of all baselines are included in the code base for reproducability purposes, and hyper-parameters for all baselines are tuned using cross-validation.
Contrastive Predictive Coding (CPC): The CPC baseline ﬁrst processes the sequential signal windows using a encoder Z t =
Enc ( X t ) , with a similar architecture to the encoders of other baselines.
Next, an autoregressive model g ar aggregates all the information in Z ≤ t and summarizes it into a context latent representation c t = g ar ( Z ≤ t ) .
In our implementation we have used a single layer, one-directional recurrent neural network with GRU cell and hidden size equal to the encoding size as the auto-regressor.
Similar to the original paper, the density ratio is estimated using a linear transformation and the model is trained for 1 step ahead prediction.
Triplet-Loss (T-Loss): The triplet loss baseline is implemented using the original code made available by the authors on Github 2 .
KNN and K-means: These two baselines for classiﬁcation and clustering are implemented using the tslearn library 3 , that integrates distance metrics such as DTW.
Note, evaluating DTW is computationaly expensive and the tslearn implementation is not optimized, therefore for the waveform data with windows of size 2500, we had to down-sampled the signal frequency by a factor of 2.
A. TNC IMPLEMENTATION EXTRA DETAILS
In order to deﬁne the nighborhood range in the TNC framework, as mentioned earlier, we use the
Augmented-Dickey Fuller (ADF) statistical test, to determine this range ( η ) as the region for which the signals remains stationary.
More precisely, we gradually increase the range, from a single window size up to 3 times the window size (our upper limit), and repeatedly perform the ADF test.
We use the p -value from this statistical test to determine whether the Null hypothesis can be rejected, meaning that the signal is stationary.
At the point where the p -value is above our deﬁned threshold ( 0 . 01 ), we can no longer assume that the signal is stationary and this is where we set the η parameter.
Now, once the Neighborhood is deﬁned, we make sure the non-nieghboring samples are taken from the distribution of windows with at least 4 × η away from W t , ensuring low likelihood of belonging to the neighborhood.
Note that for implementation of ADF, we use the stats model library 4 .
Unfortunately, this implementation is not optimized and doesn’t support GPU implementation, therefore evaluating the neighborhood range using ADF slows down the training of TNC framework.
As a future direction, we would like to work on a more efﬁcient implementation of the ADF score for our framework.
A. S ELECTING THE WINDOW SIZE
The window size δ is an important factor in representation learning, not only for the TNC framework, but also for similar baselines such as CPC and triplet loss.
Overall, the window size should be selected such that it is long enough to contain information about the underlying state, and not too long to span over multiple underlying states.
In our settings, we have selected the window sizes based on our prior knowledge of the signals.
For instance in the case of an ECG signal, the selected window size is equivalent to 7 seconds of recording, which is small enough such that the ECG remains in a stable state, and yet has enough information to determine that underlying state.
Our understanding of the time series data can help us select an appropriate window size, but we can also experiment with different δ to learn this parameter.
Table 4 shows classiﬁcation performance results for the simulation setups, under different window sizes.
We can clearly see the drop in performance for all baseline methods when the window size is too small or too large.
A. C LUSTERING METRICS
Most cluster validity measures assess certain structural properties of a clustering result.
In our evaluation we have used 2 measures, namely the Silhouette score and Davies-Bouldin index, to
[Table]
evaluate the clustering quality of the representations.
Davies-Bouldin measures intra-cluster similarity (coherence) and inter-cluster differences (separation).
Let C
=
{C 1 , ..., C k } be a clustering of a set D of objects.
Davies-Bouldin score can is evaluated as follows:
[Equation]
where s ( C ) measures the scatter within a cluster, and δ is a cluster to cluster distance measure.
The silhouette score on the other hand, measures how similar an object is to its own cluster compared to other clusters.
Both measures are commonly used for evaluation of clustering algorithm.
A comparison of 2 metric has shown that in some cases, Silhouette index produces slightly more accurate results, however, Davies-Bouldin index is much less complex in terms of computation
Petrovic (2006).
A. S ETTING THE WEIGHTS FOR PU LEARNING
As mentioned in the Experiment section, in order to determine the weight parameter for debiasing the loss, we evaluate TNC loss for different weights.
Table 5 shows these values for the different experiment settings.
The loss column reports the value measured in Equation 1, and the accuracy shows how well the discriminator identiﬁes the neighboring samples from non-neighboring ones.
We pick the optimal weight for each setting, as the one that minimized TNC objective loss.
[Table]
In addition, in order to assess the impact of re-weighting the loss on downstream classiﬁcation performance, we compared these performance measures for weighted and non-weighted settings.
Table 6 demonstrates these results and conﬁrms that weight adjusting the loss for non-neighboring samples, improves the quality of learnt representations.
[Table]
A.
S UPPLEMENTARY F IGURE
A.7.
HAR DATA
[Figure] [Figure]
A.7. C LINICAL WAVEFORM DATA
In order to understand what TNC framework learns from the high dimensional ECG signals, we visualize the trajectory of the representations of an individual sample over time.
Figure A.5 demonstrates this example, where the top 2 rows are ECG signals from two recording leads and the bottom row demonstrates the representation vectors.
We see that around second 40 the pattern in the representations change as a result of an artifact happening in one of the signals.
Also, with the help of our clinical expert, we tried to interpret different patterns in the encoding space.
For instance, between time 80 and 130 , where features 0-10 become more activated, the heart rate (HR) increases has increased.
Increase in HR can be seen as increased frequency in the ECG signals and is one of the indicators of arrhythmia that we believe TNC.
A.7. S IMULATION DATA
In addition to the initial experiment, we also show the trajectory of the encoding for a smaller encoding size ( 3 ).
In this setting, we have 4 underlying states in the signal, and only 3 dimensions for the encoding.
[Figure]
[Figure] [Figure]