Attention mechanism fused Bi-LSTM (Bidirectional Long Short Term Memory) model-based returned and supplemented electric quantity calculation method and system

By applying the Bi-LSTM model based on attention mechanism fusion in the field of power measurement, predicting the power consumption data of power users during failure, solving the problem of lengthy and inaccurate existing power replenishment calculation methods, and achieving more efficient and reliable power replenishment calculations.

CN119534991APending Publication Date: 2025-02-28STATE GRID JIANGSU ELECTRIC POWER CO ZHENJIANG POWER SUPPLY CO +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411713485.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

The existing calculation methods for power replenishment are lengthy, time-consuming, and have low timeliness and reliability. Especially when failures of multiple types of power equipment occur, it is difficult to accurately calculate power replenishment.

Method used

The Bi-LSTM model based on the fusion of attention mechanism is adopted to calculate the power consumption data by mining the characteristics of the user's power consumption data, thereby predicting the power consumption data during the failure, avoiding direct modeling failures, improving the accuracy of power consumption data prediction, and thus calculating the power supply.

Benefits of technology

It improves the accuracy and efficiency of the calculation of the power replenishment, reduces the time for manual judgment and calculation, and enhances the timeliness and reliability of the calculation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119534991A_ABST
    Figure CN119534991A_ABST
Patent Text Reader

Abstract

The invention discloses an attention mechanism fusion-based return and supplement electric quantity calculation method of a Bi-LSTM model. The method comprises the following steps of: judging a metering fault time interval; the method comprises the following steps of: judging an optimal trend change point of starting and ending of a metering fault by using a change point detection algorithm according to trend change of data characteristics acquired by different meters in a time period when the metering equipment is mounted in a metering equipment fault time period last time, so as to realize intelligent recommendation of a metering fault interval; dividing a metering fault time interval; calculating metering fault retreating and supplementing electric quantity; and generating a metering fault electricity quantity returning and supplementing report. According to the method, the efficiency of returning and supplementing electric quantity calculation is improved, manual query and calculation links are reduced, and the personnel cost is reduced. And data values are fully released by utilizing a digital intelligence means, the timeliness of the return and supplement electric quantity calculation is enhanced, and the working process efficiency is effectively improved through a refined return and supplement calculation process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method and system for calculating the amount of electricity to be refunded or compensated based on a Bi-LSTM model fused with an attention mechanism, and belongs to the technical field of electric energy metering. Background Art

[0002] In the field of electricity metering, there are many electricity metering failures caused by human or natural factors. These failures lead to incorrect measurement of the electricity meter, resulting in a difference between the measured electricity consumption and the actual electricity consumption. Therefore, power supply companies need to calculate the amount of electricity to be refunded during the period of metering failure, so as to provide a basis for the future recovery of electricity charges.

[0003] The calculation of the amount of electricity to be refunded refers to the difference between the actual amount of electricity used and the amount of electricity measured by the electric energy meter during the period of metering failure. The current method for calculating the amount of electricity to be refunded mainly adopts the correction coefficient method. The entire process of calculating the amount of electricity to be refunded is lengthy, and a lot of time is required for manual judgment and calculation, which affects the timeliness and reliability of the calculation of the amount of electricity to be refunded. This method uses different power metering models according to the type of on-site metering device and the different faults. The actual amount of electricity during the metering failure is calculated based on the metered electricity during the failure, and then the correction coefficient is calculated to obtain the amount of electricity to be refunded. However, the correction coefficient method has strict requirements on the type of equipment failure, and the actual failures on site are diverse. Therefore, when multiple types of power equipment failures occur in a mixed manner, it is difficult to propose a corresponding model based on the actual situation on site. Therefore, in actual work, the previous electricity consumption or current electricity consumption is often used as a benchmark for calculation, but this method ignores the trend changes in electricity consumption data before and after the failure. Summary of the invention

[0004] The purpose of the present invention is to provide a method and system for calculating the amount of electricity refunded and subsidized based on a Bi-LSTM model fused with an attention mechanism. The method for calculating the amount of electricity refunded and subsidized based on a Bi-LSTM model fused with an attention mechanism mines the characteristics of the electricity consumption data of users before and after the metering failure, and then infers the electricity consumption data of users during the failure period, thereby avoiding direct modeling of the metering failure. At the same time, based on the Bi-LSTM model fused with an attention mechanism, after the local and global features of the sequence are fused with attention, the long-term and short-term features of the sequence can be better captured, thereby more accurately predicting the electricity consumption data, and then more accurately calculating the amount of electricity refunded and subsidized. Through this method and system, the staff can select different users and failure times through system interaction to calculate their amount of electricity refunded and subsidized, thereby improving work efficiency and work quality.

[0005] The purpose of the present invention is achieved through the following technical solutions:

[0006] A method for calculating the amount of electricity refunded based on a Bi-LSTM model fused with an attention mechanism, comprising:

[0007] Step 1: Obtain the electricity consumption data of the power user and express it as a time interval [t1,t N ], and normalize the time series to obtain the normalized sequence S = {s1, s2, …, s N}; According to the input length l-k+1 metering fault occurrence time interval [t k ,t l ], according to the time series S before the fault a ={s1,s2,…,s k-1} and the time series S after the failure b ={s l+1 ,s l+2 ,…,s N}Predict the time series S during the failure c ={s l+1 ,s l+2 ,…,s N};

[0008] Step 2: Construct training and test sets based on the time series before and after the fault, and use a sliding window of variable length for sampling. The window sampling length before the fault is W. a , the window sampling length after the fault is W b , the window sampling length during the fault period is W c = l-k+1, the total sliding window sampling length is W a +W b +l-k+1; where W a The initial value is k-1, W b The initial value is Nl, which is reduced by synchronously a ,W b Get sliding windows of different sizes and sample the entire time series. The sampled time series is represented as X s ={X a ,X c ,X b}, where X a , X b is the input of the sample sequence, X c The output of the sample sequence is randomly divided into two parts, 70% of which are used as training samples and 30% as test samples;

[0009] Step 3: Input X to the obtained sample a ,X b , use a vector of length l-k+1 containing 0 elements to fill the time between the two sequences and express it as X={X a,0,…,0,X b}; In order to avoid the influence of 0 elements on the training model, the corresponding length is defined as W a +W b The mask vector of +l-k+1 is M, where X a ,X b The element at the corresponding position is 1, and the remaining elements are 0; for the obtained sample X c , recorded as output vector Y;

[0010] Step 4: Train the samples through the Bi-LSTM model based on the multi-head attention mechanism fusion to achieve sequence prediction during the power metering failure, and obtain the local feature vector through the multi-head attention mechanism;

[0011] By measuring the distance between each point in the input sequence and the center point of the target output sequence, each point is weighted to obtain the final local feature vector, so that the sequence features closer to the target sequence can be better captured during the training process; the weight calculation formula for the input sequence X is as follows:

[0012]

[0013] Among them, |t i -c t | represents the distance from the point to the center point c t The absolute distance, p i Represents the weight of the point, and the final weight vector is expressed as P, then the local feature weight vector is X'=PX;

[0014] The time-weighted vector X' and the unprocessed vector X are respectively input into the multi-head attention mechanism model to extract effective information, thereby obtaining the local feature vector and the global feature vector; the linear layer outputs the query vector Q, the key vector K and the value vector V; the concatenated vector obtained by multi-head fusion is as follows:

[0015]

[0016] head i =Attention(QW Q i ,KW K i ,VW V i )

[0017] MultHead(Q,K,V)=Contact(head1,...,head m )W o

[0018] Where WQ i , W K i , W V i Represents the weight matrix of the i-th head Q, K, V, W o Represents the weight matrix of the multi-head attention mechanism output; d k represents the dimension size of the key vector K, and softmax represents the activation function; the local feature vector and the global feature vector finally obtained by the multi-head attention mechanism are represented as M l and M g ;

[0019] Finally, the local feature vector and the global feature vector are dynamically weighted to obtain the final feature M f :

[0020]

[0021] Where W l , W g Represent the weight matrices of local eigenvectors and global eigenvectors respectively, and sigmoid represents the activation function;

[0022] Step 5: For the final feature M f The encoding and decoding model is used to capture the long-term and short-term features of the sequence. The encoder uses a Bi-LSTM-based model to extract the features of the sequence through a bidirectional LSTM. The hidden state vector of a single LSTM during training is h t :

[0023] First, the input vector x t Use the mask vector m t and the last estimated vector To update:

[0024]

[0025] For input gate i t Calculate, W xi ,W hi ,b i is the model parameter corresponding to the input gate, and σ is the sigmoid activation function:

[0026] i t =σ(W xi x t +W hi h t-1 +b i )

[0027] Forget gate f t Calculate, Wxf ,W hf ,b f Model parameters corresponding to the forget gate:

[0028] f t =σ(W xf x t +W hf h t-1 +b f )

[0029] Calculate the new state unit c t The value of W xc ,W hc ,b c are the model parameters corresponding to the state unit:

[0030] c t =f t .c t-1 +i t .tanh(W xc x t +W hc h t-1 +b c )

[0031] For output gate o t Calculate, W xo ,W ho ,b o Is the model parameter corresponding to the output gate:

[0032] o t =σ(W xo x t +W ho h t-1 +b o )

[0033] Finally, the new hidden state vector h is obtained t :

[0034] h t =o t .tanh(c t )

[0035] Through two LSTMs trained from the forward sequence and the backward sequence respectively, the forward hidden state vector sequence is obtained

[0036] and the backward hidden state vector sequence Splice them together to get the final hidden state sequence h, where

[0037] The decoding uses a unidirectional LSTM and a linear activation function to obtain continuous output values.

[0038] x t =LSTM(h t ,x t-1 )

[0039] y t =W y x t +b y

[0040] The final output sequence uses the mean square error MSE to evaluate the gap between the predicted sequence and the original sequence:

[0041]

[0042] Where n represents the sequence length of the predicted output, y i represents the predicted value, represents the actual value;

[0043] Step 6: After the model training is completed, the user power consumption sequence during the metering failure period is predicted;

[0044] Step 7: Subtract the user's actual electricity consumption from the total electricity consumption of the user's electricity consumption sequence according to different electricity price periods to obtain the final refunded electricity.

[0045] The electricity subsidy calculation system based on the above-mentioned electricity subsidy calculation method comprises a resource storage layer, a data processing layer, a model prediction layer and a display application layer;

[0046] The display application layer includes: a browser display module, which displays the power consumption data of power users during the predicted metering failure period and the calculated refund and subsidy power; a browser interaction module, which interacts with the user to select his power user and failure time interval;

[0047] The resource storage layer includes: a data storage module, which stores the user's electricity consumption data in the database; a data maintenance module, which maintains the data to ensure the validity and integrity of the data;

[0048] The data processing layer includes: a request processing module that parses the user's request data, completes the calculation of the amount of electricity refunded, and constructs the return data to the user; a data segmentation module that uses a dynamic sliding window method to sample the user's electricity consumption data to obtain a training set and a test set;

[0049] The model prediction layer includes: a Bi-LSTM model training prediction module fused with an attention mechanism. The training set constructed by the data processing module is trained using the Bi-LSTM model fused with an attention mechanism, and the actual power consumption data of the user during the fault period is predicted.

[0050] The purpose of the present invention can also be further achieved by the following technical measures:

[0051] In the aforementioned method for calculating the amount of electricity to be refunded based on the Bi-LSTM model with fusion of the attention mechanism, in the multi-head attention mechanism model of step 4, the number of heads used is 8.

[0052] Compared with the prior art, the present invention has the following beneficial effects:

[0053] The present invention sorts out metering fault categories and refund calculation methods: through the refund electricity calculation regulations in the "Power Supply Business Rules", the following fault categories and corresponding refund times and calculation methods are summarized.

[0054] Metering fault time interval judgment: Determine the metering fault time according to the metering fault category. For the fault time that needs to be determined by the operating data of the electric energy metering device, the timing characteristics of the collected data before and after the metering fault are mined to intelligently determine the start and end time of the fault.

[0055] Through the time period from the last installation of the metering equipment to the failure of the metering equipment, according to the trend changes of the data characteristics of different metering collections, the change point detection algorithm is used to determine the optimal trend change points of the start and end of the metering failure, thereby realizing the intelligent recommendation of the metering failure interval. For the time series obtained by metering collection, the algorithm uses a dynamic programming method to find the best splitting method of all possible subsequences obtained by splitting the time series, so as to obtain the optimal start time and end time of the metering failure. Among them, the loss function based on the kernel function is used to measure the quality of the splitting results, so as to realize the judgment of the optimal start time and end time of the metering failure.

[0056] Metering failure time interval division: According to different types of users and different electricity prices in different time periods, the electricity volume across different electricity price periods is split into monthly, peak, flat and valley periods, thus providing a basis for the subsequent calculation of electricity fee refunds.

[0057] Calculation of electricity quantity refunded and subsidized due to metering failure: According to the different types of metering failures, the corresponding method in the intelligent calculation category table of electricity quantity refunded and subsidized is used to calculate the electricity quantity refunded and subsidized. Among them, for "taking the electricity consumption of users in normal months as the benchmark", first, try to use the electricity consumption in the same period of last year for refunding and subsidizing; second, use the average electricity consumption during the normal time of metering failure as the basis for refunding and subsidizing. At the same time, it also supports manual adjustments, and the system automatically queries and calculates, so as to adapt to changes in marketing business more flexibly.

[0058] Generation of report on electricity quantity refunded due to metering failure: According to the above process, the report on electricity quantity refunded due to metering failure is automatically generated to reduce the manual process of front-line personnel.

[0059] By improving the efficiency of electricity subsidy calculation, reducing manual query and calculation links, and reducing personnel costs. By using digital means, the value of data is fully released, the timeliness of electricity subsidy calculation is enhanced, and the efficiency of the workflow is effectively improved by refining the subsidy calculation process.

[0060] Provide electricity refund and subsidy calculation services, enhance the timeliness of electricity refund and subsidy calculation, and effectively improve work process efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 It is a flow chart of the method for calculating the amount of electricity to be refunded and subsidized of the present invention;

[0062] Figure 2 It is a structural diagram of the power refund and subsidy calculation system of the present invention. DETAILED DESCRIPTION

[0063] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.

[0064] like Figure 1 As shown, a method for calculating the amount of electricity refunded based on a Bi-LSTM model fused with an attention mechanism includes:

[0065] Step 1: Obtain the electricity consumption data of the power user and express it as a time interval [t1,t N ], the time series is normalized to avoid the influence of the amplitude of the sequence on its training, and then the normalized sequence S = {s1, s2, …, s N According to the input length l-k+1 metering fault occurrence time interval [t k ,t l ]. Therefore, the problem can be expressed as using the time series S before the failure a ={s1,s2,…,s k-1} and the time series S after the failure b ={s l+1 ,s l+2 ,…,s N}Predict the time series S during the failure c ={s l+1 ,s l+2 ,…,s N}.

[0066] Step 2: Construct training and test sets based on the time series before and after the fault. Since training requires a large number of samples, a sliding window with a variable length is used for sampling. The window sampling length before the fault is W. a , the window sampling length after the fault is W b , the window sampling length during the fault period is Wc = l-k+1, so the total sliding window sampling length is W a +W b +l-k+1. Where W a The initial value is k-1, W b The initial value is Nl, which is reduced by synchronously a ,W b Get sliding windows of different sizes and sample the entire time series. The sampled time series can be expressed as X s ={X a ,X c ,X b}, where X a , X b is the input of the sample sequence, X c is the output of the sample sequence. The obtained data set is randomly divided into two parts, 70% of which are used as training samples and 30% as test samples.

[0067] Step 3: Input X to the obtained sample a ,X b In order to ensure their timing relationship, a vector with a length of l-k+1 containing 0 elements is used to fill the time between the two sequences and express it as X={X a ,0,…,0,X b}. In order to avoid the influence of 0 elements on the training model, the corresponding length is defined as W a +W b The mask vector of +l-k+1 is M, where X a ,X b The element at the corresponding position is 1, and the remaining elements are 0. For the obtained sample X c , then record it as the output vector Y.

[0068] Step 4: Train the samples through the Bi-LSTM model based on the multi-head attention mechanism fusion to achieve sequence prediction during power metering failure. The local feature vector is obtained through the multi-head attention mechanism

[0069] By measuring the distance between each point in the input sequence and the center point of the target output sequence, each point is weighted to obtain the final local feature vector, so that the sequence features closer to the target sequence can be better captured during the training process. The weight calculation formula for the input sequence X is as follows:

[0070]

[0071] Among them, |t i -c t | represents the distance from the point to the center point c t The absolute distance, pi Represents the weight of the point, and the final weight vector is expressed as P. Then the local feature weight vector is X'=PX.

[0072] The time-weighted vector X' and the unprocessed vector X are respectively input into the multi-head attention mechanism model to better extract effective information, thereby obtaining local feature vectors and global feature vectors. The number of multi-heads is m = 8, and the linear layer outputs the query vector Q, key vector K and value vector V. The concatenated vector obtained by multi-head fusion is as follows:

[0073]

[0074] head i =Attention(QW Q i ,KW K i ,VW V i )

[0075] MultHead(Q,K,V)=Contact(head1,...,head m )W o

[0076] Where W Q i , W K i , W V i Represents the weight matrix of the i-th head Q, K, V, W o Represents the weight matrix of the multi-head attention mechanism output. d k represents the dimension size of the key vector K, and softmax represents the activation function. The local feature vector and global feature vector finally obtained by the multi-head attention mechanism are represented as M l and M g .

[0077] Finally, the local feature vector and the global feature vector are dynamically weighted to obtain the final feature M f .

[0078]

[0079] Where W l , W g They represent the weight matrices of local eigenvectors and global eigenvectors respectively, and sigmoid represents the activation function.

[0080] Step 5: For the final feature M fThe encoding and decoding model is used to capture the long-term and short-term features of the sequence. The encoder uses a Bi-LSTM-based model to extract the features of the sequence through a bidirectional LSTM, so that both the forward and backward features of the sequence can be better captured. The hidden state vector of a single LSTM during training is h t :

[0081] First, the input vector x t Use the mask vector m t and the last estimated vector to update.

[0082]

[0083] For input gate i t Calculate, W xi ,W hi ,b i is the model parameter corresponding to the input gate, and σ is the sigmoid activation function.

[0084] i t =σ(W xi x t +W hi h t-1 +b i )

[0085] Forget gate f t Calculate, W xf ,W hf ,b f is the model parameter corresponding to the forget gate.

[0086] f t =σ(W xf x t +W hf h t-1 +b f )

[0087] Calculate the new state unit c t The value of W xc ,W hc ,b c is the model parameter corresponding to the state unit.

[0088] c t =f t .c t-1 +i t .tanh(W xc x t +W hc h t-1 +b c )

[0089] For output gate o t Calculate, W xo ,W ho ,b o is the model parameter corresponding to the output gate.

[0090] o t =σ(W xo x t +W ho h t-1 +b o )

[0091] Finally, we get the new hidden state vector h t .

[0092] h t =o t .tanh(c t )

[0093] Through two LSTMs trained from the forward sequence and the backward sequence respectively, the forward hidden state vector sequence can be obtained respectively and the backward hidden state vector sequence Splice them together to get the final hidden state sequence h.

[0094] The decoding adopts unidirectional LSTM and uses a linear activation function to obtain continuous output values.

[0095] x t =LSTM(h t ,x t-1 )

[0096] y t =W y x t +b y

[0097] The final output sequence uses the mean square error (MSE) to evaluate the difference between the predicted sequence and the original sequence.

[0098]

[0099] Where n represents the sequence length of the predicted output, y i represents the predicted value, Represents actual value.

[0100] Step 6: After the model training is completed, the user power consumption sequence during the metering failure period is predicted.

[0101] Step 7: Subtract the user's actual electricity consumption from the total electricity consumption of the user's electricity consumption sequence according to different electricity price periods to obtain the final refunded electricity.

[0102] The electricity subsidy calculation system based on the above electricity subsidy calculation method includes a resource storage layer, a data processing layer, a model prediction layer and a display application layer, such as Figure 2 shown.

[0103] The display application module includes: a browser display module, which displays the power consumption data of power users during the predicted metering failure period and the calculated refunded power; and a browser interaction module, which interacts with the user to select his power user and failure time interval.

[0104] The resource storage layer includes: a data storage module, which stores user power consumption data in the database; and a data maintenance module, which maintains the data to ensure the validity and integrity of the data.

[0105] The data processing layer includes: a request processing module, which parses the user's request data, completes the calculation of the amount of electricity to be refunded, and constructs the return data to the user; a data segmentation module, which uses a dynamic sliding window method to sample the user's electricity consumption data to obtain a training set and a test set.

[0106] The model prediction layer includes: a Bi-LSTM model training prediction module fused with an attention mechanism. The training set constructed by the data processing module is trained using the Bi-LSTM model fused with an attention mechanism, and the actual power consumption data of the user during the fault period is predicted.

[0107] This method is used to conduct experimental comparisons with the current advanced methods on the same test samples. The training set samples contain 800 sample sequence data, and the test sample contains 200 sample sequence data. The input lengths are 48 before and after, and the predicted lengths are 48, 96, and 192 respectively. The experimental results are as follows:

[0108]

[0109] From the above table, we can see that the root mean square error (MSE) index of this method is better than that of the comparison algorithm, which shows that this method has a better effect.

[0110] In addition to the above embodiments, the present invention may also have other implementation modes. Any technical solutions formed by equivalent replacement or equivalent transformation shall fall within the protection scope required by the present invention.

Claims

1. A method for calculating the amount of electricity refunded based on a Bi-LSTM model fused with an attention mechanism, characterized in that: include: Step 1: Obtain the electricity consumption data of the power user and express it as a time interval [t1,t N ], and normalize the time series to obtain the normalized sequence S = {s1, s2, …, s N }; According to the input length l-k+1 metering fault occurrence time interval [t k ,t l ], according to the time series S before the fault a ={s1,s2,…,s k-1 } and the time series S after the failure b ={s l+1 ,s l+2 ,…,s N }Predict the time series S during the failure c ={s l+1 ,s l+2 ,…,s N }; Step 2: Construct training and test sets based on the time series before and after the fault, and use a sliding window of variable length for sampling. The window sampling length before the fault is W. a , the window sampling length after the fault is W b , the window sampling length during the fault period is W c = l-k+1, the total sliding window sampling length is W a +W b +l-k+1; where W a The initial value is k-1, W b The initial value is Nl, which is reduced by synchronously a ,W b Get sliding windows of different sizes and sample the entire time series. The sampled time series is represented as X s ={X a ,X c ,X b }, where X a , X b is the input of the sample sequence, X c The output of the sample sequence is randomly divided into two parts, 70% of which are used as training samples and 30% as test samples; Step 3: Input X to the obtained sample a ,X b , use a vector of length l-k+1 containing 0 elements to fill the time between the two sequences and express it as X={X a ,0,…,0,X b }; In order to avoid the influence of 0 elements on the training model, the corresponding length is defined as W a +W b The mask vector of +l-k+1 is M, where X a ,X b The element at the corresponding position is 1, and the remaining elements are 0; for the obtained sample X c , recorded as output vector Y; Step 4: Train the samples through the Bi-LSTM model based on the multi-head attention mechanism fusion to achieve sequence prediction during the power metering failure, and obtain the local feature vector through the multi-head attention mechanism; By measuring the distance between each point in the input sequence and the center point of the target output sequence, each point is weighted to obtain the final local feature vector, so that the sequence features closer to the target sequence can be better captured during the training process; the weight calculation formula for the input sequence X is as follows: Among them, |t i -c t | represents the distance from the point to the center point c t The absolute distance, p i Represents the weight of the point, and the final weight vector is expressed as P, then the local feature weight vector is X'=PX; The time-weighted vector X' and the unprocessed vector X are respectively input into the multi-head attention mechanism model to extract effective information, thereby obtaining the local feature vector and the global feature vector; the linear layer outputs the query vector Q, the key vector K and the value vector V; the concatenated vector obtained by multi-head fusion is as follows: headi=Attention(QW Q i ,KW K i ,VW V i ) MultiHead(Q,K,V)=Contact(head1,...,head m )W o Where W Q i , W K i , W V i Represents the weight matrix of the i-th head Q, K, V, W o Represents the weight matrix of the multi-head attention mechanism output; d k represents the dimension size of the key vector k, and softmax represents the activation function; the local feature vector and the global feature vector finally obtained by the multi-head attention mechanism are represented as M l and M g ; Finally, the local feature vector and the global feature vector are dynamically weighted to obtain the final feature M f : Where W l , W g Represent the weight matrices of local eigenvectors and global eigenvectors respectively, and sigmoid represents the activation function; Step 5: For the final feature M f The encoding and decoding model is used to capture the long-term and short-term features of the sequence. The encoder uses a Bi-LSTM-based model to extract the features of the sequence through a bidirectional LSTM. The hidden state vector of a single LSTM during training is h t : First, the input vector x t Use the mask vector m t and the last estimated vector To update: For input gate i t Calculate, W xi ,W hi ,b i is the model parameter corresponding to the input gate, and σ is the sigmoid activation function: i t =σ(W xi x t +W hi h t-1 +b i ) Forget gate f t Calculate, W xf ,W hf ,b f Model parameters corresponding to the forget gate: f t =σ(W xf x t +W hf h t-1 +b f ) Calculate the new state unit c t The value of W xc ,W hc ,b c are the model parameters corresponding to the state unit: c t =f t .c t-1 +i t .tanh(W xc x t +W hc h t-1 +b c ) For output gate o t Calculate, W xo ,W ho ,b o Is the model parameter corresponding to the output gate: o t =σ(W xo x t +W ho h t-1 +b o ) Finally, we get the new hidden state vector h t : h t =o t .tanh(c t ) Through two LSTMs trained from the forward sequence and the backward sequence respectively, the forward hidden state vector sequence is obtained and the backward hidden state vector sequence Splice them together to get the final hidden state sequence h, where The decoding uses a unidirectional LSTM and a linear activation function to obtain continuous output values. x t =LSTM(h t ,x t-1 ) y t =W y x t +b y The final output sequence uses the mean square error MSE to evaluate the gap between the predicted sequence and the original sequence: Where n represents the sequence length of the predicted output, y i represents the predicted value, represents the actual value; Step 6: After the model training is completed, the user power consumption sequence during the metering failure period is predicted; Step 7: Subtract the user's actual electricity consumption from the total electricity consumption of the user's electricity consumption sequence according to different electricity price periods to obtain the final refunded electricity.

2. The method for calculating the amount of electricity refunded and compensated based on the Bi-LSTM model with attention mechanism fusion according to claim 1, characterized in that: In the multi-head attention mechanism model of step 4, the number of heads used is 8.

3. A refund and subsidy power calculation system based on the Bi-LSTM model fused with attention mechanism, characterized in that: Contains resource storage layer, data processing layer, model prediction layer and display application layer; The display application layer includes: a browser display module, which displays the power consumption data of power users during the predicted metering failure period and the calculated refund and subsidy power; a browser interaction module, which interacts with the user to select his power user and failure time interval; The resource storage layer includes: a data storage module, which stores the user's electricity consumption data in the database; a data maintenance module, which maintains the data to ensure the validity and integrity of the data; The data processing layer includes: a request processing module that parses the user's request data, completes the calculation of the amount of electricity refunded, and constructs the return data to the user; a data segmentation module that uses a dynamic sliding window method to sample the user's electricity consumption data to obtain a training set and a test set; The model prediction layer includes: a Bi-LSTM model training prediction module fused with an attention mechanism. The training set constructed by the data processing module is trained using the Bi-LSTM model fused with an attention mechanism, and the actual power consumption data of the user during the fault period is predicted.