A method and apparatus for predicting power generation capacity.
By improving the Transformer model and using a continuous learning strategy, and combining local feature extraction with global time dependencies, the problems of accuracy and cross-seasonal adaptability in photovoltaic power generation prediction were solved, achieving higher accuracy and more stable photovoltaic power generation prediction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-26
- Publication Date
- 2026-03-10
AI Technical Summary
Existing photovoltaic power generation prediction accuracy is low, making it difficult to capture long-term time dependence and cross-seasonal changes, resulting in decreased prediction accuracy and catastrophic amnesia when weather changes and seasons change.
An improved Transformer model is used in conjunction with 1D convolution to extract local meteorological-power correlation features. A Transformer encoder is used to model global temporal dependence, and enhanced location encoding and continuous learning strategies are introduced. Historical samples are stored in a dynamic memory bank, and seasonal labels and sample priority are used for weighted sampling to enhance the model's cross-seasonal generalization ability.
It improves the accuracy and stability of photovoltaic power generation forecasting, effectively copes with changes in meteorological conditions and seasonal changes, reduces the model's forgetting of past scenarios, and improves the accuracy and robustness of forecasts.
Smart Images

Figure CN120875628B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of data prediction technology, and in particular relates to a method and apparatus for predicting power generation. Background Technology
[0002] Solar energy, as an ideal renewable energy source, occupies an important position in the global energy transition due to its abundant reserves and environmentally friendly characteristics. Photovoltaic power generation, as the core method of solar energy utilization, can not only alleviate the energy crisis caused by the shortage of traditional fossil fuels but also reduce greenhouse gas emissions and environmental problems such as acid rain. However, photovoltaic power generation is significantly affected by meteorological factors such as solar radiation intensity, temperature, and humidity, exhibiting high randomness, volatility, and intermittency. This characteristic makes it easy for large-scale photovoltaic power plants to impact the safe and stable operation of the power grid when connected to the grid. When the installed capacity of photovoltaic power exceeds 15% of the grid, power fluctuations may cause grid paralysis.
[0003] To address these issues, accurate photovoltaic (PV) power forecasting is necessary. From a grid operation perspective, short-term power forecasts (1-3 days ahead) provide crucial information for power dispatching departments, helping to optimize dispatch plans, reduce system reserve capacity, lower operating costs, and enhance the grid's ability to absorb new energy sources. From an industry development perspective, forecast results provide data support for PV power plant operation and maintenance, electricity market bidding, and other aspects, enhancing the competitiveness of PV power generation in the energy market. Furthermore, with the continuous growth of global PV installed capacity, high-precision forecasting technology plays a vital role in promoting PV as a mainstream energy source and ensuring the smooth progress of energy structure transformation.
[0004] However, the accuracy of current photovoltaic power generation forecasts is still relatively low, and no effective solutions have yet been proposed to improve the accuracy of photovoltaic power generation forecasts. Summary of the Invention
[0005] The purpose of this application is to provide a method and apparatus for predicting power generation, which can achieve accurate prediction of photovoltaic power generation.
[0006] This application provides a method and apparatus for predicting power generation, which is implemented as follows:
[0007] A method for predicting power generation capacity, comprising:
[0008] Acquire historical power data of photovoltaic power plants and historical meteorological data of the area;
[0009] Based on the sampling time, the historical power data and the historical meteorological data of the region are aligned to obtain the processed power data and meteorological data;
[0010] The processed power data features and the processed meteorological data statistical features are extracted by a feature extractor, and the processed power data features and the processed meteorological data statistical features are used as local features.
[0011] By improving the Transformer, global dependencies can be extracted from the extracted local features;
[0012] The data in the global dependency that are located at the nearest predetermined number of time steps are subjected to enhanced weight allocation to obtain the time-step weighted feature vector;
[0013] The time-step weighted feature vector is input into the feedforward neural network for calculation to obtain the prediction result. Based on the error between the prediction result and the actual result, the feature extractor, the improved Transformer and the feedforward neural network are trained.
[0014] After training, the power generation of the photovoltaic power station is predicted using the trained feature extractor, improved Transformer, and feedforward neural network.
[0015] A power generation prediction device, comprising:
[0016] The acquisition module is used to acquire historical power data of photovoltaic power plants and historical meteorological data of the area where they are located;
[0017] The processing module is used to align the historical power data and the historical meteorological data of the region according to the sampling time to obtain the processed power data and meteorological data.
[0018] The extraction module is used to extract the features of the processed power data and the statistical features of the processed meteorological data through the feature extractor, and to use the features of the processed power data and the statistical features of the processed meteorological data as local features.
[0019] The global module is used to extract global dependencies from the extracted local features by improving the Transformer;
[0020] The weighting module is used to assign enhanced weights to the data in the global dependency that are in the most recent predetermined number of time steps, so as to obtain the time-step weighted feature vector;
[0021] The calculation module is used to input the time-step weighted feature vector into the feedforward neural network for calculation to obtain the prediction result. Based on the error between the prediction result and the actual result, the feature extractor, the improved Transformer and the feedforward neural network are trained.
[0022] The prediction module is used to predict the power generation of the photovoltaic power station after training by using a trained feature extractor, an improved Transformer, and a feedforward neural network.
[0023] This application provides a method and apparatus for predicting power generation. The method involves extracting processed power data features and processed meteorological data statistical features using a feature extractor, and using these features as local features. Then, an improved Transformer is used to extract global dependencies from the extracted local features. Data within the nearest predetermined number of time steps in the global dependencies are weighted to obtain a time-step weighted feature vector. This time-step weighted feature vector is then input into a feedforward neural network for calculation to obtain a prediction result. Based on the error between the prediction result and the actual result, the feature extractor, the improved Transformer, and the feedforward neural network are trained. After training, the trained feature extractor, improved Transformer, and feedforward neural network are used to predict the power generation of the photovoltaic power station. Specifically, local meteorological-power correlation features were extracted, and global time dependence was modeled using a Transformer encoder. Enhanced location encoding was employed to accurately distinguish the relative importance of different time steps. Furthermore, a training strategy based on continuous learning was introduced, storing historical samples through a dynamic memory bank and weighting sampling based on seasonal labels and sample priorities to learn data patterns from different seasons in a balanced manner. Historical knowledge was transferred and preserved to avoid the model's "catastrophic forgetting" of typical scenarios from the past. This solved the technical problem of low accuracy in existing photovoltaic power generation predictions and achieved the technical effect of effectively improving the accuracy of photovoltaic power generation prediction results. Attached Figure Description
[0024] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 This is a flowchart of one embodiment of the power generation prediction method provided in this application;
[0026] Figure 2 This is a schematic diagram of the photovoltaic power prediction model provided in this application;
[0027] Figure 3 This is a schematic diagram of the data preprocessing workflow provided in this application;
[0028] Figure 4 This is a schematic diagram of the improved Transformer provided in this application;
[0029] Figure 5 This is a hardware structure block diagram of an electronic device for a method of predicting power generation provided in this application;
[0030] Figure 6 This is a schematic diagram of the module structure of one embodiment of the power generation prediction device provided in this application. Detailed Implementation
[0031] To enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this application.
[0032] Given the inaccuracy of current photovoltaic power generation forecasts, the main problems are as follows:
[0033] 1) Insufficient capture of time series dependencies: Photovoltaic power generation is highly time-dependent, affected by both short-term (e.g., the first 15 minutes, 1 hour) output fluctuations and long-term (e.g., seasonal changes, diurnal cycles). However, existing power forecasting only captures local time-series correlations, but has limited ability to model long-term dependencies and struggles to accurately distinguish the relative importance of different time steps. This results in a lag in predicting power fluctuations caused by sudden weather changes (e.g., cloud cover).
[0034] 2) Poor model generalization ability and susceptibility to seasonal and time-of-day changes: The periodic changes in photovoltaic power (such as the difference in output between summer and winter) cause the data distribution to shift dynamically over time. Existing models are mostly trained based on data from fixed time periods, which can easily lead to "catastrophic forgetting" when migrating across seasons. That is, training with new data will overwrite the memory of historical patterns, resulting in a decrease in the prediction accuracy of typical scenarios in the past.
[0035] To address the aforementioned issues, this paper presents an improved photovoltaic power generation forecasting method based on an enhanced Transformer and continuous learning approach. This method aims to improve forecast accuracy and cross-seasonal generalization under complex meteorological conditions. Specifically, an improved Transformer model is proposed, which combines 1D convolution to extract local meteorological-power correlation features and models global time dependencies through a Transformer encoder. Enhanced positional encoding (sine and cosine encoding + learnable encoding) is employed to accurately distinguish the relative importance of different time steps. Furthermore, a continuous learning-based training strategy is introduced, which stores historical samples through a dynamic memory and performs weighted sampling based on seasonal labels and sample priorities to learn data patterns from different seasons in a balanced manner. Historical knowledge is transferred and retained to avoid the model's "catastrophic forgetting" of typical past scenarios, thereby improving the stability of cross-seasonal forecasts.
[0036] Figure 1 This is a flowchart of one embodiment of the power generation prediction method provided in this application. Although this application provides method operation steps or apparatus structures as shown in the following embodiments or figures, more or fewer operation steps or module units may be included in the method or apparatus based on conventional or non-inventive effort. In steps or structures where there is no logically necessary causal relationship, the execution order of these steps or the module structure of the apparatus is not limited to the execution order or module structure described in the embodiments and figures of this application. When the method or module structure is applied in actual devices or terminal products, it can be executed sequentially or in parallel according to the method or module structure shown in the embodiments or figures (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed processing environment).
[0037] Specifically, such as Figure 1 As shown, the above-mentioned method for predicting power generation may include the following steps:
[0038] Step 101: Obtain historical power data of the photovoltaic power station and historical meteorological data of the area;
[0039] Step 102: Align the historical power data and the historical meteorological data of the region according to the sampling time to obtain the processed power data and meteorological data;
[0040] That is, we can first obtain the historical power of the photovoltaic power station and the historical meteorological data of the area (if the meteorological data is gridded, it is averaged according to the grid space), and then align the power and meteorological data according to the sampling time. Furthermore, we can zero out invalid power at night and use cubic spline functions to interpolate and complete missing meteorological data.
[0041] Specifically, based on the sampling time, the historical power data and the historical meteorological data of the region are aligned to obtain processed power data and meteorological data. This may include: if the historical meteorological data of the region is grid data, averaging it according to the grid space to obtain averaged historical meteorological data; aligning the averaged historical power data and the historical meteorological data of the region based on the sampling time; zeroing out the invalid nighttime power in the aligned historical power data to obtain processed power data; and interpolating and completing the missing meteorological data in the aligned historical meteorological data to obtain processed meteorological data.
[0042] Step 103: Extract the processed power data features and the processed meteorological data statistical features using the feature extractor, and use the processed power data features and the processed meteorological data statistical features as local features;
[0043] Specifically, feature engineering is performed to extract statistical and power characteristics from the meteorological data, seasonal information for each month is calculated, and finally, the power and meteorological data are standardized to eliminate the influence of different value ranges on the results. Training, validation, and test sets are then divided according to the time series. Meteorological data is used as the input sequence, and power data as the output sequence. Considering the need for short-term forecasting of photovoltaic power generation, the time period corresponding to the data sequence can be set to no more than 3 days.
[0044] The aforementioned feature extractor can be a two-layer one-dimensional convolutional neural network, wherein the first convolutional layer has 32 output channels, a kernel size of 3, and a padding size of 1; the first max pooling layer has a pooling kernel of 2 and a stride of 2; the second convolutional layer has 64 output channels, a kernel size of 3, and a padding size of 1; the second max pooling layer has a pooling kernel of 2 and a stride of 2.
[0045] Based on the feature extractor described above, the extracted power data features and the statistical features of the processed meteorological data can be extracted using the following formula:
[0046]
[0047] Where X is the input data, B is the batch size, L is the sequence length, F is the dimension of the input feature data, permute is the transpose function, ReLU is the activation function, MaxPool is the max pooling function, Conv is the convolution operation, and D represents the dimension.
[0048] That is, after transposing the data, it undergoes two consecutive "convolution-ReLU activation function calculation-max pooling" operations. A one-dimensional convolutional neural network is used for downsampling and local feature extraction, thereby reducing sequence length and computational complexity.
[0049] Step 104: Extract global dependencies from the extracted local features by improving the Transformer;
[0050] Step 105: Perform enhanced weight allocation on the data in the global dependency that are located at the nearest predetermined number of time steps to obtain the time-step weighted feature vector;
[0051] Step 106: Input the time-step weighted feature vector into the feedforward neural network for calculation to obtain the prediction result. Based on the error between the prediction result and the actual result, train the feature extractor, the improved Transformer and the feedforward neural network.
[0052] Step 107: After training is completed, the power generation of the photovoltaic power station is predicted by the trained feature extractor, improved Transformer and feedforward neural network.
[0053] In one implementation, the improved Transformer includes a position encoder composed of multiple stacked sub-encoders. Each sub-encoder includes a first sub-layer connection network structure and a second sub-layer connection network structure. The first sub-layer connection network structure consists of a multi-head self-attention mechanism, residual connections, and a normalization layer. The second sub-layer connection network structure consists of a feedforward neural network, a normalization layer, and residual connections. The position encoder architecture has an embedding dimension of 128, an attention head count of 8, an encoder layer count of 3, and an output dimension of 1 to achieve point prediction.
[0054] That is, each improved Transformer encoder contains two sub-layer connected network structures. The first sub-layer connected structure consists of a multi-head self-attention mechanism, residual connections, and a normalization layer. The second sub-layer connected structure consists of a feedforward neural network, a normalization layer, and residual connections. In implementation, position encoding can be calculated using a hybrid position encoder. Specifically, the position encoder can perform position encoding as follows:
[0055]
[0056] Among them, PE final For position encoders, PE static For static position sub-encoder, PE learned For learnable position sub-encoders, PE final By PEstatic and PE final superimposed, pos represents the position index of the vector in the position encoding matrix, i represents the dimension index in the position encoding vector, and d model represents the dimension of the embedded vector, and PE static captures the relative relationship between sequential meteorological data through the linear transformation properties of the sine and cosine functions;
[0057] Furthermore, the above-mentioned learnable position sub-encoder creates an embedding matrix W of size (max(len), d model ) in a randomly initialized manner pos , and W pos is updated through backpropagation during training, where max(len) represents the maximum number of time steps supported by the model. The i-th row (0 <= i <= max(len)) in this matrix corresponds to the learnable position encoding vector of the i-th position. During actual operation, according to the actual length seq len of the input sequence, a position index sequence is generated to obtain the corresponding learnable position encoding vector in the position embedding matrix, which can be expressed as:
[0058] ;
[0059] The matrix W pos is updated through backpropagation during training. By combining static encoding and learnable encoding, it not only retains the generalization ability of sine position encoding but also increases flexibility, enabling the model to adjust position representation according to specific tasks.
[0060] In one embodiment, data located in the nearest predetermined number of time steps in the global dependency relationship is subjected to enhanced weight assignment, and the time-step weighted feature vector can include:
[0061] S1: Define the global dependency relationship as , where B represents the batch size, L represents the time-step length, and D represents the feature dimension;
[0062] S2: Extract the matrix located in the last k time steps as ;
[0063] S3: Define the time trend weight vector as to represent the emphasis on the recent trend. Among them, when i < j, w i < w j ;
[0064] S4: Normalize W to obtain the final trend weight vector W recent , and according to the following formula, multiply T last by W recentMultiply them and sum them along the time step direction to obtain the time-step weighted eigenvector:
[0065]
[0066] Where o represents the time-step weighted feature vector.
[0067] Specifically, inputting the time-step weighted feature vector into a feedforward neural network for prediction to obtain the predicted power generation of the photovoltaic power station can include: inputting the time-step weighted feature vector into a three-layer feedforward neural network and scaling the output dimension to obtain the prediction result.
[0068]
[0069] in, For the prediction results, W1, W2, and W3 are weight matrices. b1 is the activation function, and b2 and b3 are bias vectors.
[0070] In the example above, after obtaining the global dependencies, we only focus on the last k time steps of data, thus highlighting the impact of recent weather trends on photovoltaic power generation. By enhancing the weight allocation through time steps, we achieve a stronger focus on recent features.
[0071] To enable the model to perceive the impact of seasonal changes on photovoltaic power generation, this example also adopts the idea of continuous learning to enhance the model's ability to process new data. Specifically, the model is divided into a snapshot model and a main model. The snapshot model represents the model trained on historical data to preserve old knowledge, while the main model is the main model trained to preserve new knowledge.
[0072] Based on this, the above method further includes: establishing a memory bank for the feature extractor, the improved Transformer, and the feedforward neural network;
[0073] The establishment of a memory bank for the feature extractor, the improved Transformer, and the feedforward neural network may include:
[0074] S1: Initialize a blank memory bank at the start of training;
[0075] S2: Update the memory bank when the following three conditions are met simultaneously: training has been performed for a predetermined number of rounds, the set update frequency has been reached, and the improvement rate of model performance has reached a preset rate.
[0076] Updating the memory bank can include:
[0077] S21: Calculate the sample priority of the data samples according to the following formula:
[0078]
[0079] Among them, w priority (x) i ) represents sample x i priority, Indicates sample x i The predicted value, It is a smoothing constant;
[0080] S22: Calculate the seasonal weights of the data samples according to the following formula:
[0081]
[0082] Among them, w season Seasonal weights, season(x) i ) represents sample x i The corresponding season.
[0083] S23: Based on sample priority and seasonal weight, determine the sampling weight of the data samples according to the following formula:
[0084]
[0085] Where, p i Indicates sample x i The sampling weights of the pair;
[0086] S24: During the update, calculate the sampling weight of each sample in the training set, sample according to the sampling weight, and replace the old samples in the memory with the sampled samples.
[0087] The aforementioned feature extractor, improved Transformer, and feedforward neural network model can all be composed of a snapshot model and a main model. Correspondingly, training the feature extractor, improved Transformer, and feedforward neural network model can include:
[0088] Step 1: Iterate through the training data batches and determine the comprehensive loss according to the following formula:
[0089]
[0090] Among them, L new Indicates the overall loss, B represents the batch size, and y represents the total loss. i This represents the true value of the i-th sample. f represents the model's prediction for the i-th sample. t f represents the predicted value of the snapshot model. s This represents the predicted value from the main model. This represents the dependency weight value on the old data.
[0091] Step 2: Perform backpropagation and parameter update on the main model based on the comprehensive loss.
[0092] Specifically, backpropagation and parameter updates are performed on the main model, including:
[0093] Step 21: If the memory bank is not empty, randomly sample a batch of data from the memory bank;
[0094] Step 22: Input a randomly sampled batch of data into the main model;
[0095] Step 23: Calculate the memory playback loss function according to the following formula:
[0096]
[0097] Among them, L re This represents the memory playback loss function. For playback weights, M represents the amount of data randomly sampled from the memory bank;
[0098] Step 24: Perform backpropagation based on the memory playback loss to update the main model.
[0099] Training the feature extractor, the improved Transformer, and the feedforward neural network model may further include: updating the snapshot model every predetermined time interval, copying the parameters of the main model to the snapshot model, and, if the model performance does not improve in multiple consecutive rounds, initiating an early stop mechanism to prevent overfitting, thereby obtaining the trained main model, wherein the main model is used for power generation prediction.
[0100] The above method will be described below with reference to a specific embodiment. However, it should be noted that this specific embodiment is only for better illustration of this application and does not constitute an improper limitation of this application.
[0101] This paper proposes a short-term photovoltaic power generation prediction method based on improved Transformer and continuous learning to address the catastrophic forgetting problem caused by seasonal changes in meteorological characteristics. By establishing a multi-scale correlation between meteorological elements and power generation through a hybrid convolution-Transformer architecture, the interference of meteorological trend changes in different seasons is eliminated, thereby improving prediction accuracy and effectively reducing performance degradation caused by seasonal transitions, providing reliable technical support for photovoltaic power prediction.
[0102] The model structure provided in this example can be as follows: Figure 2 As shown, it may include the following steps:
[0103] 1) Data preprocessing:
[0104] The data preprocessing process can be as follows: Figure 3 As shown, the process first acquires historical power data of the photovoltaic power station and historical meteorological data of the surrounding area (if the meteorological data is gridded, it is averaged according to the grid space). Power and meteorological data are aligned according to the sampling time. Invalid power at night is zeroed out, and missing meteorological data is interpolated using cubic spline functions. Then, feature engineering is performed to extract statistical and power characteristics from the meteorological data, and seasonal information for each month is calculated. Finally, the power and meteorological data are standardized to eliminate the influence of different value ranges on the results. Training, validation, and test sets are then divided according to the time series. Meteorological data serves as the input sequence, and power data as the output sequence. To focus on short-term photovoltaic power generation forecasting, the time period corresponding to the data sequence can be set to no more than 3 days.
[0105] 2) Local Feature Extraction: The feature extractor consists of a two-layer one-dimensional convolutional neural network. Let the input data be... Where B = batch_size, L = sequence length, and F = input feature dimension, the feature extractor calculation process is as follows:
[0106]
[0107] In other words, the data is transposed and then subjected to two consecutive "convolution-ReLU activation function calculation-max pooling" operations. A one-dimensional convolutional neural network is used for downsampling and local feature extraction to reduce sequence length and computational complexity.
[0108] 3) Global Dependency Extraction: This module accepts the output of the feature extractor and consists of multiple stacked improved Transformer encoders. The specific structure can be as follows: Figure 4 As shown, each improved Transformer encoder contains two sub-layer connected network structures. The first sub-layer connected structure consists of a multi-head self-attention mechanism, residual connections, and a normalization layer. The second sub-layer connected structure consists of a feedforward neural network, a normalization layer, and residual connections. Position encoding is calculated using a hybrid position encoder, and the specific calculation method is as follows:
[0109]
[0110] Among them, PE final For position encoders, the static position encoder PE is used. static and learnable positional coding PE learned It consists of two superimposed parts: pos represents the position index of the vector in the position encoding matrix, i represents the dimension index in the position encoding vector, and d represents the position index. modelRepresents the embedding vector dimension, static positional encoding (PE) static The relative relationships between time-series meteorological data are captured by utilizing the linear transformation properties of sine and cosine functions; the learnable position encoder PE learned First, create a randomized initialization object of size (max(len), d)... model The embedding matrix W pos Here, max(len) represents the maximum number of time steps the model can support, and the i-th row (0 <= i <= max(len)) in this matrix corresponds to the learnable positional encoding vector at the i-th position. In actual runtime, the actual length of the input sequence (seq) will be used. len Generate a position index sequence, which is from 0 to seq. len The integer -1 can be used to obtain the corresponding learnable positional encoding vector in the positional embedding matrix, as shown in Equation 10:
[0111]
[0112] Due to matrix W pos During training, the encoder is updated via backpropagation, hence it is called a learnable encoder. It can adaptively learn a unique representation for each position and capture task-specific positional patterns. In this example, static encoding is combined with learnable encoding, which retains the generalization ability of sinusoidal positional encoding while adding flexibility, allowing the model to adjust the positional representation according to the specific task.
[0113] After data preprocessing, the output data is first added to the position vector after position encoding to obtain the encoder's input matrix X. Then, it enters the self-attention layer. The self-attention layer first creates multiple query, key, and value matrices for X, namely: Q (i) K (i) and V (i) These three matrices are obtained by multiplying X by different weight matrices, as shown in Formula 11:
[0114]
[0115] Among them, W Q W K W V It is a weight matrix learned through training, used to map the input matrix to the query, key, and value spaces. Then u, for each vector x in the input matrix X. i Calculate its query vector q i With all other vectors x j The key vector k jThe correlation between them. This correlation is determined by q. i With key vector k j The inner product is used to represent the attention score, which measures the correlation between the input meteorological data. The specific calculation is shown in Formula 12:
[0116]
[0117] To maintain the stability of the attention score, it can be scaled according to the following formula 13:
[0118]
[0119] The scaled attention score is normalized using the Softmax function to generate single-head attention, as shown in Equation 14:
[0120]
[0121] Finally, the multiple single-head attentions are concatenated column by column to form a multi-head attention output as shown in Formula 15:
[0122]
[0123] Where h represents the number of attention heads.
[0124] The multi-head attention output, after layer normalization and residual connection, forms the output of the first sub-layer of the encoder. The second sub-layer of the encoder processes this input through a feedforward neural network, as shown in Equation 16.
[0125]
[0126] Among them, W i b i Let represent the weight matrix and bias vector of the i-th layer, respectively. The output of the feedforward neural network is normalized and connected to the residuals to obtain the output of the second sub-layer of the encoder.
[0127] That is, based on the long-term dependencies captured by Transformer in meteorological data, its enhanced location coding is more flexible than a single fixed coding method and can adapt to the periodic and random changes in photovoltaic power generation data.
[0128] 4) Recent Trend Extraction:
[0129] To highlight the impact of recent weather trends on photovoltaic power generation, after obtaining the global dependency, we can focus only on the data of the last k time steps.
[0130] Let the output of the global dependency extraction module be , where B represents the batch size, L represents the length of the time step, and D represents the feature dimension; then the matrix of the last k time steps is extracted as . Define the time trend weight vector as , where, when i < j, w i < w j , to indicate the emphasis on the recent trend. Perform Softmax normalization on W to obtain the final trend weight vector W recent . Multiply this tensor by T last and sum along the time step direction to obtain the time step weighted feature vector:
[0131]
[0132] where o represents the time step weighted feature vector.
[0133] In this step, by time step enhanced weight assignment, enhanced attention to recent features is achieved. Finally, scale the output dimension through a 3-layer feedforward neural network to obtain the predicted output:
[0134]
[0135] where o is the time step weighted feature vector, W1, W2, and W3 are weight matrices, is the ReLU activation function, b i (i = 1, 2, 3) is the bias vector.
[0136] To enable the model to perceive the impact of seasonal changes on photovoltaic power generation, in this example, a snapshot model is used to represent the model trained on historical data to preserve old knowledge, and the main model is the main model for training to preserve new knowledge. Further, to enable the model to learn new data and avoid forgetting old knowledge when new data keeps coming, in this example, a combined mechanism of knowledge distillation and memory replay is used to prevent the catastrophic forgetting phenomenon in continuous learning.
[0137] Specifically, in this example, the snapshot model does not participate in gradient updates and its parameters are frozen; the main model is the model currently being trained and needs to learn new data while retaining the knowledge of old data. At initialization, the snapshot model is a copy of the main model. During the training process, the snapshot model is updated every 5 epochs, and the current parameters of the student model are copied to the snapshot model. In this way, the snapshot model memorizes all the knowledge (including new knowledge) learned by the main model so far. In the subsequent training, the main model mimics this updated snapshot model, thus achieving a balance between old knowledge (preserved by the snapshot model) and new knowledge.
[0138] Specifically, at the beginning of training, a blank memory can be initialized, indicating that the model has no data memory at the start of training. The memory is updated when the following three conditions are met simultaneously:
[0139] Condition 1: Training has already gone through a certain number of rounds (epoch>n);
[0140] Condition 2: Reach the set update frequency (every m rounds);
[0141] Condition 3: Model performance has improved.
[0142] In implementation, the memory update adopts a sampling strategy based on sample priority, and the specific calculation method may include:
[0143] S1: Priority of sample calculation:
[0144] The model uses the reciprocal of the absolute value of the predicted value as a measure of sample priority. Specifically, it assumes the model should focus more on decision boundary samples, i.e., samples during sunrise / sunset, when the power prediction is close to 0. Therefore, in this example, the sample weight is set inversely proportional to the absolute value of the predicted value; the smaller the absolute value of the predicted value, the greater the sampling weight. To prevent the denominator from being zero, a small constant can be added to the denominator of the formula, as shown in Equation 19. :
[0145]
[0146] S2: Calculate the seasonal weights for the sample:
[0147] To focus on the impact of seasonal variations on photovoltaic power generation patterns, the model uses Equation 20 to calculate the seasonal weights of the samples:
[0148]
[0149] For example, setting the weight of the current season's samples to 5 times that of the non-seasonal samples allows the model to focus on the current data distribution while retaining a small number of historical samples to prevent seasonal forgetting.
[0150] S3: Combined weighted sampling:
[0151] To simultaneously reflect both the sample's own priority and seasonal weight, the above weights can be combined according to Formula 21 during sampling to calculate the sampling probability:
[0152]
[0153] This approach balances seasonal relevance and sample priority, resulting in a bias towards high-value samples.
[0154] During each update, the weight of each sample in the entire training set can be calculated, and then min (memory set capacity, training set size) samples can be sampled based on these weights. The sampled samples then replace the old samples in the memory.
[0155] In the example above, on the one hand, a snapshot model is used to constrain the training of the main model on new data so that it does not forget old knowledge; on the other hand, the main model is retrained directly using old data stored in the memory bank. The simultaneous use of these two mechanisms can better solve the problem of catastrophic forgetting.
[0156] This example provides methods for training the model, which may include:
[0157] S1: Training on new data:
[0158] Iterate through the training data batches, calculate the MSE loss and distillation loss according to Formula 22, and perform backpropagation and parameter updates based on the combined loss:
[0159]
[0160] Where B is the batch size, y i Let i be the true value of the i-th sample. Let be the predicted value of the student model for the i-th sample. The distillation weights are larger, indicating a greater tendency to learn from older data. The MSE loss component in the loss function ensures the model accurately predicts the current data, while the distillation loss component constrains the model's update direction, preventing the main model from over-adapting to new data and forgetting old patterns.
[0161] S2: Memory Replay Training
[0162] When the memory is not empty, a batch of data is randomly sampled from the memory, and this batch of replay data is input into the current model. The replay loss is calculated and backpropagation is used to update the model. Replay training allows the model to adapt to new data without forgetting the old knowledge in the memory.
[0163] The replay loss function can be expressed as:
[0164]
[0165] in, For replay weights, M is the number of samples in the replay batch.
[0166] S3: Model Selection and Memory Update:
[0167] The model's performance metrics are calculated on the validation set. If performance improves, the current model is saved as the best model, and it is determined whether the memory update condition is met. If it is met, the memory is updated by weighted sampling. If performance does not improve, the early stopping count is incremented by 1. When the early stopping count exceeds a set threshold, the early stopping mechanism is activated, and training is stopped.
[0168] S4: Snapshot Model Update:
[0169] The snapshot model is updated every 5 epochs, and the parameters of the master model are copied to the snapshot model.
[0170] S5: Load the test set and predict photovoltaic power based on the trained master model.
[0171] In the example above, by combining local feature extraction from a 1D convolutional neural network with global temporal modeling using a Transformer, multi-scale feature extraction and high-quality spatiotemporal representation are achieved, solving the problem of joint modeling of short-term meteorological fluctuations and long-term seasonal patterns in photovoltaic data. The Transformer architecture optimizes positional encoding by employing an enhancement mode combining static and learnable encoding, addressing the positional invariance deficiency of existing Transformers in time series prediction and improving the model's noise resistance and generalization capabilities. Furthermore, a time-step weighting mechanism is adopted to fully utilize recent data information, improving prediction accuracy. By combining seasonal factors and sample priority factors in a sampling strategy, dual focus on current meteorological patterns and high-value samples is achieved. Combined with a dynamic sample memory and asynchronous update strategy (triggered only when performance is improved), stable year-round photovoltaic forecasts that are aware of seasonal changes are realized. By establishing a closed-loop optimization system for knowledge evolution, model parameters are synchronously snapshotted every 5 epochs. New sample training uses "main loss + distillation loss" to reinforce continuous learning. Combined with a memory replay mechanism, catastrophic forgetting is effectively suppressed, improving the model's robustness and prediction accuracy in dynamic scenarios such as seasonal changes.
[0172] To illustrate with a specific example, we select photovoltaic (PV) power generation data. This dataset contains the annual power generation data of a PV power plant from January 1, 2024 to December 31, 2024, with a data interval of 15 minutes. For meteorological data, we select the first meteorological source in the dataset. This dataset contains meteorological forecast data from January 1, 2024 to December 30, 2024, with a data interval of 1 hour. Specific meteorological elements are shown in Table 1 below.
[0173] Table 1
[0174]
[0175] Based on this, this example provides a method for predicting photovoltaic power generation, which may include the following steps:
[0176] S1: Data Preprocessing
[0177] Meteorological and power data are read in. Since the meteorological data is in an 11×11 grid, it is averaged. Power and meteorological data are aligned according to sampling time, with a uniform 15-minute time interval. Invalid nighttime power data is zeroed out, and missing meteorological data is interpolated using cubic spline functions. Then, feature engineering is performed to extract statistical features from the meteorological data (such as calculating the rate of change, 3-hour rolling average, and 3-hour rolling maximum for each meteorological channel) and power features. Seasonal labels are assigned to the data by month. Finally, power and meteorological data are standardized to eliminate the influence of different value ranges on the results. The dataset is divided into training, validation, and test sets according to time series, with meteorological data as the input sequence and power data as the output sequence. Specifically, data before November 15, 2024, is used as the training set; data from November 15 to December 1, 2024, is used as the validation set; and data after December 1, 2024, is used as the test set.
[0178] S2: Local Feature Extraction
[0179] Local feature extraction is performed using formulas 1 to 5 above. The first convolutional layer has 32 output channels, a kernel size of 3, and a padding size of 1. The first max pooling layer has a pooling kernel of 2 and a stride of 2. The second convolutional layer has 64 output channels, a kernel size of 3, and a padding size of 1. The second max pooling layer has a pooling kernel of 2 and a stride of 2.
[0180] S3: Global Dependency Extraction
[0181] Using formulas 6 to 16 and referring to... Figure 4 The model structure in the code completes global temporal dependency modeling. Specifically, the improved Transformer architecture has an embedding dimension of 128, an attention head of 8, an encoder layer of 3, and an output dimension of 1 to achieve single-value prediction.
[0182] S4: Recent Trend Extraction:
[0183] Let the time step parameter k=3, meaning we focus on the data from the last three time steps, and perform time-weighted aggregation according to Formula 17. Finally, obtain the predicted output according to Formula 18.
[0184] S5: Memory Replay
[0185] At the start of training, an empty memory is initialized, indicating that the model has no data stored in it at the beginning of training. The memory is updated when all three of the following conditions are met:
[0186] Condition 1: Training has been conducted for a certain number of epochs (epoch>5);
[0187] Condition 2: Reach the set update frequency (every round);
[0188] Condition 3: Model performance has improved.
[0189] If the conditions are met, data is sampled and the memory is updated according to Formulas 19 to 21, where the capacity of the memory is set to 1000, that is, a maximum of 1000 samples are retained.
[0190] S6: Model Training
[0191] During training, the batch size of each input sample is 128, the length of the input sequence is 96 (i.e., the power output predicted 24 hours later), the dropout rate is set to 0.3, the learning rate is set to 0.0003, and the maximum number of training epochs is set to 100.
[0192] The training data batches are iterated through, and the MSE loss and distillation loss are calculated according to Formula 22. Then, backpropagation and parameter updates are performed based on the loss function values. The distillation weights are... This is used to control the proportion of knowledge distillation loss in the total loss.
[0193] When the memory is not empty, a batch of data is randomly sampled from the memory, and this batch of replay data is input into the current model. The replay loss is calculated according to Formula 23, and the model is updated via backpropagation. The replay weights are... This is used to control the weight of the replay samples in the loss calculation. The number of samples in the replay batch is 128.
[0194] Calculate the model's performance metrics on the validation set. If performance improves, save the current model as the best model and check if the memory update condition is met. If it is, update the memory using weighted sampling. If performance does not improve, increment the early stopping count by 1. When the early stopping count is greater than 10, activate the early stopping mechanism and stop training.
[0195] For the snapshot model, it can be updated every 5 epochs by copying the parameters of the main model to the snapshot model. Then, the test set is loaded, and photovoltaic power is predicted based on the trained main model.
[0196] Based on the same dataset, the method in this example is compared with other methods. Specifically, three commonly used regression metrics—RMSE, MAE, and R2—are used to evaluate the model performance. The calculation formulas for the evaluation metrics are shown in Table 2 below:
[0197] Table 2
[0198]
[0199] Table 3 below shows the comparative experimental results. The experimental results prove that the method in this example performs well in error control (RMSE / MAE) and data fitting (R2), and its prediction performance is superior to existing intelligent prediction algorithms. It can predict photovoltaic power generation more accurately.
[0200] Table 3
[0201]
[0202] It can be executed on mobile terminals, computer terminals, or similar computing devices. Taking its operation on electronic devices as an example... Figure 5 This is a hardware structure block diagram of an electronic device for a method of predicting power generation provided in this application. (See diagram for example.) Figure 5 As shown, the electronic device 10 may include one or more (only one is shown in the figure) processors 02 (processors 02 may include, but are not limited to, processing devices such as microprocessors (MCUs) or programmable logic devices (FPGAs), a memory 04 for storing data, and a transmission module 06 for communication functions. Those skilled in the art will understand that... Figure 5 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device described above. For example, electronic device 10 may also include... Figure 5 The more or fewer components shown, or having the same Figure 5 The different configurations shown.
[0203] The memory 04 can be used to store software programs and modules of application software, such as the program instructions / modules corresponding to the power generation prediction method in this embodiment. The processor 02 executes various functional applications and data processing by running the software programs and modules stored in the memory 04, thereby realizing the power generation prediction method of the aforementioned application. The memory 04 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 04 may further include memory remotely located relative to the processor 02, and these remote memories can be connected to the electronic device 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0204] The transmission module 06 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the electronic device 10. In one example, the transmission module 06 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission module 06 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0205] At the software level, the aforementioned power generation prediction device can be as follows: Figure 6 As shown, it includes:
[0206] The acquisition module 601 is used to acquire historical power data of the photovoltaic power station and historical meteorological data of the area where it is located;
[0207] Processing module 602 is used to align the historical power data and the historical meteorological data of the region according to the sampling time to obtain processed power data and meteorological data;
[0208] The extraction module 603 is used to extract the processed power data features and the processed meteorological data statistical features through the feature extractor, and to use the processed power data features and the processed meteorological data statistical features as local features.
[0209] Global module 604 is used to extract global dependencies from extracted local features by improving the Transformer;
[0210] The weighting module 605 is used to enhance the weight allocation of data in the global dependency that are located at the nearest predetermined number of time steps, so as to obtain the time-step weighted feature vector.
[0211] The calculation module 606 is used to input the time-step weighted feature vector into the feedforward neural network for calculation to obtain the prediction result, and to train the feature extractor, the improved Transformer and the feedforward neural network based on the error between the prediction result and the actual result.
[0212] The prediction module 607 is used to predict the power generation of the photovoltaic power station after training by using the trained feature extractor, improved Transformer and feedforward neural network.
[0213] In one embodiment, the processing module 602 may, if the historical meteorological data of the region is grid data, perform mean processing according to the grid space to obtain mean historical meteorological data; align the mean historical power data with the historical meteorological data of the region according to the sampling time; zero-value the invalid nighttime power in the aligned historical power data to obtain processed power data; and interpolate and complete the missing meteorological data in the aligned historical meteorological data to obtain processed meteorological data.
[0214] In one implementation, the feature extractor is a two-layer one-dimensional convolutional neural network, wherein the first convolutional layer has 32 output channels, a kernel size of 3, and a padding size of 1; the first max pooling layer has a pooling kernel of 2 and a stride of 2; the second convolutional layer has 64 output channels, a kernel size of 3, and a padding size of 1; the second max pooling layer has a pooling kernel of 2 and a stride of 2.
[0215] In one implementation, the extraction module 603 can specifically perform feature extraction according to the following formula:
[0216]
[0217] Where X is the input data, B is the batch size, L is the sequence length, F is the dimension of the input feature data, permute is the transpose function, ReLU is the activation function, MaxPool is the max pooling function, Conv is the convolution operation, and D represents the dimension.
[0218] In one implementation, the improved Transformer includes a position encoder composed of multiple stacked sub-encoders. Each sub-encoder includes a first sub-layer connection network structure and a second sub-layer connection network structure. The first sub-layer connection network structure consists of a multi-head self-attention mechanism, residual connections, and a normalization layer. The second sub-layer connection network structure consists of a feedforward neural network, a normalization layer, and residual connections. The position encoder architecture has an embedding dimension of 128, an attention head count of 8, an encoder layer count of 3, and an output dimension of 1 to achieve point prediction.
[0219] In one embodiment, the position encoder described above can perform position encoding in the following manner:
[0220]
[0221] Among them, PE final For position encoders, PE static For static position sub-encoder, PE learned For learnable position sub-encoders, PE finalComposed of PE static and PE final superimposed, pos represents the position index of the vector in the position encoding matrix, i represents the dimension index in the position encoding vector, and d model represents the dimension of the embedded vector, and PE static captures the relative relationship between sequential meteorological data through the linear transformation properties of the sine and cosine functions;
[0222] The learnable position sub-encoder creates an embedding matrix W of size (max(len), d model ) in a randomly initialized manner, and W pos is updated through backpropagation during training. Here, max(len) represents the maximum number of time steps supported by the model. The i-th row (0 <= i <= max(len)) in this matrix corresponds to the learnable position encoding vector of the i-th position. During actual operation, a position index sequence is generated according to the actual length seq pos of the input sequence to obtain the corresponding learnable position encoding vector in the position embedding matrix. len
[0223] In one embodiment, the weighting module 605 can define the global dependency as , where B represents the batch size, L represents the length of the time step, and D represents the feature dimension; the matrix located in the last k time steps is extracted as ; the time trend weight vector is defined as to represent the emphasis on the recent trend. Here, when i < j, w i < w j ; W is normalized to obtain the final trend weight vector W recent , and T last is multiplied by W recent and summed along the time step direction to obtain the time step weighted feature vector:
[0224]
[0225] where o represents the time step weighted feature vector.
[0226] In one embodiment, the prediction module 607 can specifically input the time step weighted feature vector into a three-layer feed-forward neural network to scale the output dimension and obtain the prediction result:
[0227]
[0228] where is the prediction result, and W1, W2, and W3 are weight matrices, b1 is the activation function, and b2 and b3 are bias vectors.
[0229] In one embodiment, the prediction of the above-mentioned power generation can also establish a memory bank for the feature extractor, the improved Transformer, and the feedforward neural network; wherein, establishing a memory bank for the feature extractor, the improved Transformer, and the feedforward neural network includes: initializing a blank memory bank at the start of training; updating the memory bank when the following three conditions are met simultaneously, wherein the three conditions include: training has been performed for a predetermined number of rounds, a set update frequency has been reached, and the improvement ratio of model performance has reached a preset ratio; wherein updating the memory bank includes: calculating the sample priority of data samples according to the following formula:
[0230]
[0231] Among them, w priority (x) i ) represents sample x i priority, Indicates sample x i The predicted value, It is a smoothing constant;
[0232] The seasonal weights of the data samples are calculated using the following formula:
[0233]
[0234] Among them, w season Seasonal weights, season(x) i ) represents sample x i The corresponding season.
[0235] Based on sample priority and seasonal weight, the sampling weight of the data samples is determined according to the following formula:
[0236]
[0237] Where, p i Indicates sample x i The sampling weights of the pair;
[0238] During the update, the sampling weights of each sample in the training set are calculated, and sampling is performed according to the sampling weights. The old samples in the memory are replaced by the samples obtained from the sampling.
[0239] In one implementation, the feature extractor, the improved Transformer, and the feedforward neural network model all consist of a snapshot model and a main model. Accordingly, training the feature extractor, the improved Transformer, and the feedforward neural network model may include:
[0240] Iterate through the batches of training data and determine the comprehensive loss using the following formula:
[0241]
[0242] Among them, L new Indicates the overall loss, B represents the batch size, and y represents the total loss. i This represents the true value of the i-th sample. f represents the model's prediction for the i-th sample. t f represents the predicted value of the snapshot model. s This represents the predicted value from the main model. This represents the dependency weight value on the old data.
[0243] The main model is backpropagated and its parameters are updated based on the comprehensive loss.
[0244] In one implementation, backpropagation and parameter updates of the main model may include:
[0245] If the memory bank is not empty, a batch of data is randomly sampled from the memory bank;
[0246] Input a randomly sampled batch of data into the main model;
[0247] Calculate the memory playback loss function using the following formula:
[0248]
[0249] Among them, L re This represents the memory playback loss function. For playback weights, M represents the amount of data randomly sampled from the memory bank;
[0250] Backpropagation is performed based on the memory playback loss to update the main model.
[0251] In one implementation, training the feature extractor, the improved Transformer, and the feedforward neural network model includes: updating the snapshot model every predetermined time interval, copying the parameters of the main model to the snapshot model, and, if the model performance does not improve in multiple consecutive rounds, initiating an early stop mechanism to prevent overfitting, thereby obtaining the trained main model, wherein the main model is used for power generation prediction.
[0252] The embodiments of this application also provide a specific implementation of an electronic device capable of implementing all steps in the power generation prediction method of the above embodiments. The electronic device specifically includes: a processor, a memory, a communication interface, and a bus; wherein the processor, memory, and communication interface communicate with each other through the bus; the processor is used to call a computer program in the memory, and when the processor executes the computer program, it implements all steps in the power generation prediction method of the above embodiments. For example, when the processor executes the computer program, it implements the following steps:
[0253] Step 1: Obtain historical power data of the photovoltaic power station and historical meteorological data of the area;
[0254] Step 2: Align the historical power data and the historical meteorological data of the region according to the sampling time to obtain the processed power data and meteorological data;
[0255] Step 3: Extract the processed power data features and the processed meteorological data statistical features using a feature extractor, and use the processed power data features and the processed meteorological data statistical features as local features;
[0256] Step 4: Extract global dependencies from the extracted local features by improving the Transformer;
[0257] Step 5: Perform enhanced weight allocation on the data in the global dependency that are in the most recent predetermined number of time steps to obtain the time-step weighted feature vector;
[0258] Step 6: Input the time-step weighted feature vector into the feedforward neural network for calculation to obtain the prediction result. Based on the error between the prediction result and the actual result, train the feature extractor, the improved Transformer and the feedforward neural network.
[0259] Step 7: After training is completed, the power generation of the photovoltaic power station is predicted by the trained feature extractor, improved Transformer and feedforward neural network.
[0260] Embodiments of this application also provide a computer-readable storage medium capable of implementing all steps of the power generation prediction method in the above embodiments. The computer-readable storage medium stores a computer program that, when executed by a processor, implements all steps of the power generation prediction method in the above embodiments. For example, when the processor executes the computer program, it implements the following steps:
[0261] Step 1: Obtain historical power data of the photovoltaic power station and historical meteorological data of the area;
[0262] Step 2: Align the historical power data and the historical meteorological data of the region according to the sampling time to obtain the processed power data and meteorological data;
[0263] Step 3: Extract the processed power data features and the processed meteorological data statistical features using a feature extractor, and use the processed power data features and the processed meteorological data statistical features as local features;
[0264] Step 4: Extract global dependencies from the extracted local features by improving the Transformer;
[0265] Step 5: Perform enhanced weight allocation on the data in the global dependency that are in the most recent predetermined number of time steps to obtain the time-step weighted feature vector;
[0266] Step 6: Input the time-step weighted feature vector into the feedforward neural network for calculation to obtain the prediction result. Based on the error between the prediction result and the actual result, train the feature extractor, the improved Transformer and the feedforward neural network.
[0267] Step 7: After training is completed, the power generation of the photovoltaic power station is predicted by the trained feature extractor, improved Transformer and feedforward neural network.
[0268] As described above, this embodiment of the application extracts processed power data features and processed meteorological data statistical features using a feature extractor, and uses these features as local features. Then, an improved Transformer extracts global dependencies from the extracted local features. Data within the nearest predetermined number of time steps in the global dependencies are weighted to obtain a time-step weighted feature vector. This time-step weighted feature vector is then input into a feedforward neural network for calculation to obtain a prediction result. Based on the error between the prediction result and the actual result, the feature extractor, the improved Transformer, and the feedforward neural network are trained. After training, the trained feature extractor, improved Transformer, and feedforward neural network are used to predict the power generation of the photovoltaic power station. Specifically, local meteorological-power correlation features were extracted, and global time dependence was modeled using a Transformer encoder. Enhanced location encoding was employed to accurately distinguish the relative importance of different time steps. Furthermore, a training strategy based on continuous learning was introduced, storing historical samples through a dynamic memory bank and weighting sampling based on seasonal labels and sample priorities to learn data patterns from different seasons in a balanced manner. Historical knowledge was transferred and preserved to avoid the model's "catastrophic forgetting" of typical scenarios from the past. This solved the technical problem of low accuracy in existing photovoltaic power generation predictions and achieved the technical effect of effectively improving the accuracy of photovoltaic power generation prediction results.
[0269] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on its differences from other embodiments. In particular, hardware + program embodiments are relatively simple in description because they are fundamentally similar to method embodiments; relevant parts can be referred to the descriptions in the method embodiments.
[0270] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0271] While this application provides the method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-inventive labor. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual device or client product execution, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment).
[0272] While this specification provides method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes said elements is not excluded.
[0273] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, in implementing the embodiments of this specification, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0274] Those skilled in the art will also know that, besides implementing the controller using purely computer-readable program code, the same functions can be achieved by logically programming the method steps, making the controller function as logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers (PLCs), and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the devices within it used to implement various functions can also be considered structures within that hardware component. Alternatively, the devices used to implement various functions can be considered as both software modules implementing the method and structures within a hardware component.
[0275] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0276] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, the embodiments of this specification can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, the embodiments of this specification can take the form of computer program products implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0277] The embodiments described in this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. The embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0278] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the embodiments in this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0279] The above description is merely an embodiment of the present specification and is not intended to limit the embodiments of the present specification. For those skilled in the art, various modifications and variations can be made to the embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of the embodiments of the present specification should be included within the scope of the claims of the embodiments of the present specification.
Claims
1. A method of predicting power generation, characterized by, The method comprises the following steps: acquiring historical power data of a photovoltaic power station and historical meteorological data of a region where the photovoltaic power station is located; aligning the historical power data and the historical meteorological data of the region according to a sampling time to obtain processed power data and processed meteorological data; extracting features of the processed power data and statistical features of the processed meteorological data by using a feature extractor, and taking the features of the processed power data and the statistical features of the processed meteorological data as local features; extracting global dependency relationships from the extracted local features by using an improved Transformer; performing enhancement weight allocation on data located in a latest predetermined number of time steps in the global dependency relationships to obtain a time step weighted feature vector; inputting the time step weighted feature vector into a feedforward neural network to perform calculation and obtain a prediction result, and training the feature extractor, the improved Transformer and the feedforward neural network based on an error between the prediction result and an actual result; after the training is completed, predicting power generation of the photovoltaic power station by using the trained feature extractor, the improved Transformer and the feedforward neural network; wherein the feature extractor, the improved Transformer and the feedforward neural network model are composed of a snapshot model and a main model, and the training of the feature extractor, the improved Transformer and the feedforward neural network model comprises the following steps: iterating through a training data batch, and determining a comprehensive loss according to the following formula: where L new represents the comprehensive loss, B represents the batch size, y i represents the true value of the i-th sample, represents the prediction value of the i-th sample by the model, f t represents the prediction value of the snapshot model, f s represents the prediction value of the main model, represents the dependency weight value on old data; performing back propagation and parameter updating on the main model according to the comprehensive loss.
2. The method of claim 1, wherein, aligning the historical power data and the historical meteorological data of the region according to a sampling time to obtain processed power data and processed meteorological data, which comprises the following steps: in the case that the historical meteorological data of the region is grid data, performing mean value processing according to a grid space to obtain mean value processed historical meteorological data; aligning the mean value processed historical power data and the historical meteorological data of the region according to a sampling time; performing zero value processing on invalid power in the aligned historical power data to obtain processed power data; performing interpolation completion processing on missing meteorological data in the aligned historical meteorological data to obtain processed meteorological data.
3. The method of claim 1, wherein, The feature extractor is a two-layer one-dimensional convolutional neural network, wherein the output channel number of a first layer convolutional layer is 32, the convolution kernel size is 3, and the padding size is 1; the pooling kernel of a first layer maximum pooling layer is 2, and the step length is 2; the output channel number of a second layer convolutional layer is 64, the convolution kernel size is 3, and the padding size is 1; the pooling kernel of a second layer maximum pooling layer is 2, and the step length is 2.
4. The method of claim 3, wherein, The feature extractor extracts features of the processed power data and statistical features of the processed meteorological data according to the following formula: wherein X is input data, B is batch size, L is sequence length, F is dimension of input feature data, permute is a transposition function, ReLU is an activation function, MaxPool is maximum pooling, Conv is convolution operation, and D represents dimension. 5. The method of claim 1, wherein, The improved Transformer includes a position encoder stacked by a plurality of sub-encoders, each of which includes a first sub-layer connection network structure and a second sub-layer connection network structure, wherein the first sub-layer connection network structure is composed of a multi-head self-attention mechanism, a residual connection and a normalization layer, and the second sub-layer connection network structure is composed of a feedforward neural network, a normalization layer and a residual connection; the embedding dimension of the architecture of the position encoder is 128, the number of attention heads is set to 8, the number of encoder layers is set to 3, and the output dimension of the model is set to 1 to realize point prediction.
6. The method of claim 5, wherein, The position encoder encodes positions in the following manner: where PE final is a position encoder, PE static is a static position sub-encoder, PE learned is a learnable position sub-encoder, PE final is a position encoder, PE static and PE final are superimposed, pos represents the position index of the vector in the position encoding matrix, i represents the dimension index in the position encoding vector, d model represents the dimension of the embedded vector, PE static captures the relative relationship between the time series meteorological data through the linear transformation property of the sine function and the cosine function; The learnable position sub-encoder creates an embedding matrix W of size (max(len), d model ) in a randomly initialized manner pos , W pos is updated through backpropagation during training, where max(len) represents the maximum time step that the model can support, the i-th row (0<=i<=max(len)) of the matrix corresponds to the learnable position encoding vector of the i-th position, and during actual operation, a position index sequence is generated according to the actual length seq len of the input sequence to obtain the corresponding learnable position encoding vector in the position embedding matrix.
7. The method of claim 1, wherein, The data located in the nearest predetermined number of time steps in the global dependency relationship is enhanced weight allocation to obtain a time step weighted feature vector, including: The global dependency is defined as where B denotes batch size, L denotes time step length, and D denotes feature dimension. Extracting the matrix located at the last k time steps as ; The time trend weight vector is defined as to characterize the emphasis on recent trends, where w i <w j ; W is normalized to obtain the final trend weight vector W recent T is multiplied by W last recent and summed along the time step direction to obtain the time step weighted feature vector: Wherein, o represents the time step weighted feature vector.
8. The method of claim 7, wherein, The trained feature extractor, improved Transformer and feedforward neural network are used to predict the power generation of the photovoltaic power station, including: The time step weighted feature vector is input into a three-layer feedforward neural network to scale the output dimension to obtain a prediction result: wherein, W1, W2, and W3 are weight matrices for the prediction results, f is an activation function, and b1, b2, and b3 are bias vectors.
9. The method of claim 1, wherein, Further comprising: A memory bank is established for the feature extractor, the improved Transformer and the feedforward neural network; Wherein, establishing a memory bank for the feature extractor, the improved Transformer and the feedforward neural network includes: At the beginning of training, an empty memory bank is initialized; When the following three conditions are met at the same time, the memory bank is updated, wherein the three conditions include: the training has been carried out for a predetermined number of rounds, the set update frequency has been reached, and the improvement ratio of the model performance reaches a preset ratio; Wherein, updating the memory bank includes: The sample priority of the data sample is calculated according to the following formula: where w priority represents the priority of the sample x i , i and represents the predicted value of the sample x i , is a smoothing constant. The seasonal weight of the data sample is calculated according to the following formula: where w season is the season weight, season(x i ) denotes the season corresponding to sample x i ; According to the sample priority and the seasonal weight, the sampling weight of the data sample is determined according to the following formula: where p i represents the sampling weight of sample x i pair; When updating, the sampling weight of each sample in the training set is calculated, and sampling is performed according to the sampling weight, and the sample obtained by sampling replaces the old sample in the memory bank.
10. The method of claim 1, wherein, The main model is backpropagated and the parameters are updated, including: When the memory bank is not empty, a batch of data is randomly sampled from the memory bank; The randomly sampled batch of data is input into the main model; The memory replay loss function is calculated according to the following formula: where L re represents a memory replay loss function, is a replay weight, and M represents the amount of data randomly sampled from the memory bank; The main model is updated by backpropagation according to the memory replay loss.
11. The method of claim 1, wherein, Training the feature extractor, the improved Transformer and the feedforward neural network model includes: Every predetermined length of time, update the snapshot model, copy the parameters of the main model to the snapshot model, start the early stopping mechanism in the case of continuous multiple rounds of model performance not improving, prevent overfitting, and obtain the trained main model, wherein the main model is used for power generation prediction.
12. A power generation power prediction device characterized by comprising: Including: An acquisition module is configured to acquire historical power data of a photovoltaic power station and historical meteorological data of a region where the photovoltaic power station is located. The processing module is configured to align the historical power data and historical meteorological data of the region according to a sampling time, to obtain processed power data and meteorological data. The extraction module is configured to extract features of the processed power data and statistical features of the processed meteorological data by a feature extractor, and to take the features of the processed power data and the statistical features of the processed meteorological data as local features. The global module is configured to extract global dependency from the extracted local features by an improved Transformer. The weighting module is configured to assign an enhanced weight to data located in the nearest predetermined number of time steps in the global dependency, to obtain a time-step-weighted feature vector. The calculation module is configured to input the time-step-weighted feature vector into a feedforward neural network for calculation, to obtain a prediction result, and to train the feature extractor, the improved Transformer and the feedforward neural network based on an error between the prediction result and an actual result. The prediction module is configured to predict power generation of the photovoltaic power station by the trained feature extractor, the improved Transformer and the feedforward neural network after the training is completed. The feature extractor, the improved Transformer and the feedforward neural network model are composed of a snapshot model and a main model, and the training of the feature extractor, the improved Transformer and the feedforward neural network model includes: traversing a training data batch, determining a comprehensive loss according to the following formula: where L new represents the comprehensive loss, B represents the batch size, y i represents the true value of the i-th sample, represents the prediction value of the i-th sample by the model, f t represents the prediction value of the snapshot model, f s represents the prediction value of the main model, represents the dependency weight value on old data; performing back propagation and parameter updating on the main model according to the comprehensive loss.
13. A terminal device comprising a processor and a memory for storing processor- executable instructions, characterized in that, The processor executes the instructions to implement the steps of the method in any one of claims 1 to 11.
14. A computer readable storage medium having stored thereon computer programs / instructions, characterized in that, The computer program / instructions are executed by the processor to implement the steps of the method in any one of claims 1 to 11.
Citation Information
Patent Citations
Photovoltaic power short-term prediction method and system based on Gaussian mixture model clustering
CN117494896A
Photovoltaic power generation power / quantity prediction method and device based on regression and time sequence fusion
CN117708716A