{'fraction_non_alphanumeric': 0.0336415877002702, 'fraction_numerical': 0.00936179929215664, 'mean_word_length': 4.573276776246023, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Virtual Battery Parameter Identification using Transfer Learning based Stacked Autoencoder

Recent studies have shown that the aggregated dynamic flexibility of an ensemble of thermostatic loads can be modeled in the form of a virtual battery. The existing methods for computing the virtual battery parameters require the knowledge of the first-principle models and parameter values of the loads in the ensemble. In real-world applications, however, it is likely that the only available information are end-use measurements such as power consumption, room temperature, device on/off status, etc., while very little about the individual load models and parameters are known. We propose a transfer learning based deep network framework for calculating virtual battery state of a given ensemble of flexible thermostatic loads, from the available end-use measurements. This proposed framework extracts first order virtual battery model parameters for the given ensemble. We illustrate the effectiveness of this novel framework on different ensembles of ACs and WHs.


Introduction
In recent years, deep learning has been gaining popularity among researchers due to its inherent nature of imitating human brain learning process. Specifically, several research works show the applicability of deep learning in capturing representative information from raw dataset using multiple nonlinear transformations as shown in [12]. Deep learning based methods can model high level abstractions in data utilizing multiple processing layers, compared to shallow learning methods. In [3], deep learning methods are used for simplifying a learning task from input examples. Based on scientific knowledge in the area of biology, cognitive humanoid autonomous methods with deep-learning-architecture have been proposed and applied over the years [4,11,19,28,30]. Deep learning replaces handcrafted feature extraction by learning unsupervised features as shown in [27]. However, although there exists great potential, application of these deep network based frameworks are relatively sparse in power system applications.
The last few years have seen a significant increase in integration of renewables into the electricity grid, and the intermittent nature of renewables causes uncertainty in power generation. Moreover, there is increased visibility into the operations of thermostatically controllable loads (TCLs) such as air conditioners (ACs) and electric water heaters (WHs) due to advancements in power electronics, communication capabilities that enable remote monitoring/controlling of TCLs. With increased renewable penetration, these advancements allow TCLs to provide grid ancillary services in the form of demand response, such as frequency regulation [2,6,9,16,17,21,22,29]. The thermostatic loads such as ACs and electric WHs can be characterized as 'energy-driven' loads, because end-use quality of service is reliant on the energy consumption over a duration. Availability of these loads to address demand response is strongly influenced by their dynamics. While modeling and coordinating each load individually in a power systems network is intractable for a grid operator, a reduced-order model to characterize the dynamic flexibility of an ensemble of loads is more amenable to be integrated into grid operation and planning tools. To this effect, recent studies have proposed the 'virtual battery' (or, 'generalized battery') models for an ensemble of flexible thermostatic loads.
Most recent works on virtual battery (VB) model identification can be seen in [9,10,15,20]. These works include characterizing a VB model for a wide range of systems from small residential TCLs to complex systems such as commercial building heating, ventilating, and air-conditioning loads. Similar to a real battery, the VB also has self-dissipation, energy capacity, and power (charge/discharge) limits as parameters. Existing state of the art methods on identification of VB parameters for an ensemble of thermostatic loads can be either via closed-form (albeit, ad-hoc) expressions or via optimization-based techniques. Both of these require the knowledge of the individual load models and parameters. In real-world applications, however, it is expected that very little about the individual load models and parameters are known. The only available information are the end-use measurements such as power consumption, room temperature, device on/off status, etc. In this work, we propose an alternative, data-driven, deep neural network framework of characterizing the aggregate flexibility of ensemble of ACs and WHs using the available end-use measurements. Since the training of the deep networks is an offline process requiring high computational efforts, it is not desirable to retrain the network if number of TCLs in the ensemble change over time due to changing availability of end-use appliances. Henceforth, we propose a transfer learning based approach to identify the VB parameters of the new ensemble with minimal retraining.
The main contribution of this paper is to develop a novel transfer learning based stacked autoencoder framework for representing virtual battery state of a given ensemble of TCLs. We also propose a novel one-dimensional convolution based LSTM network for calculating rest of the VB parameters, utilizing the previously calculated VB state from the stacked autoencoder. Finally, the VB parameters are numerically identified for two different ensembles of ACs and WHs.
The organization of this paper is as follows. In Section 2 we introduce stacked autoencoder along with the respective optimization problem for its training. In Section 3, we introduce the training objective of a LSTM network, and we describe the proposed one-dimensional convolution operation in Section 4. Transfer learning for the stacked autoencoder is introduced in Section 5. In Section 6, we introduce the dynamics and the power limit calculations for any given ensemble of ACs and WHs. In Section 7-8, we introduce a novel training process for training the convolution based LSTM network along with a detailed description of the dataset and whole deep network based framework. Numerical results are discussed in Section 9.

Description of Stacked Autoencoder
Autoencoder [1] (AE) is a type of deep neural network which gets trained by restricting the output values to be equal to the input values. This also indicates both input and output spaces have same dimensionality. The reconstruction error between the input and the output of network is used to adjust the weights of each layers. Therefore, the features learned by AE can well represent the input data space. Moreover, the training of AE is unsupervised, since it does not require label information.

General setup for AE
We have considered a supervised learning problem with a training set of n (input,output) pairs S n = {(x (1) , y (1) ), . . . , (x (n) , y (n) )}, that is sampled from an unknown distribution q(X, Y ). X is a d dimensional vector in R d . Z ∈ R d is a lower (d < d) dimensional representation of X. Z is linked to X by a deterministic mapping f θ , where θ is a vector of trainable parameters. Now, we briefly mention the terminology associated with AE.
Encoder: Encoder involves a deterministic mapping f θ which transforms an input vector x into hidden representation z. 1 f θ is an affine nonlinear mapping defined as where θ = {W , b} is a set of parameters, and W is d × d weight matrix, b is a bias vector of dimension d , and s(.) is an activation function. Decoder: The hidden dimensional representation z is mapped to dimension d, using mapping g θ and represented asŷ. The mapping g θ is called the decoder. Similar to f θ , g θ is also an affine nonlinear mapping defined as where θ = {W , b }. Also,ŷ is not an exact reconstruction of x, but rather in probabilistic terms as the parameters of a distribution p(X|Ŷ =ŷ) that may generate x with high probability. Now, we can equate the encoded and decoded outputs as p(X|Z = z) = p(X|Ŷ = g θ (ŷ)). Now, the reconstruction error to be optimized is L(x,ŷ) ∝ − log p(x|ŷ). For real valued x, L(x,ŷ) = L 2 (x,ŷ), where L 2 (., .) represents euclidean distance between two variables. In other words, we will use the squared error objective for training our autoencoder. For this current work, we will use affine and linear encoder along with affine and linear decoder with squared error loss. Furthermore, autoencoder training consists of minimizing the reconstruction error, by carrying out the optimization where E (.) [×] denotes the expectation, and q 0 is the empirical distribution defined by samples in S n . Now for the loss function defined before, the optimization problem can be rewritten as Intuitively, objective of training an autoencoder is to minimize the reconstruction error amounts by maximizing lower bound on the shared information between X and hidden representation Z.

Stacked Autoencoder (SAE)
We utilize the proposed AE and stack them to initialize a deep network as the similar way of deep belief networks [12] or ordinary AEs ( [3], [25], [18]). Once the AEs have been properly stacked, the inner most encoding layer output as shown in schematic, Figure 1, is considered as a virtual battery representation of the ensemble of TCLs. Furthermore, the number of layers of the stacked AEs are designed based on the reconstruction error for AE. Keeping in mind, a sudden change in dimension in both encoding and decoding layers can cause a difficulty in minimizing the reconstruction error in J AE . The parameters of all layers is fine-tuned using a stochastic gradient descent approach [5].

Description of Long-Short-Term-Memory network
We have used long short-term memory LSTM [13] to learn the long range temporal dependencies of virtual battery state of a given ensemble (encoded representation of the TCL states). For a LSTM cell with N memory units (see Figure 2), at each time step, the evolution of its parameters is determined by where the W x () and W h () terms are the respective rectangular input and square recurrent weight matrices, W c () are peephole weight vectors from the cell to each of the gates, σ denotes sigmoid activation functions (applied element-wise) and the i t , f t , and o t equations denote the input, forget, and output gates, respectively; z t is the input to the cell c t . The output of a LSTM cell is o t and denotes pointwise vector products. The forget gate facilitates resetting the state of the LSTM, while the peephole connections from the cell to the gates enable accurate learning of timings. The goal of a LSTM cell training is to estimate the conditional probability p(o t |i t ) where i t consists of a concatenated set of variables (virtual battery state of previous time steps and control input) and o t consists of virtual battery state of current time step. The proposed LSTM calculates this conditional probability by first obtaining fixed dimensional representation v t of the input i t given by the hidden state h t . Subsequently, the conditional probability of o t is calculated by using the hidden state representation h t . Now given a training dataset with input S and output T , training of the proposed LSTM is done by maximizing the log probability of the training objective whereT is the LSTM based prediction of output dataset T .

Description of ConvNet
A simple convolution neural network (ConvNet) is a sequence of layers, and every layer of a ConvNet transforms one volume of activations to another through a differentiable function. In this work, we used two type of layers to build ConvNet architectures: a Convolution Layer and a Pooling Layer. We stack these two layers alternately to form a ConvNet. We can write the output of a one-dimensional ConvNet as follows: • One-dimensional convolution layer -Accepts a volume of size W 1 × H 1 × D 1 , where W 1 is the batch size of the training data set -Requires four hyperparameters: number of filters K C , their spatial extent F C , length of stride S C , and the amount of zero padding P C -Produces a volume of size -Each filter in a convolution layer introduces F × F × D 1 weights, and in total (F × F × D 1 ) × K weights and K biases -Requires two hyperparameters: spatial extent F P , and stride S P -Produces a volume of size -Introduces zero weights and biases, since the pooling layer computes a fixed function of the input.
Next, for our proposed ConvNet, we will outline the architecture as applied to predict VB state and simultaneously learn and estimate VB parameters.
• Input [b s × l b × 1], where b s denotes the batch size of our training process (two hours, with 1 second resolution).
• The convolutional (CONV) layer computes the output of neurons that are connected to local regions in the input, each computing a dot product between their weights and a small region they are connected in the input volume. We have multiple CONV layers in our proposed ConvNet, each with a different filter size K C . For an input layer of size [b s × l b × 1], the output of CONV layer will be [b s × l b × K C ].
• The rectified linear unit (RELU) layer will apply an element-wise activation function, such as max(0, x) thresholding at zero. This leaves the size of the output volume unchanged to [b s × l b × K C ].
• The pooling (POOL) layer will perform a down-sampling operation along the spatial dimension (width, height), resulting in an output volume such , with a filter size of F P × S P .

Transfer learning via Net2Net for SAE
The structure (input node numbers) for the proposed SAE depends on the number of TCLs in the ensemble. This requires retraining of the SAE if we change the number of TCL in the ensemble. We are proposing to use the developed Net2Net strategy [7] where there is a change in number or type of TCLs in the ensemble. In order to explain this idea in the context of VB state modeling, we define "source system" (S) as an ensemble of N devices (where N is a defined integer) 2 . We will further define "target system" (T ) as an ensemble of M devices (where M = N ). The goal is that S will provide a good internal representation of the given task for T to copy and begin refining. This idea was initially presented as FitNets [26] and subsequently modified by Chen et al. in [7] as Net2Net.
We are proposing to combine two Net2Net strategies, namely Net2WiderNet and Net2DeeperNet 3 . Both of them based on initializing the "target" network to represent the same function as the "source" network. As an example, let the SAE representing S is represented by a functionŷ = f (x, θ), where x is input to the SAE,ŷ is output from the SAE (which for SAE is the reconstruction of input x), and θ is the trainable parameters of the SAE. We propose to choose a new set of parameters θ for the SAE representing T such that ∀x, f (x, θ) = g(x, θ )

Net2DeeperNet
As the name suggests, Net2DeeperNet allows to transform a network into a deeper one. Mathematically, Net2DeeperNet replaces one layer with two layers, i.e., The new weight matrix W 2 is initialized as identity matrix and get updated in the training process. Moreover, we need to ensure that φ(Iφ(v)) = φ(v) for all v, in order to ensure Net2DeeperNet can successfully replace the original network with deeper ones.

Net2WiderNet
Net2WiderNet allows a layer to be replaced with a wider layer, meaning a layer that has more neurons (can be also narrower if needed). Suppose that layer i and layer i + 1 are both fully connected layers, and layer i uses an elementwise non-linearity. To widen layer i, we replace W (i) with W (i+1) . If layer i has m inputs and n outputs, and layer i + 1 has p outputs, then W (i) ∈ R m×n and W (i+1) ∈ R n×p . Net2WiderNet allows to replace layer i with a layer that has q outputs, with q > n. We will introduce a random mapping function The new weights in the network for target T is given by Here, the first n columns of W (i) are copied directly into U (i) . Columns n + 1 through q of U (i) are created by choosing a random sample as defined in g. The random selection is performed with replacement, so each column of W (i) is copied potentially many times. For weights in U (i+1) , we must account for the replication by dividing the weight by replication factor given by 1 |{x|g(x)=g(j)}| , so all the units have exactly the same value as the unit in the network in source S.
Next, we discuss the application of this transfer learning to identify Virtual Battery (VB) parameters corresponding to an ensemble of ACs or WHs. We begin with the description of the VB model.

Virtual Battery Model
We use the following first order system model to describe the dynamics of a VB system,ẋ where x(t) ∈ R denotes the state of charge of the VB at time t with the initial state of charge; a denotes the self-dissipation rate; while the lower and upper energy limits of the VB are denoted by C 1 and C 2 , respectively. The regulation signal, u(t) acts as an input to the VB and must always lie within the power limits P − and P + . This simple first-order VB model can be applied to characterize the aggregated flexibility of many building loads and TCLs [9,10,15]. Note here that, unlike the typical assumption of symmetrical energy limits (i.e. C 1 = −C 2 ) in the existing VB identification methods, we allow the lower and upper energy limits to be different. Overall, the vector φ = [a, C 1 , C 2 , x 0 , P − , P + ] denotes the group of VB parameters. In order to identify the VB parameters, synthetic data are generated concerning the performance of an ensemble of TCLs in responding to a frequency regulation service request. Specifically the synthetic data are generated using simulation models of TCLs described in this section and the regulation signals from PJM [24]. This time series evolution of each device with respect to each regulation signal is then used to learn the first order VB system. For the sake of completeness, we also describe briefly the hybrid dynamical models of individual TCLs, used in simulations to generate synthetic data for training and testing of the transfer learning based deep network. Note, however, that the network itself is agnostic of the load models and parameters.

AC Model
Each AC device is governed by the following temperature dynamics [22,23]. where -outside air temperature T set (t) -set point temperature δT -dead band temperature C r -thermal capacitance of the room R -thermal resistance of the room η -load efficiency p(t) -power drawn by the AC: 0 when 'off'; P when 'on'.

WH Model
The below described model is formed by assuming that the water temperature inside the water tank has a uniform temperature, i.e., the water inside the tank is either all hot or all cold [8,22]. where, T w -water temperature inside the tank T set w -water temperature set-point T in -inlet water temperature δT w -dead band temperature W -thermal conductance of the tank C p -thermal capacitance p(t) -power drawn by the WH: 0 when 'off'; P w when 'on'.

Two-stepped training process
Before proceeding into the detailed training process for VB state prediction, we introduce few notations for clarity. 1 F and 2 F denote the functional representation of Convolution based LSTM network after first and second training process, respectively. X and Y denote input and output to the Convolution based LSTM network, during first step of training process. d is used as a historical window for prediction. 2Ŷ denotes the prediction of VB state after second step of training process.

First step of training process
This step of the training process involved an unsupervised learning, by utilizing historical VB state and regulation signal of size d (i.e., d number of historical data points consisting VB state and regulation signal at each data point). Given VB state x, and regulation signal u, input to the unsupervised learning X is defined as, X . . |u i ] for all i = 0, 1, . . . , N − 1, and output to the unsupervised learning Y is defined as The objective of first step of the training process is to learn 1 F while minimizing the loss, i.e., Y − 1 F(X) 2 .

Second step of training process
The purpose of having second step of training process is to mitigate the effect of error accumulation on the forecasting value, over time. For the second step training process, prediction of VB state from previous time step gets used in the next step, along with other historic VB state (we are using d number of historical data points). Upon continuing to forecast in the future, the historic data window keeps getting filled with forecast from previous iterations. This cause a forecasting error accumulation, which results in a divergence of predicted VB state from the actual state magnitude. Algorithm 1 which comprises the second step, defines a novel way of mitigating this aforementioned error accumulation.    (9)). The regulation signals from PJM [24] are considered and scaled appropriately to match the ensemble of ACs and WHs. The devices in each ensemble has to change their state in order to follow a regulation signal. In doing so, while keeping the aggregate power of the ensemble close to the regulation signal, the switching action of the ensemble should not violate the temperature constraints of individual devices. The switching strategy is determined by the solution of an optimization problem (similar to as shown in [15]). For ensemble of AC devices, a combination of 100 ACs is considered and the ON and OFF devices at every time instance are identified by solving an optimization problem. This generates the temperature state of each device, T (t), at each time iteration, for 200 distinct regulation signals. If the ensemble fails to track a regulation signal, then the time-series data is considered up to the point where tracking fails. The outside air temperature and user set-point for each device are assumed to be same in this analysis. The power limits of the ensemble are computed through a one-sided binary search algorithm as described in [14]. The 100 AC ensemble is simulated for 2 hours with 1 sec time resolution, for each regulation signal. For some regulation signals the ensemble violate the power limits P − and P + before the 2 hours running time and the temperature of each AC is only considered, until when the ensemble satisfies the power limit. Finally for making the suitable dataset for applying SAE, we stack temperature of each AC devices, followed by temperature set points for each devices, load efficiency and thermal capacity of each AC devices, by column, and stack the data points for each regulation signals by row. For the selected ensemble, these stacking result in a dataset of dimension R 1440199×203 . To obtain the input stack to SAE for an ensemble of WHs, a similar approach as described above for AC devices is followed. While generating this data, it is assumed that water flow into the WHs is at a medium rate.

Method description
The SAE introduced in Section 2 is trained on the dataset described in Section 8.1 for an ensemble of 100 AC devices. The objective of the training of SAE is to represent the given 203 dimensional dataset into a 1 dimensional encoded space, and subsequently transforms the 1 dimensional encoded representation back into the 203 dimensional original data space, with tolerable loss. The selected layer dimension of proposed SAE is 203-150-100-50-20-1-20-50-100-150-203, where all the activation functions are linear. Moreover, the variables in 203 input dimensions are not normalized, to represents the VB state dependency on the input variables. That also motivates the necessity of having unbounded linear activation functions, throughout the proposed SAE.
Moreover, when more AC devices are added to the given 100 AC devices ensemble, we leverage the proposed Net2Net framework introduced in Section 5, for the retraining and subsequent representation of the VB state for the dataset representing the new ensemble. Obviously the robust way is to retrain the proposed SAE architecture from scratch for the new dataset, but that includes higher computation cost and time. We can utilize the already trained network on 100 AC devices ensemble, for the new ensemble dataset, which results in significant savings of computation cost and time.
Finally, we introduced convolution based LSTM network, for forecasting the VB state evolution, given any regulation signal. Given the SAE, only able to represent VB state, for the given time the state of TCL is available, it is required to utilize a deep network for predicting time evolution of VB state, for the ensemble of TCLs. Simultaneously, this proposed convolution based LSTM network can be used to estimate the remaining unknown parameter a in the vector φ, which represents all the parameters related to VB. In the next section, we demonstrate the amalgamation of two proposed deep network framework for an ensemble of 100, 112 AC devices, and 120, 135 WHs.

Results and Discussion
We evaluate the performance of our proposed deep network framework on four different ensembles, namely ensemble of 100 and 112 AC devices and ensemble of 120 and 135 WH devices. Table 1 shows the effectiveness of utilizing proposed transfer learning instead of retraining the deep network for every ensemble. Table 1 shows an average computation time 4 savings of 77%, when identifying virtual battery states for different ensembles. Figures 5 and 6 show the reconstruction error histogram for two different ensembles of WHs and ACs, respectively. Both plots show a very small reconstruction error, which justifies a possibility of utilizing the proposed stacked autoencoder (specifically the trained decoder), to map the virtual battery state to individual device level, for checking the controller performances in device level. Table 2 shows calculated virtual battery parameters for four different ensembles, after using the proposed convolution LSTM network. Power limits (P + and P − ) are calculated using an optimization framework [14].
Finally, this proposed framework is shown to be generalizable for different type of TCLs, and also shown to be transferable for different number of devices in any given ensemble. Our future work will involve applying this framework for heterogeneous ensembles.