# Analytic Continual Learning-Based Non-Intrusive Load Monitoring Adaptive to Diverse New Appliances
## 3 Methodology
### Supervised Contrastive Learning-Based Pretraining Strategy  
The pretraining on the initial dataset \(D_{0}\) provides the foundation for continual learning and determines the upper bound of NILM performance on subsequent streaming data. The proposed pretraining strategy consists of two stages. First, the feature extraction module is trained jointly with the load identification branch. Then, the novelty detection branch is trained separately. This separation is necessary because the load identification branch learns to distinguish among original appliance types, while the novelty detection branch learns to treat them as a single group. This conflict has limited impact, as more discriminative features reduce the risk of confusing new appliances with original ones. In addition, the novelty branch includes one extra fully connected layer compared to the load identification branch, facilitating the transformation between the two kinds of feature spaces.  
In the pretraining stage, in addition to the cross-entropy loss in existing continual learning-based NILM methods, a SCL-based loss [25] is applied to the feature extraction module parameters \(W^{\text{en}}\), as shown below:  
\[\underset{W^{\text{en}}}{\text{min}}\underset{j\in I}{\sum}\frac{-1}{|L(j)|} \underset{l\in L(j)}{\sum}\log\frac{\exp(X_{j}^{\text{en}}\cdot X_{l}^{\text{en }}/\tau)}{\sum\limits_{a\in I\setminus\{j\}}\exp(X_{j}^{\text{en}}\cdot X_{q}^ {\text{en}}/\tau)} \tag{2}\]  
where \(I\) denotes the set of sample indexes in a training batch, \(L(j)\) is the set of indexes sharing the same appliance type as the \(j\)th sample (excluding \(j\) itself), and \(\tau\) is the temperature parameter used in the dot-product similarity calculation.  
Compared to the unsupervised contrast learning loss that is commonly used in NILM, which only improves inter-sample distinctiveness [19; 26], the SCL-based loss leverages label information to enhance inter-type separation and intra-type clustering, as shown in the middle part of Figure 1. This reduces the learning difficulty for both the novelty detection and load identification branches. To facilitate the SCL to better distinguish different types of features, the waveforms are augmented by adding random Gaussian noise \(I^{\text{g}}\) and random wandering noise \(I^{\text{r}}\)[27], doubling the training set. In particular, Gaussian noise simulates typical background noise, while random wandering noise models the variations in appliance waveforms. Both types are applied in equal proportion. For the first time, random walk noise is introduced as an augmentation method that is specifically adapted to NILM. This approach better reflects the electrical characteristics of appliances, enabling augmented samples to retain key distinctive features while more accurately representing the variations within the same appliance type. As shown in Figure 2, even with the same signal-to-noise ratio (SNR) of 5 dB, random walk noise preserves the flat peaks of air conditioner waveforms and the plateau in Halogen Fluter waveforms. These noise sequences are derived from unit noise \(I^{\text{g}}\) and \(I^{\text{r}}\), scaled according to the preset SNR and the signal power \(P^{\text{w}}\) of the appliance waveform, as shown in (3)-(5).  
\[I^{\text{g}}=\sqrt{P^{\text{n}}}\times I^{\text{g}\prime} \tag{3}\]  
\[I^{\text{r}}=\sqrt{P^{\text{n}}}\times I^{\text{r}\prime} \tag{4}\]  
\[P^{\text{n}}=\frac{P^{\text{w}}}{10^{\text{SNR}/10}} \tag{5}\]