Building energy consumption data anomaly detection method and device based on time-frequency cross attention mask autoencoder

CN122986509APending Publication Date: 2026-10-27ZHEJIANG UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611167224.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

现有方法多侧重于单一时域建模,难以在复杂的高维特征空间中同步捕捉局部时序细节与全局周期性结构,导致对复杂运行工况的表征能力受限

Benefits of technology

1. 本发明的解耦的时域与频域双流编码架构能够从多尺度视角同步捕获局部工况突变细节和全局日/周循环周期,通过频域自注意力机制学习频率间的协同依赖关系,显著提升了模型对建筑能耗数据中复杂运行模式的表征能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122986509A_ABST
    Figure CN122986509A_ABST
Patent Text Reader

Abstract

The application discloses a building energy consumption data anomaly detection method and device based on a time-frequency cross attention mask autoencoder, which comprises the following steps: obtaining multivariate time series data of building energy consumption and preprocessing; adopting a block mask strategy to mask the preprocessed data to generate mask sequence data; constructing a time-frequency cross attention mask autoencoder model, wherein a time domain encoder extracts local time sequence features of the mask sequence based on attention residual, a frequency domain encoder extracts global dominant frequency features from a complete sequence, and a cross attention fusion module takes the time domain features as a query vector, takes the frequency domain features as a key vector and a value vector, and performs information fusion in the time-frequency cross domain; a multilayer perception decoder maps the fused features back to the original feature space for sequence reconstruction; and a total loss function optimization model parameter is constructed by jointly minimizing the reconstruction mean square error of the mask position and the entropy loss of the cross attention weight. The application has high detection precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of smart buildings and anomaly detection, specifically relating to a method and device for anomaly detection of building energy consumption data based on a time-frequency cross-attention mask autoencoder. Background Technology

[0002] Building energy consumption plays a significant role in global energy consumption, accounting for approximately 30% of global final energy consumption and 26% of energy-related carbon emissions. Heating, ventilation, and air conditioning (HVAC) systems, as the primary energy-consuming equipment in buildings, typically consume 40% to 50% of the energy in commercial buildings, and their operational status directly impacts building energy consumption and indoor environmental quality. HVAC systems are usually equipped with dozens to hundreds of sensors that monitor physical quantities such as temperature, humidity, energy consumption, flow rate, and pressure in real time. Timely and accurate detection of abnormal conditions from these sensor data is of great practical significance for ensuring safe equipment operation, improving energy efficiency, and reducing operation and maintenance costs.

[0003] Currently, methods for anomaly detection in building energy consumption data can be broadly categorized into two types: one is rule-based or statistical threshold-based methods, which identify anomalies by setting rules or statistical boundaries for sensor data. While these methods offer strong interpretability, they often require extensive domain knowledge for rule formulation, struggle to capture complex temporal dependencies, and are poorly adaptable to complex and variable operating conditions. The other type is based on deep learning methods, such as variational autoencoders and Transformers, which achieve anomaly detection by learning normal operating modes. However, these methods still face numerous challenges in practical applications.

[0004] In recent years, deep learning architectures based on masked autoencoders (MAEs) have made significant progress in time-series anomaly detection. MAEs achieve self-supervised modeling of normal operating patterns by masking parts of the input data and prompting the model to reconstruct the missing portions. Methods such as TimesNet and CATCH further introduce frequency domain transformations to capture periodic patterns, while methods like DCdetector (Dual Attention Contrastive Representation Detector) improve feature discrimination capabilities through contrastive learning. However, when dealing with highly complex sensor data such as building energy consumption, existing anomaly detection methods still face several serious challenges: (1) Imbalance between time-domain and frequency-domain feature capture. Building energy consumption data exhibits complex cross-scale characteristics, including both local transients caused by rapid equipment start-up and shutdown, and significant long-term structures such as daily and weekly cycles driven by human activities and climate change. Existing methods mostly focus on single-time-domain modeling, making it difficult to simultaneously capture local temporal details and global periodic structures in a complex high-dimensional feature space, thus limiting the ability to represent complex operating conditions.

[0005] (2) Training data contamination and high-frequency noise interference. In practical applications, building energy consumption sensor data are often not carefully cleaned manually, and the training set inevitably contains unlabeled abnormal operating condition samples. Traditional reconstruction-based methods lack explicit filtering mechanisms for high-frequency unstructured noise and abnormal components, and are very likely to "learn" the distribution of abnormal patterns during the training process, thus leading to a decrease in the discrimination power during the detection stage.

[0006] (3) Information degradation in deep feature extraction. When faced with multivariate high-dimensional sensor data, deep neural networks generally face the problems of feature degradation and gradient loss when extracting complex spatiotemporal correlations. Existing simple residual connection mechanisms are difficult to fully aggregate global context information across layers, which limits the accuracy of the model in capturing subtle deviations when dealing with complex coupling relationships.

[0007] In summary, existing methods for detecting anomalies in building energy consumption data have significant shortcomings in three aspects: the balance of time-frequency feature capture, the robustness of training data noise, and the fidelity of deep features. There is an urgent need to propose an anomaly detection method that can simultaneously model time-domain and frequency-domain information, has denoising capabilities, and can effectively mitigate the degradation of deep information. Summary of the Invention

[0008] To address the shortcomings of existing technologies, this invention provides a method and apparatus for anomaly detection in building energy consumption data based on a time-frequency cross-attention mask autoencoder. By constructing a decoupled time-domain and frequency-domain dual-stream encoder architecture, it aims to simultaneously capture local transient and global periodic features to overcome the feature capture imbalance problem. By introducing a "denoising-first" Top-K frequency selection and cross-attention mechanism, frequency structure priors are injected into the reconstruction process, effectively suppressing training data contamination and high-frequency noise interference. Simultaneously, a deep attention residual aggregation mechanism is introduced into the time-domain encoder to alleviate information degradation in deep networks under high-dimensional data. Finally, by combining cross-attention entropy regularization and dynamic threshold determination, high-precision and robust anomaly detection is achieved.

[0009] The objective of this invention is achieved through the following technical solution: A method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder includes the following steps: S1: Obtain multivariate time series data of building energy consumption and perform standardized preprocessing; use a block masking strategy to mask the preprocessed data and generate masked sequence data; S2: Construct a time-frequency cross-attention mask autoencoder model, including a time-domain encoder, a frequency-domain encoder, a cross-attention fusion module, and a multilayer perceptron decoder; wherein, the time-domain encoder extracts local temporal features of the mask sequence based on attention residuals; the frequency-domain encoder extracts global dominant frequency features from the complete sequence; the cross-attention fusion module performs time-frequency cross-domain information fusion using time-domain features as query vectors and frequency-domain features as key and value vectors; the multilayer perceptron decoder maps the fused features back to the original feature space for sequence reconstruction; S3: Input the mask sequence data into the time-frequency cross-attention mask autoencoder model for self-supervised training. Optimize the model parameters by constructing a total loss function that jointly minimizes the reconstruction mean square error of the mask position and the entropy loss of the cross-attention weights. S4: The trained time-frequency cross-attention mask autoencoder model is used to perform sliding window reconstruction on the test data, and the absolute error between the predicted value and the true value is calculated as the original anomaly score. The original anomaly score is then smoothed by median filtering based on time sliding window and normalized by relative scale based on historical feature mean. Finally, the dynamic threshold is calculated using the POT dynamic threshold method based on extreme value theory, and anomaly judgment is performed to output the final detection result.

[0010] Furthermore, a block masking strategy is employed to mask the preprocessed data, generating a masked sequence of data, specifically including: Divide the sequence X of length T into... A fixed length of l p Data blocks; given mask ratio ρ m Calculate the number of data blocks that need to be masked for each feature. , This indicates a floor operation; N is independently and randomly selected for each feature channel. m The indexes of each data block are masked to construct a mask matrix. In this context, state 0 represents the mask position, and state 1 represents the reserved position; F is the number of feature dimensions; the final result is the mask sequence data. ; This represents the element-wise multiplication operator.

[0011] Furthermore, the temporal encoder fuses the output representations of all preceding layers through a deep attention aggregation mechanism, specifically including: The outputs of all the previous layers are stacked in the depth dimension and normalized by the root mean square layer to obtain the key matrix. Attention weights are calculated using the learnable query vectors of the current layer and weighted summation is performed to obtain the aggregated result. The result is then input into the Transformer layer of the Pre-Norm structure for feature extraction and outputs temporal features that retain local temporal information.

[0012] Furthermore, the frequency domain encoder extracts global dominant frequency features from the complete sequence, specifically including: A real-valued Fast Fourier Transform is performed along the time dimension on the input time series to obtain the amplitude spectrum and phase spectrum. The amplitude spectrum and phase spectrum are concatenated and projected onto the feature space, and frequency position codes are superimposed to obtain a frequency domain embedding sequence. The average amplitude of all feature channels is calculated as the global frequency energy. A learnable frequency importance parameter is introduced to calculate the weighted energy score. The top K dominant frequency indices with the largest weighted energy scores are selected to form a simplified frequency domain sequence. The simplified frequency domain sequence is input into a Fourier Transformer block for frequency domain self-attention interaction to learn the co-dependency between the fundamental frequency and harmonics, and output frequency domain features.

[0013] Furthermore, the cross-attention fusion module generates the query matrix, key matrix, and value matrix respectively through linear projection, calculates the cross-attention weights, obtains the attention output, and uses residual connection and layer normalization output to fuse the features; The multilayer perceptron decoder consists of two fully connected layers and an intermediate GELU activation function, which maps the fused features back to the original feature space and outputs the reconstructed time series.

[0014] Further, S4 includes: S4.1: Use the trained time-frequency cross-attention mask autoencoder model to perform sliding window reconstruction on the test data, and calculate the absolute error between the predicted value and the true value as the original anomaly score; S4.2: Smooth the original outlier scores using median filtering based on a time sliding window; S4.3: Calculate the average absolute value of each feature dimension in the training set as the feature scale, and perform relative scale normalization on the outlier scores after median filtering smoothing to obtain the final outlier scores; S4.4: The POT dynamic threshold method based on extreme value theory is adopted to calculate the dynamic threshold for historical abnormal scores within the sliding window; S4.5: When the final anomaly score S at the i-th time step final,i Greater than the dynamic threshold θ i At that time, it was determined that abnormal building energy consumption data had occurred.

[0015] Furthermore, S4.4 specifically includes: S4.4.1: For the first Each time step selects outlier scores within the historical window; S4.4.2: Calculate the initial quantile threshold based on outlier scores within the historical window; S4.4.3: Extract the set of excess values ​​that exceed the initial quantile threshold from the history window; S4.4.4: Using the Grimshaw method for excess value sets The data in the model are fitted with the scale parameter σ and shape parameter γ of the generalized Pareto distribution. S4.4.5: Calculate the dynamic threshold θ at the i-th time step based on the GPD quantile function i .

[0016] A building energy consumption data anomaly detection device based on time-frequency cross-attention mask autoencoder includes one or more processors for implementing a building energy consumption data anomaly detection method based on time-frequency cross-attention mask autoencoder.

[0017] An electronic device, comprising: One or more processors; A storage device for storing one or more programs, which, when executed by the electronic device, enable the electronic device to implement a method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder.

[0018] A computer-readable storage medium is characterized in that it stores a program thereon, which, when executed by a processor, implements a method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder.

[0019] The beneficial effects of this invention are as follows: 1. The decoupled time-domain and frequency-domain dual-stream coding architecture of the present invention can simultaneously capture details of local operating condition changes and global daily / weekly cycles from a multi-scale perspective. By learning the cooperative dependency relationship between frequencies through the frequency-domain self-attention mechanism, it significantly improves the model's ability to represent complex operating modes in building energy consumption data.

[0020] 2. This invention introduces a Top-K dominant frequency screening mechanism with "denoising priority" and a cross-attention fusion module. By guiding the reconstruction process of local time points through the global frequency structure, it effectively filters high-frequency unstructured noise from the sensor and shields the interference of abnormal samples hidden in the training set, thereby reducing the false alarm rate in the detection stage and improving the prediction accuracy of the method of this invention.

[0021] 3. The temporal encoder of this invention adopts a deep attention residual aggregation mechanism, which effectively alleviates the problems of information degradation and gradient loss in the deep feature extraction process by explicitly aggregating global context information across layers, and significantly enhances the model's accuracy in capturing subtle anomalies when processing high-dimensional multivariate data.

[0022] 4. The block masking strategy of this invention, combined with cross-attention entropy regularization, prevents attention collapse while forcing the model to deeply mine the semantic structure of sensor data sequences. Combined with the POT dynamic thresholding method, it ultimately achieves high robustness and adaptability in anomaly detection in highly complex building environments. Attached Figure Description

[0023] Figure 1 This is a flowchart of the building energy consumption data anomaly detection method based on time-frequency cross-attention mask autoencoder of the present invention.

[0024] Figure 2 This is a schematic diagram of the time-domain and frequency-domain encoders and the cross-attention fusion module in an embodiment of the present invention.

[0025] Figure 3 This is a time-series waveform diagram of multivariable sensor data from a building cooling system in an embodiment of the present invention, wherein... Figure 3 (a) is the time-series waveform of the total active power of the system, (b) is the time-series waveform of the centrifuge power, and (c) is the time-series waveform of the power of the industrial frequency cooling pumps 2 and 4.

[0026] Figure 4 This is a schematic diagram comparing the Top-K spectrum selection before and after in the time-frequency cross-attention mask autoencoder model of this invention, wherein... Figure 4 Figure (a) is a schematic diagram of the original spectrum, and Figure (b) is the spectrum after Top-16 selection.

[0027] Figure 5 This is a heatmap of the cross-attention weights of the time-frequency cross-attention mask autoencoder model in an embodiment of the present invention.

[0028] Figure 6 This is a training loss curve of the time-frequency cross-attention mask autoencoder model in an embodiment of the present invention.

[0029] Figure 7 This is a graph showing the anomaly score and POT dynamic threshold determination of the time-frequency cross-attention mask autoencoder model outputting test set data in an embodiment of the present invention.

[0030] Figure 8 This is an anomaly detection result diagram of the time-frequency cross-attention mask autoencoder model in an embodiment of the present invention. Detailed Implementation

[0031] The present invention will be described in detail below with reference to the accompanying drawings and preferred embodiments. The purpose and effects of the present invention will become clearer. It should be understood that the specific embodiments described herein are merely for explaining the present invention and are not intended to limit the present invention.

[0032] The core idea of ​​the anomaly detection method for building energy consumption data based on time-frequency cross-attention mask autoencoder of the present invention is to construct a decoupled time-domain and frequency-domain dual-stream encoder architecture to capture local temporal details and global periodic features of building energy consumption data respectively. The time-domain encoder extracts local temporal features through an attention residual mechanism, while the frequency-domain encoder obtains frequency-domain tokens through real-number fast Fourier transform, linear embedding, and frequency position encoding. Furthermore, a Fourier Transformer block is introduced to perform self-attention interaction in the frequency domain to learn the harmonic dependencies between frequencies, and the dominant frequency token is selected based on learnable importance weights. The two encoders work together through a cross-attention mechanism, using time-domain features as queries and frequency-domain features as keys, to achieve information fusion of "global frequency structure guiding local time point reconstruction". Under the framework of mask self-supervised learning, the reconstruction error and cross-attention entropy loss are jointly optimized, and finally robust anomaly detection is achieved through median filtering and dynamic thresholding based on extreme value theory. Specifically, the frequency domain encoder maps the time series to the frequency space through Fourier transform and learns the co-dependency between the fundamental frequency and harmonics using a frequency domain self-attention mechanism, thereby explicitly extracting global rhythmic patterns such as daily and weekly cycles implicit in the data. The time domain encoder, on the other hand, focuses on capturing local transient features such as equipment start-up and shutdown and operating condition switching. In addition, this invention introduces a high-proportion block mask strategy to force the model to break away from the shortcut learning of local interpolation, and combines cross-attention entropy regularization to optimize information distribution, ensuring that the extracted features are both discriminative and conform to the physical laws of building energy consumption data, thereby achieving high-precision and highly robust anomaly detection.

[0033] On the one hand, such as Figure 1 As shown in the figure, the method for detecting abnormal building energy consumption data based on time-frequency cross-attention mask autoencoder in this embodiment includes the following steps one through four.

[0034] Step 1: Obtain multivariate time series data of building energy consumption and perform standardized preprocessing; use a block masking strategy to mask the preprocessed data to generate masked sequence data.

[0035] The standardized preprocessing here includes: (1) Data resampling: The original data is resampled to a 15-minute interval to reduce data redundancy.

[0036] (2) Energy consumption feature screening: Features directly related to energy consumption were screened from the original data, including cooling tower power, centrifuge power, centrifuge corrected power, large screw compressor power, large screw compressor corrected power, small screw compressor power, total power of variable frequency cooling pump, total power of industrial frequency cooling pump, total power of variable frequency chilled pump, total power of industrial frequency chilled pump, total active power of chiller, and total active power of system, totaling 12 energy consumption features.

[0037] (3) Missing value handling: Remove feature columns with a missing rate of more than 15% to ensure data quality.

[0038] (4) Data partitioning: The data is partitioned into training set, validation set and test set according to time order.

[0039] (5) Perform Z-score standardization on the feature dimensions of the data to obtain normalized data.

[0040] The normalized data is represented as Where B is the batch size, T is the time window sequence length, and F is the number of feature dimensions.

[0041] Patch masking is used instead of random single-point masking to mask the preprocessed data, generating a mask sequence data, such as... Figure 2 As shown, it includes the following sub-steps: (1.2.1) Define the time block length l p Divide a sequence of length T into N p Non-overlapping data blocks:

[0042] (1.2.2) Given a mask ratio ρ m Calculate the number N data blocks that need to be masked for each feature. m :

[0043] in, This indicates a round-down operation.

[0044] (1.2.3) For each feature dimension Independently generate mask block indices and map them to Boolean mask matrices The time step corresponding to the selected occluded block is set to 0, while the time steps of the remaining blocks are set to 1.

[0045] (1.2.4) Multiply the original features by the mask matrix to generate the masked sequence data:

[0046] in, This represents the element-wise multiplication operator. This is the masked sequence data.

[0047] Step 2: Construct a time-frequency cross-attention mask autoencoder model, including a time-domain encoder, a frequency-domain encoder, a cross-attention fusion module, and a multilayer perceptron decoder. The time-domain encoder extracts local temporal features of the mask sequence based on attention residuals. The frequency-domain encoder obtains frequency-domain tokens through real-number fast Fourier transform, linear embedding, and frequency position encoding. It introduces a Fourier Transform block to perform self-attention interaction in the frequency domain to learn harmonic dependencies between frequencies and selects Top-K globally dominant frequency features based on learnable importance weights. The cross-attention fusion module uses time-domain features as query vectors and frequency-domain features as key and value vectors to perform cross-domain information fusion. The multilayer perceptron decoder maps the fused features back to the original feature space for sequence reconstruction.

[0048] Step two specifically includes the following steps: (2.1) Constructing a time-domain encoder like Figure 2 As shown, the temporal encoder fuses the output representations of all preceding layers through a deep attention aggregation mechanism. The specific process is as follows: (2.1.1) Input data for the mask Perform linear projection and add position encoding P pos And Time2Vec periodic time embedding, to obtain the initial embedding , where D is the hidden layer dimension of the model.

[0049] (2.1.2) The initial embedding input is contained in a multi-layer Transformer encoder with a deep attention residual aggregation mechanism. The computation process of deep attention aggregation is as follows: the outputs of all previous layers are stacked in the depth dimension and normalized by the root mean square layer to obtain the key matrix. The attention weights are calculated using the learnable query vectors of the current layer, and the weighted sum is obtained to obtain the aggregation result. Then, the result is input into the Transformer layer with the Pre-Norm structure for feature extraction.

[0050] (2.1.3) Output temporal features that retain local temporal information .

[0051] (2.2) Constructing a frequency domain encoder Frequency domain encoders aim to extract the dominant periodic component from a complete signal and learn harmonic dependencies between frequencies through frequency domain self-attention. The specific process is as follows: (2.2.1) For the original input Perform a real-valued Fast Fourier Transform (RFFT) along the time dimension to calculate the number of frequency points:

[0052] (2.2.2) Extracting the amplitude spectrum A and phase spectrum of the complex domain result :

[0053]

[0054] in, This indicates the Fourier transform operation. This represents the modulo (absolute value) operation. This indicates a phase take operation.

[0055] (2.2.3) Concatenate the amplitude and phase along the feature dimension to obtain the concatenated feature. :

[0056] (2.2.4) Project the spliced ​​feature U onto a linear layer. D A 3D feature space is created and a learnable frequency-position encoding is superimposed on it. (Random initialization, standard deviation 0.02) yields the frequency domain embedding sequence. .

[0057] (2.2.5) The global energy at each frequency point is obtained by averaging the amplitude spectrum A along the characteristic axis, and the DC component is ignored (the 0th index is cleared to zero) to obtain the global frequency energy. Introduce learnable frequency importance parameters Using fine-tuned physical frequency priors, the global frequency energy fraction is calculated after weighting by learnable importance parameters. :

[0058] in, Used for subsequent selection of dominant frequencies; sigmoid() represents the sigmoid activation function, which compresses the importance weights to the (0,1) interval; This represents the element-wise multiplication operator.

[0059] (2.2.6) Select the weighted global frequency energy fraction The largest value K A dominant frequency index, based on the index from H f Gather K frequency tokens to form a simplified frequency domain sequence .

[0060] This "filter first, interact later" denoising-first strategy can prevent frequency noise in high-dimensional sparse data from being amplified in the self-attention mechanism.

[0061] (2.2.7) Simplify the frequency domain sequence Input Fourier Transformer blocks for frequency domain self-attention interaction.

[0062] The Fourier Transformer block contains: a multi-head self-attention layer (number of heads h=8, dimension d of each head). k =D / h), using a Pre-Norm structure, layer normalization is performed first and then self-attention is calculated.

[0063] The feedforward neural network has a two-layer fully connected structure:

[0064] Where Linear represents a fully connected layer, GELU represents a Gaussian error linear unit activation function, and Dropout represents a random deactivation layer. The intermediate layer dimension D... ff =512. The calculation process is as follows:

[0065] in, and These represent the outputs of the multi-head self-attention layer and the feedforward neural network, respectively. LayerNorm represents the layer normalization operation, and MultiHeadAttn represents the multi-head self-attention operation.

[0066] This frequency domain self-attention mechanism enables tokens of different frequencies to interact and learn the cooperative dependency between the fundamental frequency and harmonics.

[0067] (2.2.8) Perform layer normalization on the output of the Fourier Transformer block to obtain the final frequency domain features. .

[0068] (2.3) Constructing a cross-attention fusion module The cross-attention fusion module uses time-domain features as the query address and frequency-domain features as the key and value to pass global structural knowledge. The specific process is as follows: (2.3.1) Generate the query matrix, key matrix, and value matrix respectively through linear projection:

[0069]

[0070]

[0071] in, , , The projection matrix is ​​learnable; For querying the matrix, The key matrix, It is a value matrix.

[0072] (2.3.2) Calculate the cross-attention weights:

[0073] in, This is the attention weight matrix. Indicates the Softmax normalization operation, superscript This indicates the transpose operation.

[0074] (2.3.3) Obtain the attention output and fuse it with the layer normalized output using residual connections:

[0075]

[0076] in, For cross-attention output, These are the features after fusion.

[0077] (2.4) Constructing a multilayer perceptron decoder The multilayer perceptron decoder consists of two fully connected layers and an intermediate GELU activation function, employing an efficient nonlinear fully connected structure to achieve reconstruction.

[0078] in, , These are the weights and biases of the first hidden layer, respectively. , The weights and biases of the output layer; For intermediate layer dimensions; This is the time series of the final reconstruction of the model.

[0079] Step 3: Input the mask sequence data into the time-frequency cross-attention mask autoencoder model, and optimize the model parameters by jointly minimizing the mean square error of mask position reconstruction and the entropy loss of cross-attention weights.

[0080] Constructing the mask mean square error loss With cross-attention entropy loss The joint loss function formed by the weighted sum Guided self-supervised reconstruction training:

[0081] Among them, the mask mean square error loss In the construction, only the masked feature pixel locations (i.e. set Error assessment will be conducted. The set of masked positions. For the size of the set, For the reconstructed value, x t,f The true value is used; cross-attention entropy loss is applied. During the construction process, the weights α in the cross-attention module are normalized using the Shannon entropy formula. c The distribution of attention to prevent attention collapse: among which, To prevent small constants from becoming zero when taking the logarithm, ;α c [b,t,k] represents the attention weights for the b-th sample, the t-th time step, and the k-th frequency position; λ e The weight hyperparameters for entropy loss are denoted as .

[0082] The AdamW optimizer is used to perform backpropagation to update the model parameters.

[0083] Step 4: Use the trained time-frequency cross-attention mask autoencoder model to perform sliding window reconstruction on the test data, and calculate the absolute error between the predicted value and the true value as the original anomaly score; perform median filtering smoothing based on time sliding window and relative scale normalization based on the historical mean of features on the original anomaly score in turn; finally, use the POT (Peaks-Over-Threshold) dynamic thresholding method based on extreme value theory to calculate the dynamic threshold, and perform anomaly judgment to output the final detection result.

[0084] During the testing phase, the unmasked test data X test Input the trained network to obtain the reconstructed output. Calculate the abnormal score and make an anomaly judgment.

[0085] (4.1) Calculation of raw error: The trained model is used to perform sliding window reconstruction on the test data, and the absolute error between the predicted value and the true value is calculated as the raw outlier score:

[0086] in, This is the original anomaly score matrix.

[0087] (4.2) Smoothing the original outlier scores using median filtering based on a time sliding window: For each feature dimension f, a window of size w is applied along the time axis. med The 1D median filter is expressed as:

[0088] Median() represents the median operation.

[0089] This step can effectively smooth out non-abnormal isolated high-frequency sensor jitter and equipment start-up and shutdown spikes within a reasonable range.

[0090] (4.3) Relative Scale Normalization: Based on the absolute average scale of the original training data, a baseline scaling is performed to eliminate the dimensional differences between different feature dimensions. Specifically, this includes: (4.3.1) Calculate the average absolute value of each feature dimension in the training set as the feature scale:

[0091] in, This indicates the operation of calculating the mean along the sample axis. To prevent numerical stability constants with a division factor of zero.

[0092] (4.3.2) Perform relative scaling normalization on the outlier scores after median filtering smoothing to obtain the final outlier scores:

[0093] in, This is the final abnormal score matrix.

[0094] This step ensures that anomaly detection has a balanced sensitivity across all feature dimensions, preventing large numerical features from masking anomalies in small numerical features.

[0095] (4.4) The POT dynamic threshold method based on extreme value theory is adopted to calculate the dynamic threshold for the historical abnormal scores within the sliding window. The specific process is as follows: (4.4.1) Selection of historical sliding window: For the first At each time step, select the outlier scores within the historical window:

[0096] Where w is the size of the sliding window. Only historical data is used to avoid information leakage.

[0097] (4.4.2) Initial threshold determination: Calculate the initial quantile threshold t0 based on the outlier scores within the historical window:

[0098] Where q is the initial quantile, and Percentile() represents the percentile function.

[0099] (4.4.3) Excessive calculation exceeding the threshold: Extract the set of excessive values ​​that exceed the initial quantile threshold from the historical window. :

[0100] (4.4.4) Grimshaw method for fitting GPD parameters: The Grimshaw method is used to fit the excess value set. The data in the model are fitted to the scaling parameters of the Generalized Pareto Distribution (GPD). With shape parameters .

[0101] The cumulative distribution function of GPD is:

[0102]

[0103] Where y≥0 represents the excess value beyond the threshold, σ>0 represents the scale parameter, and γ represents the shape parameter.

[0104] The Grimshaw method is a univariate numerical search algorithm for solving the maximum likelihood estimation of GPD parameters.

[0105] (4.4.5) Dynamic threshold calculation: Calculate the dynamic threshold θ at the i-th time step based on the GPD quantile function. i :

[0106]

[0107] Where r is the preset risk level, which controls the upper limit of the expected false alarm rate; This represents the natural logarithm function.

[0108] (4.5) Output judgment: When the final anomaly score S at the i-th time step is... final,i Greater than the dynamic threshold θ i At that time, it was determined that an anomaly had occurred in the building energy consumption data Y. anomaly,i :

[0109] in, This is an indicator function that takes the value 1 when the condition is true and 0 otherwise. This is the vector of anomaly detection results, and it triggers an alert.

[0110] On the other hand, corresponding to the aforementioned embodiment of the building energy consumption data anomaly detection method based on time-frequency cross-attention mask autoencoder, the present invention also provides an embodiment of the building energy consumption data anomaly detection device based on time-frequency cross-attention mask autoencoder.

[0111] The building energy consumption data anomaly detection device based on time-frequency cross-attention mask autoencoder provided in this embodiment of the invention includes one or more processors for implementing the building energy consumption data anomaly detection method based on time-frequency cross-attention mask autoencoder in the above embodiment.

[0112] This embodiment of the building energy consumption data anomaly detection device based on time-frequency cross-attention mask autoencoder can be applied to any device with data processing capabilities, such as a computer. The device embodiment can be implemented in software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by the processor of any data processing device reading the corresponding computer program instructions from non-volatile memory into memory and executing them. From a hardware perspective, in addition to the processor, memory, network interface, and non-volatile memory, the data processing device in this embodiment may also include other hardware depending on its actual functions; these will not be elaborated further.

[0113] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.

[0114] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the present invention according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0115] The following analysis of anomaly detection in the cooling system data of buildings ABCD in a company's science park verifies the effectiveness of the method of the present invention.

[0116] Multivariate time series data of the cooling system of buildings ABCD in a company's science park were obtained. The original data collection period was from April 1 to October 31, 2023, a total of 214 days. The original time resolution was 5 minutes, and the original feature number consisted of 113 sensor measurements.

[0117] First, the original data was resampled to a 15-minute interval to reduce data redundancy. Then, 12 energy consumption features directly related to energy consumption were selected from the original sensor data. Next, the data was divided into a training set (70%), a validation set (15%), and a test set (15%) according to time order. Finally, the data was normalized by Z-score standardization of the feature dimensions to obtain normalized data.

[0118] like Figure 3 As shown, the time-series waveforms of multivariable sensor data from a building cooling system under different operating conditions are displayed.

[0119] In this embodiment, the time window sequence length of the normalized data X is T=96, corresponding to 24 hours (15-minute resolution); the number of feature dimensions is F=12.

[0120] A block masking strategy is used to mask the data: time block length l p =4, mask ratio ρ m =0.4, which means 40% of the data blocks are obscured.

[0121] Construct a time-frequency cross-attention masked autoencoder model: The time-domain encoder has a hidden layer dimension D=128 and contains multiple Transformer encoders with deep attention residual aggregation mechanism; the frequency-domain encoder extracts the amplitude and phase spectra through RFFT, selects K=16 dominant frequency indices, the Fourier Transformer block has 8 multi-head attention heads h, and the feedforward neural network has an intermediate layer dimension D. ff =512; Dimension D of the intermediate layer of the multilayer perceptron decoder ff =512.

[0122] like Figure 4 As shown, the figure compares the Top-K spectrum selection of the time-frequency cross-attention mask autoencoder model before and after. It can be seen from the figure that there are a large number of low-amplitude high-frequency redundant components and noise in the original spectrum. After the Top-K dominant frequency selection, only the core periodic components with concentrated energy are retained, which effectively removes high-frequency noise interference while significantly reducing the feature dimension.

[0123] During training, the AdamW optimizer was used, and the learning rate was set to... The weight decay is set to The batch size is set to 32, the training epochs are set to 200, a learning rate decay strategy is used (the learning rate is halved when the validation loss no longer decreases, and the patience value is 10), and an early stopping strategy is used (training stops when the validation loss no longer decreases for 20 consecutive epochs). Loss function weights. The training continues until all training iterations are completed, at which point a fully trained model is obtained.

[0124] like Figure 5 As shown, the heatmap of the cross-attention weights of the time-frequency cross-attention mask autoencoder model is displayed. The heatmap of the 16 frequency components after 96 time steps shows that during the time step evolution, the model can adaptively capture the strong dynamic correlation between specific time intervals (such as time steps 64-93) and key dominant frequency components (such as frequency component No. 6). The highlighted areas of the heatmap clearly reflect the accurate focusing and feature extraction capabilities of the time-frequency cross-attention dimension.

[0125] In this embodiment, the curve showing the change of the model's loss function value with training epochs during the training process is as follows: Figure 6 As shown in the figure, the training loss drops rapidly in the first 5 rounds and then converges to a smaller value after 15 rounds. This verifies that the loss decreases synchronously and stably without overfitting, demonstrating that the model converges quickly, the training process is stable, and the generalization performance is good.

[0126] During the testing phase, the test set data is input into the trained model, which outputs a reconstructed sequence. The original reconstruction error is calculated using a window size w. med Median filtering with a value of 7 is used for smoothing, followed by relative scale normalization to obtain the final anomaly score. The POT dynamic threshold method is used for anomaly detection, with a sliding window size of w=8, an initial quantile of q=0.75, and a risk level of r=0.01.

[0127] In this embodiment, the model's abnormal score distribution of the small screw compressor power (feature 5) output in the test set data and the determination of the POT dynamic threshold are as follows: Figure 7 As shown, from Figure 7 As can be seen, the POT dynamic threshold can adaptively adjust its level according to the fluctuations in historical anomaly scores. When persistent clustering anomalies occur in the time step range of 1450-1600, the anomaly score significantly exceeds the dynamic threshold and is accurately triggered for capture, verifying the robustness and high sensitivity of the POT adaptive threshold mechanism under complex working conditions. Anomaly detection results are as follows: Figure 8 As shown. From Figure 8 As can be seen, the anomalies detected by the method of the present invention are basically consistent with the original signals, thus proving that the method and device of the present invention can effectively detect anomalies in building energy consumption data.

[0128] It will be understood by those skilled in the art that the above descriptions are merely preferred examples of the invention and are not intended to limit the invention. Although the invention has been described in detail with reference to the foregoing examples, those skilled in the art can still modify the technical solutions described in the foregoing examples or make equivalent substitutions for some of the technical features. All modifications and equivalent substitutions made within the spirit and principles of the invention should be included within the scope of protection of the invention.

Claims

1. A method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder, characterized in that, Includes the following steps: S1: Obtain multivariate time series data of building energy consumption and perform standardized preprocessing; use a block masking strategy to mask the preprocessed data and generate masked sequence data; S2: Construct a time-frequency cross-attention mask autoencoder model, including a time-domain encoder, a frequency-domain encoder, a cross-attention fusion module, and a multilayer perceptron decoder; wherein, the time-domain encoder extracts local temporal features of the mask sequence based on attention residuals; the frequency-domain encoder extracts global dominant frequency features from the complete sequence; the cross-attention fusion module performs time-frequency cross-domain information fusion using time-domain features as query vectors and frequency-domain features as key and value vectors; the multilayer perceptron decoder maps the fused features back to the original feature space for sequence reconstruction; S3: Input the mask sequence data into the time-frequency cross-attention mask autoencoder model for self-supervised training. Optimize the model parameters by constructing a total loss function that jointly minimizes the reconstruction mean square error of the mask position and the entropy loss of the cross-attention weights. S4: The trained time-frequency cross-attention mask autoencoder model is used to perform sliding window reconstruction on the test data, and the absolute error between the predicted value and the true value is calculated as the original anomaly score. The original anomaly score is then smoothed by median filtering based on time sliding window and normalized by relative scale based on historical feature mean. Finally, the dynamic threshold is calculated using the POT dynamic threshold method based on extreme value theory, and anomaly judgment is performed to output the final detection result.

2. The method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder according to claim 1, characterized in that, A block masking strategy is used to mask the preprocessed data, generating a masked sequence of data, specifically including: Divide the sequence X of length T into... A fixed length of l p Data blocks; given mask ratio ρ m Calculate the number of data blocks that need to be masked for each feature. , This indicates a floor operation; N is independently and randomly selected for each feature channel. m The indexes of each data block are masked to construct a mask matrix. In this context, state 0 represents the mask position, and state 1 represents the reserved position; F is the number of feature dimensions; the final result is the mask sequence data. ; This represents the element-wise multiplication operator.

3. The method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder according to claim 1, characterized in that, The temporal encoder fuses the output representations of all preceding layers through a deep attention aggregation mechanism, specifically including: The outputs of all the previous layers are stacked in the depth dimension and normalized by the root mean square layer to obtain the key matrix. Attention weights are calculated using the learnable query vectors of the current layer and weighted summation is performed to obtain the aggregated result. The result is then input into the Transformer layer of the Pre-Norm structure for feature extraction and outputs temporal features that retain local temporal information.

4. The method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder according to claim 1, characterized in that, The frequency domain encoder extracts global dominant frequency features from the complete sequence, specifically including: A real-valued Fast Fourier Transform is performed along the time dimension on the input time series to obtain the amplitude spectrum and phase spectrum. The amplitude spectrum and phase spectrum are concatenated and projected onto the feature space, and frequency position codes are superimposed to obtain a frequency domain embedding sequence. The average amplitude of all feature channels is calculated as the global frequency energy. A learnable frequency importance parameter is introduced to calculate the weighted energy score. The top K dominant frequency indices with the largest weighted energy scores are selected to form a simplified frequency domain sequence. The simplified frequency domain sequence is input into a Fourier Transformer block for frequency domain self-attention interaction to learn the co-dependency between the fundamental frequency and harmonics, and output frequency domain features.

5. The method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder according to claim 1, characterized in that, The cross-attention fusion module generates the query matrix, key matrix, and value matrix respectively through linear projection, calculates the cross-attention weights, obtains the attention output, and uses residual connection and layer normalization to fuse the features. The multilayer perceptron decoder consists of two fully connected layers and an intermediate GELU activation function, which maps the fused features back to the original feature space and outputs the reconstructed time series.

6. The method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder according to claim 1, characterized in that, S4 includes: S4.1: Use the trained time-frequency cross-attention mask autoencoder model to perform sliding window reconstruction on the test data, and calculate the absolute error between the predicted value and the true value as the original anomaly score; S4.2: Smooth the original outlier scores using median filtering based on a time sliding window; S4.3: Calculate the average absolute value of each feature dimension in the training set as the feature scale, and perform relative scale normalization on the outlier scores after median filtering smoothing to obtain the final outlier scores; S4.4: The POT dynamic threshold method based on extreme value theory is adopted to calculate the dynamic threshold for historical abnormal scores within the sliding window; S4.5: When the final anomaly score S at the i-th time step final,i Greater than the dynamic threshold θ i At that time, it was determined that abnormal building energy consumption data had occurred.

7. The method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder according to claim 6, characterized in that, S4.4 specifically includes: S4.4.1: For the first Each time step selects outlier scores within the historical window; S4.4.2: Calculate the initial quantile threshold based on outlier scores within the historical window; S4.4.3: Extract the set of excess values ​​that exceed the initial quantile threshold from the history window; S4.4.4: Using the Grimshaw method for excess value sets The data in the model are fitted with the scale parameter σ and shape parameter γ of the generalized Pareto distribution. S4.4.5: Calculate the dynamic threshold θ at the i-th time step based on the GPD quantile function i .

8. A building energy consumption data anomaly detection device based on a time-frequency cross-attention mask autoencoder, characterized in that, It includes one or more processors for implementing the building energy consumption data anomaly detection method based on time-frequency cross-attention mask autoencoder as described in any one of claims 1 to 7.

9. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by the electronic device, cause the electronic device to implement the building energy consumption data anomaly detection method based on time-frequency cross-attention mask autoencoder as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, It stores a program that, when executed by a processor, implements the method for detecting anomalies in building energy consumption data based on a time-frequency cross-attention mask autoencoder as described in any one of claims 1 to 7.