Energy consumption prediction method and device based on self-attention mechanism, equipment and medium

Through the self-attention mechanism and long-term memory network model, combined with seasonal change punishment and weighted loss function, the problem of unconsidered seasonal impact in energy consumption prediction is solved, and high-precision energy consumption prediction is achieved.

CN120409823APending Publication Date: 2025-08-01STATE GRID CHONGQING ELECTRIC POWER CO ELECTRIC POWER RES INST +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510588369.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-08
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

The prior art fails to effectively combine seasonal impact in energy consumption prediction, resulting in low prediction accuracy and inconsistent with the actual situation.

Method used

The self-attention mechanism and long-term memory network model are used to predict energy consumption by setting the weight values of different months and constructing the seasonal change amplitude penalty function, the time-step change consistency loss function and the weighted loss function.

Benefits of technology

It improves the accuracy and reliability of energy consumption prediction, can accurately grasp the periodic changes in energy consumption, and enhances the stability and accuracy of the prediction results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120409823A_ABST
    Figure CN120409823A_ABST
Patent Text Reader

Abstract

The invention discloses an energy consumption prediction method and device based on a self-attention mechanism, equipment and a medium, and relates to the technical field of energy consumption prediction, and the method comprises the steps: constructing a target training set, and setting a target weight value corresponding to each month corresponding to historical monthly electric quantity data; a target loss function is constructed, the target loss function comprises a seasonal change amplitude penalty function, a time step change consistency loss function and a weighted loss function, and the target loss function is added to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; and training the target long-short-term memory network model according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and performing energy consumption prediction by using the trained model and the self-attention mechanism. The weight values corresponding to different months are set, and energy consumption prediction is carried out by using the long and short-term memory network, so that the accuracy of the prediction result is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of energy consumption prediction, and particularly to an energy consumption prediction method, device, equipment and medium based on a self-attention mechanism. Background Technique

[0002] With the continuous growth of global energy demand, especially the rapid growth of electricity consumption, how to efficiently and accurately predict energy consumption has become a key problem to be solved. In the fields of power systems, industrial production and urban energy management, accurate energy consumption prediction is of crucial significance for energy conservation, emission reduction, cost control and sustainable development. Through energy consumption prediction, especially by inferring comprehensive energy consumption from electricity consumption data, it can effectively guide energy allocation and improve energy use efficiency, and ensure the stability of energy supply. Energy consumption is significantly affected by seasonal changes. In particular, there are large differences in electricity consumption and heat energy demand in different seasons.

[0003] Currently, when predicting energy consumption, only a neural network model is simply used to predict based on historical data. This prediction method has the problem that it cannot combine seasonal effects for energy consumption prediction, resulting in low prediction accuracy and a prediction result that does not match the actual situation. Therefore, how to perform high-precision and high-reliability energy prediction has become a technical problem to be solved currently. Summary of the Invention

[0004] In view of this, the purpose of the present invention is to provide an energy consumption prediction method, device, equipment and medium based on a self-attention mechanism, which can ensure the accuracy of the prediction result by setting the weight values corresponding to different months and using a long short-term memory network for energy consumption prediction. The specific scheme is as follows:

[0005] In the first aspect, the present application provides an energy consumption prediction method based on a self-attention mechanism, including:

[0006] Obtain historical monthly electricity consumption data and corresponding historical monthly energy consumption data, construct a target training set using the historical monthly electricity consumption data and the historical monthly energy consumption data, and set target weight values corresponding to each month corresponding to the historical monthly electricity consumption data;

[0007] Construct a target loss function based on the target weight values, and add the target loss function to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; wherein, the target loss function includes a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function. The seasonal change amplitude penalty function is used to measure the change amplitude of the energy consumption prediction values between adjacent months based on the target weight values. The time step change consistency loss function is used to measure the difference between the predicted value of the energy consumption change amount and the actual value of the energy consumption change amount between adjacent months. The weighted loss function is used to measure the difference between the predicted value of the energy consumption and the actual value of the energy consumption within the same month based on the target weight values;

[0008] Train the target long short-term memory network model according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and use the trained model and the self-attention mechanism for energy consumption prediction.

[0009] Optionally, the constructing the target training set by using the historical monthly electricity data and the historical monthly energy consumption data includes:

[0010] Clean the historical monthly electricity data and the historical monthly energy consumption data to obtain corresponding cleaned historical monthly electricity data and cleaned historical monthly energy consumption data;

[0011] Label the cleaned historical monthly electricity data to construct the target training set; wherein, the label is the corresponding cleaned historical monthly energy consumption data of each of the cleaned historical monthly electricity data.

[0012] Optionally, the setting the target weight values corresponding to each month corresponding to the historical monthly electricity data includes:

[0013] Set the target weight values of February, May, August, and November to the first weight value, and set the target weight values of January, June, July, and December to the second weight value;

[0014] Set the target weight values of March, April, September, and October to the third weight value; wherein, the first weight value is less than the second weight value, and the second weight value is less than the third weight value.

[0015] Optionally, the training the target long short-term memory network model according to the target training set and the self-attention mechanism includes:

[0016] Use the target long short-term memory network model to analyze the target training set to obtain the hidden state corresponding to the target long short-term memory network model;

[0017] Obtain the query vector, key vector, and value vector corresponding to the target training set based on the hidden state, and train the target long short-term memory network model according to the query vector, the key vector, and the value vector.

[0018] Optionally, the process of training the target long short-term memory network model includes:

[0019] Set the target learning rate corresponding to the target long short-term memory network model, and iterate the target long short-term memory network model based on the target learning rate, a preset Adam optimizer, and a backpropagation algorithm to minimize the target loss function.

[0020] Optionally, the seasonal change amplitude penalty function is:

[0021] ;

[0022] Wherein, is the function name of the seasonal change amplitude penalty function, is the energy consumption prediction value corresponding to the th sample in the historical monthly electricity consumption data, is the energy consumption prediction value corresponding to the th sample in the historical monthly electricity consumption data, is the target weight value corresponding to the th sample, is the month corresponding to the th sample, and N is the number of samples included in the historical monthly electricity consumption data.

[0023] Optionally, the time step change consistency loss function is:

[0024] ;

[0025] Wherein, is the function name of the time step change consistency loss function, is the actual energy consumption value corresponding to the th sample, is the actual energy consumption value corresponding to the th sample.

[0026] In a second aspect, the present application provides an energy consumption prediction device based on a self-attention mechanism, including:

[0027] A weight setting module, configured to obtain historical monthly power consumption data and corresponding historical monthly energy consumption data, construct a target training set by using the historical monthly power consumption data and the historical monthly energy consumption data, and set target weight values corresponding to each month corresponding to the historical monthly power consumption data;

[0028] A loss function construction module, configured to construct a target loss function based on the target weight values, and add the target loss function to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; wherein, the target loss function includes a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function, the seasonal change amplitude penalty function is used to measure the change amplitude of the energy consumption prediction values between adjacent months based on the target weight values, the time step change consistency loss function is used to measure the difference between the predicted value of the energy consumption change amount and the actual value of the energy consumption change amount between adjacent months, and the weighted loss function is used to measure the difference between the energy consumption prediction value and the actual energy consumption value within the same month based on the target weight values;

[0029] An energy consumption prediction module, configured to train the target long short-term memory network model according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and perform energy consumption prediction by using the trained model and the self-attention mechanism.

[0030] In a third aspect, the present application provides an electronic device, including:

[0031] A memory, configured to store a computer program;

[0032] A processor, configured to execute the computer program to implement the foregoing energy consumption prediction method based on the self-attention mechanism.

[0033] In a fourth aspect, the present application provides a computer-readable storage medium, configured to store a computer program, and when the computer program is executed by a processor, the foregoing energy consumption prediction method based on the self-attention mechanism is implemented.

[0034] This application first obtains historical monthly electricity consumption data and corresponding historical monthly energy consumption data, constructs a target training set using the historical monthly electricity consumption data and the historical monthly energy consumption data, and sets target weight values corresponding to each month corresponding to the historical monthly electricity consumption data. Then, a target loss function is constructed based on the target weight values, and the target loss function is added to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; wherein, the target loss function includes a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function. The seasonal change amplitude penalty function is used to measure the change amplitude of the energy consumption prediction values between adjacent months based on the target weight values. The time step change consistency loss function is used to measure the difference between the predicted value of the energy consumption change amount and the actual value of the energy consumption change amount between adjacent months. The weighted loss function is used to measure the difference between the predicted value of the energy consumption and the actual value of the energy consumption within the same month based on the target weight values. Finally, the target long short-term memory network model is trained according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and the trained model and the self-attention mechanism are used for energy consumption prediction. It can be seen that this application can accurately grasp the periodic change of energy consumption by using the long short-term memory network, so as to predict the future energy consumption situation according to the periodic change of energy consumption, improving the accuracy of the prediction result; by constructing a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function, and setting different weight values for different seasons, the seasonal influence of energy consumption is incorporated into the energy consumption prediction process, ensuring the reliability of the prediction result. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained according to the provided drawings without creative efforts.

[0036] Figure 1 It is a flowchart of an energy consumption prediction method based on a self-attention mechanism disclosed in this application;

[0037] Figure 2 It is a schematic diagram of the principle of a self-attention mechanism disclosed in this application;

[0038] Figure 3 It is a schematic diagram of a model connection structure disclosed in this application;

[0039] Figure 4 It is a schematic diagram of the structure of an energy consumption prediction device based on a self-attention mechanism disclosed in this application;

[0040] Figure 5 This is a structural diagram of an electronic device disclosed in the present application. Specific implementation manners

[0041] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0042] Currently, the method for predicting energy consumption has the problem that it cannot combine the seasonal influence for energy consumption prediction, resulting in low prediction accuracy and the prediction result not conforming to the actual situation. For this reason, the present application provides an energy consumption prediction method based on the self-attention mechanism. By setting the weight values corresponding to different months and using the long short-term memory network for energy consumption prediction, the accuracy of the prediction result is ensured.

[0043] See Figure 1 As shown, the embodiment of the present invention discloses an energy consumption prediction method based on the self-attention mechanism, including:

[0044] Step S11: Obtain the historical monthly power consumption data and the corresponding historical monthly energy consumption data, construct a target training set by using the historical monthly power consumption data and the historical monthly energy consumption data, and set the target weight values corresponding to each month corresponding to the historical monthly power consumption data.

[0045] This embodiment proposes a Stacked LSTM (Long Short-Term Memory) model based on the self-attention mechanism (i.e., the target long short-term memory network model), and trains it in combination with three innovative loss functions for energy consumption prediction using the trained model; moreover, the energy consumption prediction method based on the self-attention mechanism in this embodiment can be applied to fields such as power systems, energy management, and industrial and urban energy scheduling.

[0046] In this embodiment, the process of obtaining historical monthly power consumption data and corresponding historical monthly energy consumption data and constructing a target training set using the historical monthly power consumption data and the historical monthly energy consumption data may specifically include: cleaning the historical monthly power consumption data and the historical monthly energy consumption data to obtain the corresponding cleaned historical monthly power consumption data and cleaned historical monthly energy consumption data; tagging the cleaned historical monthly power consumption data to construct a target training set; where the tag is the cleaned historical monthly energy consumption data corresponding to each of the cleaned historical monthly power consumption data; that is, organizing the historical monthly power consumption data and the historical monthly energy consumption data to produce a data set for training a neural network model. The data set contains N input samples and tags, N is the number of input samples and tags, the dimension of the sample is T, indicating the monthly power consumption data for the past T months, and the tag is the monthly energy consumption data for the next month.

[0047] It can be understood that the energy consumption data has seasonal fluctuations, long-term dependencies, and non-linear characteristics. Among them, seasonal fluctuations: Energy consumption is significantly affected by seasonal changes. In particular, there are large differences in power consumption and heat energy demand in different seasons; long-term dependencies: Energy consumption has an obvious periodicity and there is a long-term dependence relationship over time; non-linear characteristics: Energy consumption is affected by factors such as climate change, holidays, and production activities, and there are complex non-linear relationships among these factors. Therefore, in this embodiment, different weight values are set for each month so as to train the target long short-term memory network model based on the weight values corresponding to each month, making the prediction result of the model more in line with the actual power consumption situation; correspondingly, in this embodiment, the process of setting the target weight values corresponding to each month corresponding to the historical monthly power consumption data may specifically include: setting the target weight values for February, May, August, and November as the first weight value, and setting the target weight values for January, June, July, and December as the second weight value; setting the target weight values for March, April, September, and October as the third weight value; where the first weight value is less than the second weight value, and the second weight value is less than the third weight value. By assigning different weight values to different months, a target loss function can be constructed based on the weight values, so that the prediction result of the trained model can be more in line with the actual power consumption situation.

[0048] Step S12: Construct a target loss function based on the target weight values, and add the target loss function to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; wherein, the target loss function includes a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function. The seasonal change amplitude penalty function is used to measure the change amplitude of the energy consumption prediction values between adjacent months based on each of the target weight values. The time step change consistency loss function is used to measure the difference between the predicted value of the energy consumption change amount and the actual value of the energy consumption change amount between adjacent months. The weighted loss function is used to measure the difference between the predicted value of the energy consumption and the actual value of the energy consumption within the same month based on each of the target weight values.

[0049] In this embodiment, three innovative loss functions are designed to guide the model to capture key temporal features and patterns during training, thereby improving the prediction accuracy:

[0050] Seasonal change amplitude penalty function: This loss function optimizes the prediction smoothness and accuracy by balancing the influence of seasonal fluctuations, increasing the penalty in months with small fluctuations and reducing the penalty in months with large fluctuations. That is, through a smooth square penalty, the penalty amplitude is relatively small in months with large seasonal changes, thus avoiding excessive punishment for seasonal fluctuations; while in months with small seasonal fluctuations, the penalty is large, which helps to enhance the model's constraint on prediction smoothness in these months. The seasonal change amplitude penalty function is as follows:

[0051] ;

[0052] Wherein, is the function name of the seasonal change amplitude penalty function, is the predicted value of the energy consumption corresponding to the th sample in the historical monthly electricity consumption data, is the predicted value of the energy consumption corresponding to the th sample in the historical monthly electricity consumption data, is the seasonal factor (target weight value) corresponding to the th sample, is the th sample corresponding month, and N is the number of samples included in the historical monthly electricity consumption data.

[0053] When is 5, 8, 11, 2, the seasonal factor is 1 (i.e., the first weight value), indicating the transition period;

[0054] When is 6, 7, 12, 1, the seasonal factor is 1.2 (i.e., the second weight value), indicating within summer and winter.

[0055] When is 3, 4, 9, or 10, the seasonal factor is 1.5 (i.e., the third weight value), indicating within spring and autumn.

[0056] Time-step change consistency loss function: This loss function compares the change amount between the predicted value and the actual value, penalizes the difference between the predicted change amount and the actual change amount, ensures that the predicted change of the model is consistent with the actual trend, and maintains the smoothness of the prediction. The time-step change consistency loss function is as follows:

[0057] ;

[0058] where is the function name of the time-step change consistency loss function, is the actual energy consumption value corresponding to the th sample, is the actual energy consumption value corresponding to the th sample.

[0059] Weighted loss function: Adjusts the weights for different time steps. Especially in key seasons (such as summer and winter), higher weights are given to improve the prediction accuracy during key periods. The weighted loss function is as follows:

[0060] ;

[0061] where is the function name of the weighted loss function, , different from the seasonal factor , is the weight for the th month. Higher weights are given in summer (from June to August) and winter (from December to February), is 1.5, and for other months is 1.0.

[0062] The target loss function consists of the above seasonal change amplitude penalty function, time-step change consistency loss function, and weighted loss function; where the target loss function is as follows:

[0063] ;

[0064] By constructing three new loss functions and combining them into an objective loss function, on the one hand, the seasonal variation amplitude penalty loss function enables the model to increase the penalty in months with smaller seasonal fluctuations and reduce the penalty in months with larger fluctuations during the training process, thereby optimizing the smoothness and accuracy of the prediction; on the other hand, the time step change consistency loss function can help the model maintain the consistency of the changes between the predicted value and the actual value, punish excessive prediction fluctuations, and ensure the smoothness of the model prediction, thereby improving the stability of the prediction results; thirdly, the weighted loss function can enhance the prediction accuracy of the model for the power consumption in key time periods by adjusting the weights of different time steps, especially in seasons with high power consumption.

[0065] Step S13: Train the target long short-term memory network model according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and use the trained model and the self-attention mechanism for energy consumption prediction.

[0066] In this embodiment, the principle of the self-attention mechanism is as Figure 2 shown. By using three vectors: Query, Key, and Value, the importance of each input element is calculated. First, by calculating the similarity between the query and all keys, the weight of each element is obtained, and then these weights are applied to the corresponding value vectors, and finally, the weighted sum is calculated to obtain the output. This mechanism can capture the dependencies between the elements in the input sequence, regardless of the distance between these elements. The advantage of self-attention is that it can effectively model long-distance dependencies and support parallel computing, improving the efficiency. In addition, the self-attention mechanism can automatically adjust the degree of attention to different input elements, enhancing the expression ability of the model, and is particularly suitable for processing complex time series data and long sequence tasks.

[0067] The self-attention mechanism weights the historical time steps by calculating the query vector (Q), key vector (K), and value vector (V) at each time step, helping the model to more effectively focus on the key time steps that have a greater impact on the prediction results, thereby enhancing the prediction performance. Finally, after the weighted processing of the LSTM and the self-attention mechanism, the final energy consumption prediction value is obtained through the fully connected layer.

[0068] It should be noted that Stacked LSTM is used to process the input time series data, and captures the long-term dependencies in the data by stacking two LSTM cells. During the training process, the hidden state of the LSTM passes the key information in the time series to help the model understand the time pattern of the power consumption data. Correspondingly, in this embodiment, the process of training the target long short-term memory network model according to the target training set and the self-attention mechanism specifically may include: analyzing the target training set by using the target long short-term memory network model to obtain the hidden state corresponding to the target long short-term memory network model; obtaining the query vector, key vector, and value vector corresponding to the target training set based on the hidden state, and training the target long short-term memory network model according to the query vector, key vector, and value vector.

[0069] In this embodiment, the process of training the target long short-term memory network model includes: setting the target learning rate corresponding to the target long short-term memory network model, and iterating the target long short-term memory network model based on the target learning rate, the preset Adam optimizer, and the backpropagation algorithm to minimize the target loss function; that is, in this embodiment, the Adam optimizer is adopted, the learning rate is set to 0.001, the model is trained, and through the backpropagation algorithm, the weights and biases of the model are continuously adjusted to minimize the loss function and optimize the prediction result.

[0070] After the training of the target long short-term memory network model is completed, the monthly power consumption data of a certain month can be input into the trained model so that the trained model can predict the energy consumption data corresponding to the above monthly power consumption data. Among them, the structure of the trained model is as Figure 3 shown. First, after obtaining the input data, through the processing of two LSTM layers, the self-attention model, and the fully connected layer, the corresponding prediction result is finally output. By combining the self-attention mechanism with the stacked LSTM model, the model can effectively capture the complex patterns in the time series, thereby accelerating the convergence speed of training and improving the prediction accuracy. In addition, the method in this embodiment is not only applicable to the prediction of power consumption, but also can be applied to the prediction of other energy types such as heat energy and natural gas, and has a wide range of application prospects.

[0071] In a specific embodiment, historical power consumption data and monthly energy consumption data are first collected and sorted to construct a time series data set. The samples include monthly power consumption data for the past T months, and the label is the monthly energy consumption data for the next month. The neural network model is trained. Then, Stacked LSTM is used as the basic time series model, and a self-attention mechanism is introduced on this basis to further improve the model's attention ability to key periods. A seasonal change amplitude penalty, a time step change consistency loss, and a weighted loss are added to the loss function. During the training process, the Adam optimizer is used, the learning rate is set to 0.001, and through training, the parameters are adjusted to optimize the model performance. Finally, the trained model is applied to actual prediction tasks in fields such as power systems, industrial production, and urban energy management to provide accurate energy consumption predictions, optimize resource scheduling, and reduce energy waste.

[0072] It can be seen that by using the long short-term memory network, the present application can accurately grasp the periodic changes in energy consumption, and thus can predict the future energy consumption according to the periodic changes in energy consumption, improving the accuracy of the prediction results. By constructing a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function, and setting different weight values for different seasons, the seasonal influence on energy consumption is incorporated into the energy consumption prediction process, ensuring the reliability of the prediction results.

[0073] See Figure 4 As shown, an energy consumption prediction device based on a self-attention mechanism disclosed in an embodiment of the present invention includes:

[0074] A weight setting module 11, configured to obtain historical monthly power consumption data and corresponding historical monthly energy consumption data, construct a target training set using the historical monthly power consumption data and the historical monthly energy consumption data, and set target weight values corresponding to each month corresponding to the historical monthly power consumption data;

[0075] A loss function construction module 12, configured to construct a target loss function based on the target weight values, and add the target loss function to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; wherein, the target loss function includes a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function. The seasonal change amplitude penalty function is used to measure the change amplitude of the energy consumption prediction values between adjacent months based on the target weight values. The time step change consistency loss function is used to measure the difference between the predicted value of the energy consumption change amount and the actual value of the energy consumption change amount between adjacent months. The weighted loss function is used to measure the difference between the predicted value of the energy consumption and the actual value of the energy consumption within the same month based on the target weight values;

[0076] The energy consumption prediction module 13 is used to train the target long short-term memory network model according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and use the trained model and the self-attention mechanism for energy consumption prediction.

[0077] It can be seen that by using the long short-term memory network, the present application can accurately grasp the periodic changes in energy consumption, so as to predict the future energy consumption according to the periodic changes in energy consumption, improving the accuracy of the prediction results; by constructing a seasonal change amplitude penalty function, a time step change consistency loss function and a weighted loss function, and setting different weight values for different seasons, the seasonal influence of energy consumption is incorporated into the process of energy consumption prediction, ensuring the reliability of the prediction results.

[0078] In some specific embodiments, the weight setting module 11 may specifically include:

[0079] The data cleaning unit is used to clean the historical monthly electricity data and the historical monthly energy consumption data to obtain corresponding cleaned historical monthly electricity data and cleaned historical monthly energy consumption data;

[0080] The data tagging unit is used to tag the cleaned historical monthly electricity data to construct the target training set; wherein, the tag is the corresponding cleaned historical monthly energy consumption data of each of the cleaned historical monthly electricity data.

[0081] In some specific embodiments, the weight setting module 11 may specifically include:

[0082] The first weight setting unit is used to set the target weight values of February, May, August and November to the first weight value, and set the target weight values of January, June, July and December to the second weight value;

[0083] The second weight setting unit is used to set the target weight values of March, April, September and October to the third weight value; wherein, the first weight value is less than the second weight value, and the second weight value is less than the third weight value.

[0084] In some specific embodiments, the energy consumption prediction module may specifically include:

[0085] The training set analysis unit is used to analyze the target training set by using the target long short-term memory network model to obtain the hidden state corresponding to the target long short-term memory network model;

[0086] A first model training unit, configured to obtain query vectors, key vectors, and value vectors corresponding to the target training set based on the hidden states, and train the target long short-term memory network model according to the query vectors, the key vectors, and the value vectors.

[0087] In some specific embodiments, the energy consumption prediction module may specifically include:

[0088] A second model training unit, configured to set a target learning rate corresponding to the target long short-term memory network model, and perform iterations on the target long short-term memory network model based on the target learning rate, a preset Adam optimizer, and a backpropagation algorithm, so as to minimize the target loss function.

[0089] Furthermore, an embodiment of the present application also discloses an electronic device, Figure 5 which is a structural diagram of an electronic device 20 shown according to an exemplary embodiment. The content in the figure should not be considered as any limitation to the scope of use of the present application.

[0090] Figure 5 This is a schematic structural diagram of an electronic device 20 provided by an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the energy consumption prediction method based on the self-attention mechanism disclosed in any of the foregoing embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0091] In this embodiment, the power supply 23 is used to provide operating voltages for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows is any communication protocol applicable to the technical solution of the present application, and no specific limitation is imposed on it here; the input / output interface 25 is used to obtain external input data or output data to the outside, and its specific interface type can be selected according to specific application requirements, and no specific limitation is made here.

[0092] In addition, as a carrier for resource storage, the memory 22 may be a read-only memory, a random access memory, a magnetic disk, or an optical disc, etc. The resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage method may be temporary storage or permanent storage.

[0093] Among them, the operating system 221 is used to manage and control each hardware device and computer program 222 on the electronic device 20, and it can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program that can be used to complete the energy consumption prediction method based on the self-attention mechanism executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs that can be used to complete other specific tasks.

[0094] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the energy consumption prediction method based on the self-attention mechanism disclosed above is implemented. For the specific steps of this method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be repeated here.

[0095] In this specification, the various embodiments are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts among the various embodiments can be referred to each other. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method part.

[0096] Those skilled in the art can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0097] The steps of the methods or algorithms described in combination with the embodiments disclosed in this article can be directly implemented by hardware, software modules executed by a processor, or a combination of the two. The software modules can be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium well-known in the technical field.

[0098] Finally, it should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the said element.

[0099] The technical solutions provided in this application have been introduced in detail above. Specific examples are used in this text to elaborate on the principles and implementation manners of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those of ordinary skill in the art, according to the idea of this application, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to this application.

Claims

1. An energy consumption prediction method based on self-attention mechanism, characterized in that, Including: Obtain historical monthly electricity consumption data and corresponding historical monthly energy consumption data, construct a target training set using the historical monthly electricity consumption data and the historical monthly energy consumption data, and set target weight values corresponding to each month corresponding to the historical monthly electricity consumption data; Construct a target loss function based on the target weight values, and add the target loss function to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; wherein, the target loss function includes a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function. The seasonal change amplitude penalty function is used to measure the change amplitude of the energy consumption prediction values between adjacent months based on each of the target weight values, the time step change consistency loss function is used to measure the difference between the predicted value of the energy consumption change amount and the actual value of the energy consumption change amount between adjacent months, and the weighted loss function is used to measure the difference between the predicted value of the energy consumption and the actual value of the energy consumption within the same month based on each of the target weight values; Train the target long short-term memory network model according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and use the trained model and the self-attention mechanism for energy consumption prediction.

2. The energy consumption prediction method based on the self-attention mechanism according to claim 1, characterized in that The constructing the target training set using the historical monthly electricity consumption data and the historical monthly energy consumption data includes: Perform data cleaning on the historical monthly electricity consumption data and the historical monthly energy consumption data to obtain corresponding cleaned historical monthly electricity consumption data and cleaned historical monthly energy consumption data; Label the cleaned historical monthly electricity consumption data to construct the target training set; wherein, the label is the cleaned historical monthly energy consumption data corresponding to each of the cleaned historical monthly electricity consumption data.

3. The energy consumption prediction method based on the self-attention mechanism according to claim 1, wherein The setting the target weight values corresponding to each month corresponding to the historical monthly electricity consumption data includes: Set the target weight values of February, May, August, and November to a first weight value, and set the target weight values of January, June, July, and December to a second weight value; Set the target weight values of March, April, September, and October to a third weight value; wherein, the first weight value is less than the second weight value, and the second weight value is less than the third weight value.

4. The energy consumption prediction method based on the self-attention mechanism according to claim 1, wherein The training the target long short-term memory network model according to the target training set and the self-attention mechanism includes: Analyze the target training set using the target long short-term memory network model to obtain hidden states corresponding to the target long short-term memory network model; Obtain query vectors, key vectors, and value vectors corresponding to the target training set based on the hidden states, and train the target long short-term memory network model according to the query vectors, the key vectors, and the value vectors.

5. The energy consumption prediction method based on the self-attention mechanism according to claim 1, characterized in that The process of training the target long short-term memory network model includes: Set a target learning rate corresponding to the target long short-term memory network model, and perform iteration on the target long short-term memory network model based on the target learning rate, a preset Adam optimizer, and a backpropagation algorithm to minimize the target loss function.

6. The energy consumption prediction method based on the self-attention mechanism according to claim 1, characterized in that The seasonal change amplitude penalty function is as follows: ; Among them, is the function name of the seasonal change amplitude penalty function, is the energy consumption prediction value corresponding to the th sample in the historical monthly electricity consumption data, is the energy consumption prediction value corresponding to the th sample in the historical monthly electricity consumption data, is the target weight value corresponding to the th sample, is the month corresponding to the th sample, and N is the number of samples included in the historical monthly electricity consumption data.

7. The energy consumption prediction method based on the self-attention mechanism according to claim 6, characterized in that The time step change consistency loss function is as follows: ; Among them, is the function name of the time step change consistency loss function, is the actual energy consumption value corresponding to the th sample, is the actual energy consumption value corresponding to the 8. An energy consumption prediction device based on self-attention mechanism, characterized in that, It includes: A weight setting module, configured to obtain historical monthly power consumption data and corresponding historical monthly energy consumption data, construct a target training set by using the historical monthly power consumption data and the historical monthly energy consumption data, and set target weight values corresponding to each month corresponding to the historical monthly power consumption data; A loss function construction module, configured to construct a target loss function based on the target weight values, and add the target loss function to a preset initial long short-term memory network model to obtain a corresponding target long short-term memory network model; wherein, the target loss function includes a seasonal change amplitude penalty function, a time step change consistency loss function, and a weighted loss function, the seasonal change amplitude penalty function is used to measure the change amplitude of the energy consumption prediction values between adjacent months based on the target weight values, the time step change consistency loss function is used to measure the difference between the predicted value of the energy consumption change amount and the actual value of the energy consumption change amount between adjacent months, and the weighted loss function is used to measure the difference between the energy consumption prediction value and the actual energy consumption value within the same month based on the target weight values; An energy consumption prediction module, configured to train the target long short-term memory network model according to the target training set and the self-attention mechanism to obtain a corresponding trained model, and perform energy consumption prediction by using the trained model and the self-attention mechanism.

9. An electronic device, characterized in that, It includes: A memory, configured to store a computer program; A processor, configured to execute the computer program to implement the energy consumption prediction method based on the self-attention mechanism according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, For storing a computer program, the computer program, when executed by a processor, implements the energy consumption prediction method based on the self-attention mechanism according to any one of claims 1 to 7.