{'fraction_non_alphanumeric': 0.026953748006379584, 'fraction_numerical': 0.005847953216374269, 'mean_word_length': 5.187828947368421, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Smart Metering System Capable of Anomaly Detection by Bi-directional LSTM Autoencoder

Anomaly detection is concerned with a wide range of applications such as fault detection, system monitoring, and event detection. Identifying anomalies from metering data obtained from smart metering system is a critical task to enhance reliability, stability, and efficiency of the power system. This paper presents an anomaly detection process to find outliers observed in the smart metering system. In the proposed approach, bi-directional long short-term memory (BiLSTM) based autoencoder is used and finds the anomalous data point. It calculates the reconstruction error through autoencoder with the non-anomalous data, and the outliers to be classified as anomalies are separated from the non-anomalous data by predefined threshold. Anomaly detection method based on the BiLSTM autoencoder is tested with the metering data corresponding to 4 types of energy sources electricity/water/heating/hot water collected from 985 households.

As shown in Fig. 1, the anomalies can be observed as the deviation of abnormal data from the normal ones. In case of sample data including outliers, there exist several characteristics such as large gaps between inlying and outlying observation data, and the deviation between the outliers and the inlier group measured on a standardized scale. For example, the energy consumption of buildings often exceeds the specific value representing energy savings due to anomaly even though Sangkeum  the energy model of the building is designed as a low-energy model [13]. To figure out these circumstances, anomaly detection is a helpful method to identify anomalous events. Moreover, analysis and detection of anomalies in power system are important as they have useful information on data generation process. The existing techniques for anomaly detection usually solve specific problems, utilizing various disciplines, such as deep learning techniques, statistical methods, and information theory. The setup for the use of deep learning techniques to execute the anomaly detection is fundamentally determined depending on the label applicable to the dataset and therefore it mainly consists of supervised learning, semi-supervised learning, and unsupervised learning. Supervised anomaly detection can be used if the dataset is composed of fully labeled dataset. The more abnormal samples exist in the dataset, the higher performance can be achieved. However, in industrial facilities where anomaly detection is applied, the class-imbalance problem arises as the occurrence rate of abnormal samples is less than that of normal samples. To resolve this issue, different techniques such as data augmentation, loss function design, and batch sampling can be used. In the case of semi-supervised anomaly detection, training data includes only normal data without any anomalies. This methodology is basically to set up a discriminative boundary containing normal samples and narrow it down while judging all samples outside the boundary as abnormal. Unsupervised anomaly detection scores the data focusing only on intrinsic characteristics of the dataset. Compared with supervised anomaly detection, unsupervised anomaly detection can be more useful when analyzing smart metering data in the real world, as labels are not provided for anomalies. Abnormal samples can be found by reducing and restoring dimensions using principal component analysis for given data. Among the neural network based methodologies, an autoencoder based methodology is mainly used, as it is a very powerful tool for high-level data representations. The autoencoder based methodology proceeds with encoding, which compresses the input into the latent variable, and decoding, which restores it close to the original dataset, allowing the autoencoder to learn only significant information in the data. Because the autoencoder does not have dedicated targets, it is trained in an unsupervised method to learn data presentations. In [14], successful anomaly detection of LSTM based autoencoder is presented. An autoencoder could successfully learn to reconstruct time-series data, and the reconstruction error is used to find anomalies. An autoencoder based ensemble method for anomaly detection is described in [15] with different architectures and training schemes. For assessing the performance of anomaly detection algorithms, an attention mechanism in combination with a GRU-based encoder-decoder mechanism is suggested in [16].
In this paper, a deep learning based anomaly detection method is presented to find specific patterns of anomaly in data streams of smart meters. Different studies have dealt with the anomaly detection by using deep learning techniques, considering different situations. However, few works [17,18] have attempted to get improved performance of anomaly detection. From this perspective, a bi-directional LSTM (BiLSTM) network is applied to autoencoder to get higher accuracy of anomaly detection in the smart metering system. More specifically, the BiLSTM autoencoder based approach is applied to smart metering data composed of 4 types of energy sources electricity/water/heating/hot water collected from 985 apartment households. The BiLSTM network consisting of two uni-directional LSTM networks, takes the input in two ways, one uni-directional LSTM network receiving temporal data from past to future and the other uni-directional LSTM network receiving temporal data from future to past. In this way, the BiLSTM autoencoder can extract the features of temporal data more efficiently, and therefore achieving improved anomaly detection.
The organization of this paper is as follows. In Section Ⅱ, the structure of the smart metering system is presented. Section Ⅲ presents the anomaly detection by using the BiLSTM autoencoder. Section Ⅳ describes simulation results of anomaly detection for smart metering data. In Section Ⅴ, concluding remarks are presented.

II. SMART METERING SYSTEM
A smart meter is a metering device that can measure and transmit real-time energy consumption information to utility providers, facilitating monitoring and control of power system. It is different from the traditional meter in that it can provide a wide range of advanced services, such as remote connection activation/deactivation and bi-directional communication between smart meters and utility providers. Also, the analysis of real-time power usage according to user's behavior can be achieved by smart meters. The overall structure of the smart metering system is made up of different components offering the intended services to the users. In Fig. 2, the overall structure of smart metering system is presented.
Data concentrator is a tool that is commonly found in substations and is used to manage the data collected from various smart meters in distant houses. The data concentrator primarily serves as store-and-forward link between the smart meter and the rest of the system, collecting data on energy expenditure at remote residences, transmitting the data to control centers, and providing the data to the billing system. Furthermore, data concentrators can uncover and organize freshly fitted smart meters, as well as create repeating chains, if necessary. Generally, data concentrators administer a part of infrastructure operations autonomously, such as continuously monitoring the electricity grid and smart meters, confirming failures and disruptions [19], and identifying and investigating theft and interfering attempts. Although data concentrator is unable to take incoming calls, it is capable of initiating and maintaining communication if the connection is lost. A central access server (CAS) is described as the central application which manages the information assortment, control, and parameterization, mentioned in NTA 8130. Also, it is used as the centralized authorization for accessing the metering system. Every grid operator keeps a group of servers as a component of the metering framework activity. These servers likewise have diverse programming and applications which are fundamental for the system activities. Also, these servers serve as online portals, allowing clients to access their profiles, for example, check their energy consumption trends. In addition, the metering dataset provided from the servers can be used as the input, and the output of the autoencoder for its training, as presented in Fig. 2. The independent service providers (ISPs) utilize the meter data to provide optional services offering the methods to save electricity usage through service modules. The energy suppliers are defined as commercial parties which generate or purchase electricity and sell it to customers. Grid operators typically use the information provided by the metering system, allocating electricity use. The smart metering system features numerous ports through which information can pass to facilitate communication between system components and market parties. The NTA 8130 standard specifies four ports: P1, P2, P3, and P4 (as shown in Fig. 2).
Port P1 is the read-only port to connect metering installation with external devices. Port P2 is linked to other local metering apparatus. It can be used for wired or wireless connection with electricity/water/heating/hot water meters. Port P3 is used for two-way communication with distribution system operator (DSO) to send information such as metering values, status, power quality, and outage measurements. Communication between port P3 and DSO is achieved via long-term evolution, code-division multiple access, or packet radio service. Also, it uses the international standard IEC 62056 as the communication protocol [20]. Port P4 is a gateway for ISPs, energy suppliers, and grid operators to acquire measurements from port P3. It provides a web service to access the CAS, which allows an energy supplier or ISP to get customers' metering data, regardless of the responsible DSO.
Various kinds of services can be offered to customers by using smart metering system, such as generating remotely readable meter data, facilitating energy savings for consumers, and monitoring distribution networks. Also, a two-way communication network is essential for the functionalities of smart metering system. The exchange of messages, which contain the information about the status of meter installation and operating environments, is carried out between grid operators, energy suppliers, service providers, and consumers. For example, energy suppliers and grid operators can display current state information on the metering installation via port P3.

III. ANOMALY DETECTION USING BILSTM AUTOENCODER
Power systems are being confronted with enormous information issues, and to deal with this huge volume of information, deep learning algorithms are the best arrangements [21]. In deep learning systems, different handling layers are considered and they may precisely extract the essential aspects of data with multiple levels of abstraction [22].
Recurrent neural network (RNN), long short-term memory (LSTM) network used for short-term prediction of power consumption [23] as an aid to replace multi-objective optimization of power consumption in [24], and gated recurrent unit (GRU) network applied for electricity trading [25] represent sorts of nonlinear predictor functions. Long-term dependencies are difficult for RNNs to learn, and the LSTM network is especially useful for time-series data. The LSTM network can accomplish better characterization of time-series data. The uni-directional LSTM approach produces certain errors in the results as they utilize one-way memory [26][27][28]. The BiLSTM approach is an extension of the traditional LSTM approach, which can improve the performance in the aspect of sequence classification by using the sequence information in both directions forward (past to future) and backward (future to past). The BiLSTM network has emerged as a better solution to deal with the interaction between contexts [29]. It was used to diagnose an asynchronous motor and found to be more efficient than the GRU network [30]. In issues where all timesteps of the information grouping are accessible, training the BiLSTM network represents training two uni-directional LSTM networks rather than one LSTM network on the input sequence. One LSTM network is trained by the input sequence and the other LSTM network is trained by a reversed copy of the input sequence. This can give the network more context and help it learn the problem faster and more thoroughly. As shown in Fig. 3, an LSTM cell has forget, input, and output gates for effective short and long term cell memory. In particular, the training of BiLSTM memory block has two ways, one LSTM from past to future and the other one from future to past, possessing data from both the past and the future at each time. Each layer calculates the following function for each element in the input order. Variables involving with an LSTM cell are represented as following is the hidden state of the layer at time ! 1 or the initial hidden state at time 0, and , , , represent the input, forget, cell, and output gate, respectively. is the sigmoid function, and ′ * ′ is the Hadamard product.
In most cases, the input data contains redundant or correlated characteristics, resulting in wasted processing time and model overfitting. An autoencoder comprises an encoder and a decoder. The encoder creates a compressed vector representation of the input data, which is then used by the decoder to create the target sequence. A pair of encoder and decoder is trained to reconstruct typical behavior, and then the reconstruction error is evaluated to detect anomalies. The input order is pierced successively in the LSTM autoencoder's structure, and after the last input sequence appears in the inputoutput sequence, the decoder restores the input sequence or outputs an estimated target sequence. In model learning, normal data is utilized instead of aberrant data, and the reconstruction error is measured by comparing the output with the input. The reconstruction error is obtained as follows where $ represents the reconstruction error, and ' are vectors of elements of 4 sorts of inputs and outputs of energy sources (electricity/water/heating/hot water), * +, denotes anomaly detection parameter at , is taken at every 15 minute interval, and 2 is a threshold value for reconstruction error, and "abnormal" represents anomaly. When data is provided to the model, the $ is utilized to determine whether it is normal or abnormal by comparing $ with threshold 2. If $ is less than the threshold, data is classified as normal, however, if $ is larger than threshold, data is classified as abnormal.
For the data preprocessing, data cleaning and examining, data denoising, and data normalization are employed for training the BiLSTM network. Classification and cleaning of 4 types of energy source data for each household, cleaning of tag values, and resampling at 15-minute intervals are carried out in data cleaning and sampling process. Data denoising with discrete wavelet transform (DWT) can also be utilized. The DWT method is used to effectively remove noise that is the cause of reduced performance of the trained BiLSTM network.

IV. SIMULATION RESULTS
In the smart metering system, data of electricity/water/heating/hot water are collected from 985 households. The training progress of the BiLSTM network is shown in Fig. 4 and its training parameters are as follows. The model is trained for 200 epochs with a specific batch size, using the Adam optimizer as a stochastic gradient descent. Also, the network is trained with a batch size of 128. The training loss is calculated by applying a mean squared error (MSE) as a loss function. To prevent inadequate learning such as local minimum and overfitting, dropout and gradient are applied.
Depending on the number of epochs, the decrease in both training loss and validation loss describes that BiLSTM autoencoder is well trained.  For the training of the BiLSTM autoencoder, 80% of data samples are used for training and the remaining 20% of data samples are used for validation. The receiver operating characteristic (ROC) curve is able to provide information on the overall performance of the classifier. As shown in Fig. 5, the BiLSTM autoencoder has larger area under curve (AUC) values than uni-directional LSTM autoencoder (represented by "LSTM" in the legend) with 4 types of energy sources electricity/water/heating/hot water. This demonstrates that the BiLSTM autoencoder achieves better performance in anomaly detection than the uni-directional LSTM autoencoder. Table 1 shows the accuracy, precision, recall, F1, and MSE defining the confusion matrix. Confusion matrix is composed of accuracy=(TP+TN)/(TP+FN+FP+TN), precision=TP/(TP+FP), recall=TP/(TP+FN), and F1=2*precision*recall/(precision+recall). The TP, TN, FP, and FN denote true positive, true negative, false positive and false negative in classification results.
As shown in Fig. 6, anomalies are detected in 4 types of energy sources with the BiLSTM autoencoder by calculating the reconstruction error between input and reconstructed input. The level of outliers for each data point is described by the anomaly score. A domain-specific threshold is chosen by a subject matter expert to identify the anomalies, and the data instances are sorted according to anomalous score. Dark blue dot, orange dot, and thin red line represent normal data, outlier, and threshold. When data points have higher reconstruction error than the threshold, they are classified as outlier (anomaly). On the contrary, when data points have less reconstruction error than the threshold, they are classified as normal data. There exist other outliers which are classified as normal data because of small reconstruction error similarly observed with normal data and some normal data classified as outliers due to the reconstruction error above the threshold.

V. CONCLUSION
In this paper, a novel method of anomaly detection for smart metering system is proposed. The dataset, which is composed of electricity, water, heating, and hot water and collected from 985 households, is used for simulations. To find anomalies among datasets measured by smart metering system, the BiLSTM autoencoder is utilized. To prove the comparative performance of the BiLSTM autoencoder in anomaly detection, ROC curve and AUC are calculated. As presented in Fig. 5, the BiLSTM autoencoder achieves better performance, as compared to the uni-directional LSTM autoencoder, for 4 types of energy sources due to the structure of the BiLSTM network making the input flow in forward and backward directions to preserve the past and the future information.