Indoor environment data prediction method and system based on LSTM-iTransformer
By integrating sensor and meteorological data through the LSTM-iTransformer model, the problem of lag in indoor environmental data prediction by smart home devices is solved, achieving high-precision long-term time-series prediction and environmental control effects.
Patent Information
- Application Number
- CN202511172576.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-21
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-08-21
AI Technical Summary
Existing smart home devices lag in predicting indoor environmental data and cannot respond to environmental changes in a timely manner. Traditional methods and deep learning models struggle to capture complex spatiotemporal patterns and long-distance dependencies, affecting the effectiveness of environmental comfort regulation.
An LSTM-iTransformer-based approach is adopted, which integrates LSTM, an improved iTransformer, a multi-head differential attention layer, and thermal response modulation to construct an indoor environmental data prediction model. This model integrates sensor data and meteorological information to capture temporal features and perform global deep feature representation and prediction.
It achieves high-precision, long-term indoor environmental data prediction, enhances the model's ability to identify key time-series patterns and its physical rationality, and improves the control accuracy of smart home devices and the comfort of the environment.
Smart Images

Figure CN120744481B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of indoor environmental data prediction, and specifically to an indoor environmental data prediction method and system based on LSTM-iTransformer. Background Technology
[0002] In smart home scenarios, the indoor environment plays a crucial role, directly impacting resident comfort. A pleasant indoor environment provides a comfortable living space, while unfavorable conditions can diminish the living experience. Therefore, maintaining suitable indoor environmental parameters and adjusting these factors in real time through smart home systems is key to improving resident comfort. With the widespread application of IoT technology, smart home scenarios can collect environmental data through various sensors, making indoor environmental data prediction research more feasible. Predicting the smart home environment helps improve the ability of smart home control systems to adapt to environmental changes, thereby enhancing resident comfort.
[0003] However, most current smart home devices rely on real-time or short-term historical data for adjustment. This approach is lagging and cannot respond promptly to environmental changes, thus affecting environmental comfort. Achieving indoor environmental data prediction faces numerous challenges because the indoor environment is influenced by multiple factors, and the patterns of environmental parameter changes are complex. Traditional prediction methods have limitations in processing indoor environmental data, struggling to capture complex spatiotemporal patterns and long-distance dependencies. Although deep learning models such as LSTM can process time-series data, they often encounter gradient vanishing or exploding problems in long-sequence prediction, limiting model performance and the ability to predict long-term trends, thereby affecting the control effectiveness of smart home devices.
[0004] The key issue at present is how to overcome the limitations of traditional methods and existing deep learning models, build a model that can effectively capture the complex features and dependencies of indoor environmental data, and accurately predict environmental data, so as to provide reliable data support for the recommendation of functional parameters of smart home devices. Summary of the Invention
[0005] To address the aforementioned issues, this invention proposes an indoor environmental data prediction method and system based on LSTM-iTransformer. By fusing LSTM, an improved iTransformer, and thermal response modulation with multi-head differential attention, it achieves high-precision, long-term time-series prediction of indoor temperature and humidity.
[0006] The specific plan is as follows:
[0007] On the one hand, indoor environmental data prediction methods based on LSTM-iTransformer include:
[0008] S1 integrates the temperature and humidity data monitored by indoor sensors with the outdoor weather information provided by the meteorological station to obtain integrated environmental information;
[0009] S2, input the integrated environmental information into the LSTM module to extract temporal features;
[0010] S3, the temporal features are input into the improved iTransformer module, which includes a multi-head differential attention layer, a position encoding layer, and a multilayer perceptron, to obtain a vector result containing global deep feature representation; wherein, the multi-head differential attention layer calculates the difference between attention scores of the input temporal features to obtain an enhanced representation of the input sequence; the position encoding layer introduces the position information of the sequence and performs position encoding on the enhanced representation of the input sequence to obtain a feature representation with temporal position information; the multilayer perceptron performs nonlinear transformation and feature fusion on the feature representation with temporal position information through a nonlinear activation function to obtain a vector result containing global deep feature representation;
[0011] S4 inputs the vector result containing global deep feature representation into a time series prediction model including an encoder layer, an average pooling layer, a multilayer perceptron, and a fully connected layer to predict indoor temperature and relative humidity. Specifically, the feedforward neural network structure of the encoder layer uses a one-dimensional convolutional layer to extract and model the local temporal features of the input sequence, obtaining a feature representation with local pattern awareness. The average pooling layer downsamples the feature representation with local pattern awareness to obtain dimensionality-reduced features. The multilayer perceptron performs nonlinear transformations and combinations on the dimensionality-reduced features to obtain abstract semantic features. The fully connected layer receives the abstract semantic features and predicts indoor temperature and relative humidity.
[0012] Furthermore, the LSTM module includes two LSTM neural networks connected in sequence; the number of neurons in the first LSTM neural network is set to twice the feature dimension of the input environmental information, which is used to expand the expressive power of the input features; the number of neurons in the second LSTM neural network is the same as the feature dimension of the output of the first LSTM neural network, which is used to refine the expanded features.
[0013] Furthermore, in S2, the two-layer LSTM neural network includes a forget gate, which determines whether to retain or discard information in the LSTM's memory cells. The calculation formula is as follows:
[0014] ;
[0015] in, This represents the Sigmoid function, which maps inputs to a range between 0 and 1. The weight matrix representing the forget gate; This means concatenating the hidden state from the previous moment with the current input; Indicates the bias term; This represents the output of the forget gate at time t.
[0016] Furthermore, in S3, the multi-head differential attention layer calculates the difference between attention scores based on the temporal features of the input to obtain an enhanced representation of the input sequence, specifically including:
[0017] The input time series features are compared with the parameter matrix respectively. , and After a linear transformation, it is projected onto the query vector. Key vector Sum value vector The calculation formula is as follows:
[0018] ;
[0019] ;
[0020] ;
[0021] in, Represents the temporal characteristics of the input; This represents the query vector for the first group; This represents the key vector of the first group; This represents the query vector for the second group; This represents the key vector of the second group; , and Represents the parameter matrix, , For the number of heads;
[0022] Calculate attention scores for both sets of query vectors and key vectors. For the first set, and Perform the dot product operation, then divide by Scaling, via The first set of attention scores is obtained after function processing. Second group attention scores The formula for calculating the attention score in the first group is as follows:
[0023] ;
[0024] The final attention score is obtained by subtracting the two attention scores and then adding them to the value vector. Multiplying them together, the calculation formula is as follows:
[0025] ;
[0026] ;
[0027] in, This represents a learnable difference weight coefficient used to control the degree of difference; This represents the final attention score of a traditional differential attention layer; , , and Represents a learnable vector; Used for initialization The constant;
[0028] An enhanced representation of the input sequence is obtained based on the final attention score.
[0029] Furthermore, a thermal response modulation function is embedded in the multi-head differential attention layer. The calculation formula is as follows:
[0030] ;
[0031] ;
[0032] in, This represents element-wise multiplication; , This represents the difference between indoor air temperature and wall surface temperature. The surface temperature of the wall. Indicates indoor temperature; The thermal response time constant of the wall; These are the characteristic parameters of the thermally conductive material.
[0033] Furthermore, in S3, the enhanced representation of the input sequence is positionally encoded, and the calculation formula is as follows:
[0034] ;
[0035] ;
[0036] in, Indicates location; Indicates dimension; Indicates the dimension of the input features; This represents the value of the even-numbered dimension of the encoding vector corresponding to position pos; The additional value represents the odd-numbered dimension of the encoding vector corresponding to position pos.
[0037] Furthermore, in S4, the formulas for predicting indoor temperature and relative humidity are as follows:
[0038] ;
[0039] ;
[0040] in, n represents the time step for future prediction; and These represent fully connected layers for temperature prediction and humidity prediction, respectively. Indicates multilayer sensor operation; This indicates the average pooling layer operation; This represents a one-dimensional convolutional layer operation; This represents the output of the improved iTransformer module; Indicates the predicted time is time; Indicates in Predicted temperature value at any given time.
[0041] On the other hand, an indoor environmental data prediction system based on LSTM-iTransformer includes:
[0042] The integration module is used to integrate temperature and humidity data monitored by indoor sensors with outdoor weather information provided by the meteorological station to obtain integrated environmental information;
[0043] The temporal feature acquisition module is used to input the integrated environmental information into the LSTM module to extract temporal features;
[0044] The global deep feature representation acquisition module is used to input the temporal features into an improved iTransformer module, which includes a multi-head differential attention layer, a position encoding layer, and a multilayer perceptron, to obtain a vector result containing the global deep feature representation. Specifically, the multi-head differential attention layer calculates the difference between attention scores on the input temporal features to obtain an enhanced representation of the input sequence; the position encoding layer introduces the positional information of the sequence and performs positional encoding on the enhanced representation of the input sequence to obtain a feature representation with temporal positional information; the multilayer perceptron performs nonlinear transformation and feature fusion on the feature representation with temporal positional information through a nonlinear activation function to obtain a vector result containing the global deep feature representation.
[0045] The prediction module is used to input vector results containing global deep feature representations into a time series prediction model, which includes an encoder layer, an average pooling layer, a multilayer perceptron, and a fully connected layer, to predict indoor temperature and relative humidity. Specifically, the feedforward neural network structure of the encoder layer uses one-dimensional convolutional layers to extract and model local temporal features of the input sequence, obtaining feature representations with local pattern awareness capabilities. The average pooling layer downsamples these feature representations to obtain dimensionality-reduced features. The multilayer perceptron performs nonlinear transformations and combinations on the dimensionality-reduced features to obtain abstract semantic features. The fully connected layer receives these abstract semantic features and predicts indoor temperature and relative humidity.
[0046] The present invention adopts the above technical solution and has the following beneficial effects:
[0047] (1) This invention uses a multi-head differential attention mechanism to calculate the difference between two sets of attention scores and introduces a learnable differential weight coefficient λ, which enhances the model’s ability to distinguish key temporal patterns.
[0048] (2) By embedding a heat response modulation function based on physical mechanism, this invention integrates the thermal inertia of the wall, a key factor in the building thermal environment, into a deep learning model, so that the model can better simulate the heat storage and heat release process of the building envelope in temperature prediction, thereby enhancing the physical rationality and accuracy of the prediction.
[0049] (3) The present invention adopts a hybrid architecture of LSTM and improved iTransformer. LSTM effectively captures long-period time-series dependencies, while iTransformer enhances the global context modeling capability, thereby realizing multi-level, high-precision modeling and prediction of dynamic changes in complex nonlinear indoor environments. Attached Figure Description
[0050] Figure 1 This is a flowchart of an indoor environmental data prediction method based on LSTM-iTransformer, according to an embodiment of the present invention.
[0051] Figure 2 This is a diagram illustrating the overall architecture of the LSTM-iTransformer-based environmental data prediction model according to an embodiment of the present invention.
[0052] Figure 3 This is a diagram illustrating the architecture of the multi-head differential attention mechanism in an embodiment of the present invention.
[0053] Figure 4 This is a diagram of an indoor environmental data prediction system based on LSTM-iTransformer, as described in an embodiment of the present invention. Detailed Implementation
[0054] The present invention will be further described in detail below with reference to the embodiments and accompanying drawings, but the embodiments of the present invention are not limited thereto.
[0055] like Figure 1 As shown, the present invention provides an indoor environmental data prediction method based on LSTM-iTransformer, comprising:
[0056] S1 integrates the temperature and humidity data monitored by indoor sensors with the outdoor weather information provided by the meteorological station to obtain integrated environmental information.
[0057] Specifically, the core of constructing the training set in this embodiment lies in systematically collecting real-world building operation and environmental time-series data. Focusing on the correlation between building thermal environment dynamics and equipment operating status, the aim is to provide sufficient evidence for localized indoor environment prediction models. Indoor data is collected by deploying a high-precision sensor network in key rooms, with core indicators including temperature and humidity, and a collection frequency set to once every 5 minutes to accurately capture transient changes in the indoor microenvironment. Outdoor meteorological data, such as outdoor temperature, wind speed, and solar radiation intensity, is acquired simultaneously, also maintaining a collection frequency of once every 5 minutes. The data must come from highly reliable local meteorological observation stations or rigorously calibrated self-built meteorological stations. By integrating the above multi-source time-series data and performing rigorous preprocessing (including handling missing values, outliers, and standardization), a high-quality and spatiotemporally aligned dataset required for model training is finally constructed.
[0058] The model input data originates from multi-source data collected and integrated in the early stages, including environmental data such as temperature and humidity monitored by indoor sensors and the on / off status of indoor heaters, as well as outdoor weather information provided by the meteorological station. This data is arranged chronologically, forming a dataset with time-series characteristics. Before entering the model, the data undergoes preprocessing, including handling missing and outlier values, and standardization, to ensure data quality and consistency. The processed data is then sequentially input into the LSTM module, in units of time steps. Assuming the time step is set to... Each input data includes past data. Indoor and outdoor environmental data at each time step can be represented as The format is as follows:
[0059] ;
[0060] in, Indicates indoor temperature. Indicates the outdoor temperature. This indicates indoor humidity; H indicates the on / off status of the indoor heater. Indicates radiation intensity. Indicates outdoor wind direction. This represents outdoor wind speed. Each row represents various environmental data at a time step. Data at time step 0 represents the current observation value. The subscript -T+1 indicates the data from the T-1th time step backward from the current time. Arranged chronologically from the past time steps to the current time step, this data format clearly presents the changes in indoor and outdoor environmental data over time, facilitating the model's learning and analysis of time-series features.
[0061] S2, input the integrated environmental information into the LSTM module to extract the temporal features in the integrated environmental information.
[0062] Specifically, the LSTM module consists of two LSTM neural networks connected in sequence; the number of neurons in the first layer is set to twice the dimension of the input features to expand the expressive power of the input features; the number of neurons in the second layer is the same as the dimension of the input features to refine the expanded features.
[0063] Specifically, the time step of the LSTM module is set to 72, and environmental data is collected every 5 minutes to capture the time series change pattern over a continuous 6-hour period.
[0064] Specifically, the LSTM module also includes a forget gate, which determines whether to retain or discard information in the LSTM's memory cells. The calculation formula is as follows:
[0065] ;
[0066] in, This represents the Sigmoid function, which maps inputs to a range between 0 and 1. The weight matrix representing the forget gate; This means concatenating the hidden state from the previous moment with the current input; Indicates the bias term; This represents the output of the forget gate at time t.
[0067] Specifically, the fused data is input into a two-layer LSTM to extract short-term and long-term temporal dependencies and generate enhanced temporal feature sequences.
[0068] In terms of model architecture design, considering that the changes in indoor environmental data in ordinary households are relatively gradual, and to balance model complexity and feature capture ability while avoiding overfitting, this study sets the LSTM module to a two-layer structure. The number of neurons in the first LSTM layer is set to twice the feature dimension of the input data, i.e. This design aims to perform preliminary feature expansion on the input data, fully exploring potential feature information and providing a richer data foundation for subsequent feature extraction. The second LSTM layer has the same number of neurons as the input feature dimension. Its main function is to filter and refine the features output by the first layer, remove redundant information, and extract more representative time-series features, so that the features output by the model can accurately reflect the essential features of indoor environmental data.
[0069] Specifically, the input gate Controlling the degree to which new information enters the cell state and generating candidate cell states The calculation formula is as follows:
[0070] ;
[0071] ;
[0072] in, , It is a weight matrix. , It is a bias term. The function is used to generate new candidate cell states. The input gate controls the proportion of new information entering the cell state through the sigmoid function, while also utilizing... The function generates candidate cell states, providing new information for updating cell states; cell states The update formula is as follows:
[0073] ;
[0074] in, This represents element-wise multiplication, selectively retaining and adding information to the cell state through the forget gate and input gate. This update mechanism allows the cell state to retain important historical information while promptly incorporating new information, effectively solving the dilemma of traditional recurrent neural networks in handling long-term dependencies.
[0075] Output gate The output of the hidden state is determined based on the cell state and the current input, calculated using the following formula:
[0076] ;
[0077] ;
[0078] in, It is the weight matrix of the output gate. It is a bias term that ultimately yields the hidden state at the current time step. The output gate controls the proportion of information output from the cell state through the sigmoid function, combined with the function... The cell state is processed to generate a hidden state for the current time step, which contains rich temporal feature information.
[0079] Input data The data then enters the LSTM module, where a gating mechanism is used to process the data. After two LSTM layers, the output contains hidden states rich in local temporal feature information. The first LSTM layer expands the feature dimension of the input data by two times, uncovering latent features; the second LSTM layer refines the features, removing redundant information, and yields the output. This provides high-quality input for the subsequently improved iTransformer module.
[0080] By using the LSTM module for feature extraction, the temporal features in indoor environmental data are fully mined and extracted. The hidden states output by the model contain rich local feature information, providing high-quality input for the subsequently improved iTransformer module. This effectively uncovers the changing patterns of indoor environmental data over time, laying a solid foundation for indoor environmental data prediction.
[0081] like Figure 2 As shown, this embodiment's model combines LSTM, self-attention mechanism, and CNN to process sequence data. After the input sequence passes through the LSTM layer to extract long-term dependency features, the self-attention mechanism focuses on key information. Subsequently, the CNN layer further extracts local spatial features, and finally, the fully connected layer outputs the classification or prediction result. All components work together to improve model performance.
[0082] S3, the temporal features are input into the improved iTransformer module, which includes a multi-head differential attention layer, a position encoding layer, and a multilayer perceptron, to obtain a vector result containing global deep feature representations. Specifically, the multi-head differential attention layer calculates the difference between attention scores for the input temporal features to obtain an enhanced representation of the input sequence; the position encoding layer introduces the positional information of the sequence and performs positional encoding on the enhanced representation of the input sequence to obtain a feature representation with temporal positional information; the multilayer perceptron performs nonlinear transformation and feature fusion on the feature representation with temporal positional information through a nonlinear activation function to obtain a vector result containing global deep feature representations.
[0083] Specifically, the multi-head differential attention layer calculates the difference between attention scores on the temporal features of the input to obtain an enhanced representation of the input sequence, including:
[0084] The input time series features are compared with the parameter matrix respectively. , and After a linear transformation, it is projected onto the query vector. Key vector Sum value vector The calculation formula is as follows:
[0085] ;
[0086] ;
[0087] ;
[0088] in, Represents the temporal characteristics of the input; This represents the query vector for the first group; This represents the key vector of the first group; This represents the query vector for the second group; This represents the key vector of the second group; , and Represents the parameter matrix, , For the number of heads;
[0089] Calculate attention scores for both sets of query vectors and key vectors. For the first set, and Perform the dot product operation, then divide by Scaling, via The first set of attention scores is obtained after function processing. Second group attention scores The formula for calculating the attention score in the first group is as follows:
[0090] ;
[0091] The final attention score is obtained by subtracting the two attention scores and then adding them to the value vector. Multiplying them together, the calculation formula is as follows:
[0092] ;
[0093] ;
[0094] ;
[0095] in, This represents a learnable difference weight coefficient used to control the degree of difference; This represents the final attention score of a traditional differential attention layer; , , and Represents a learnable vector; Used for initialization The constant;
[0096] An enhanced representation of the input sequence is obtained based on the final attention score.
[0097] Specifically, this invention proposes embedding a thermal response modulation function in the differential attention layer. , This represents the difference between indoor air temperature and wall surface temperature. The final attention score of the improved differential attention layer. When hour, Amplify attention to temperature-related features when hour, This maintains the original attention mechanism.
[0098] Specifically, the enhanced representation of the input sequence is positionally encoded, and the calculation formula is as follows:
[0099] ;
[0100] ;
[0101] in, Indicates location; Indicates dimension; Indicates the dimension of the input features; This represents the value of the even-numbered dimension of the encoding vector corresponding to position pos; The additional value represents the odd-numbered dimension of the encoding vector corresponding to position pos.
[0102] Specifically, a thermal response modulation function is embedded in the multi-head differential attention layer. The calculation formula is as follows:
[0103] ;
[0104] ;
[0105] in, This represents element-wise multiplication; , This represents the difference between indoor air temperature and wall surface temperature. The surface temperature of the wall. Indicates indoor temperature; The thermal response time constant of the wall; These are the characteristic parameters of the thermally conductive material.
[0106] like Figure 3The diagram illustrates a simplified process for a multi-head attention mechanism. The input first passes through multiple linear transformation layers to generate query matrices Q1 and Q2, key matrices K1 and K2, and a value matrix V. Then, two attention scores, softmax(Q1K1T) and softmax(Q2K2T), are calculated and multiplied by the value matrix V to obtain a weighted feature representation. These results are calculated independently in different "heads," then concatenated and processed by group normalization. Finally, a linear transformation is applied to output the final result. This process effectively captures the complex dependencies in the input data.
[0107] Specifically, traditional differential attention mechanisms have core flaws: they fail to consider indoor thermodynamic characteristics, cannot distinguish the heat conduction delay effects of different building structures, and are insensitive to changes in boundary conditions such as the opening and closing of doors and windows. To address these issues, a thermal response modulation function is proposed to be embedded in the differential attention layer. The wall surface temperature is collected in real time using an infrared sensor. Material parameters are retrieved from the building GIS database. and .when hour, Amplify attention to temperature-related features when hour, This invention maintains the original attention mechanism. For the first time, it introduces a thermodynamic response modulation function into the differential attention mechanism, modeling the influence of heat diffusion on attention allocation through temperature difference and heat conduction time constant, thus overcoming the shortcomings of traditional models in responding to changes in the physical environment. The nonlinear thermal response function (tanh smooth modulation) avoids discrete jumps and introduces the material physical property β and the response time constant τ. It is particularly suitable for modeling the thermal stability of building interior spaces, such as predicting dynamic scenarios involving window opening, air cooling, and thermal radiation intervention.
[0108] S4 inputs the vector result containing global deep feature representation into a time series prediction model including an encoder layer, an average pooling layer, a multilayer perceptron, and a fully connected layer to predict indoor temperature and relative humidity. Specifically, the feedforward neural network structure of the encoder layer uses a one-dimensional convolutional layer to extract and model the local temporal features of the input sequence, obtaining a feature representation with local pattern awareness. The average pooling layer downsamples the feature representation with local pattern awareness to obtain dimensionality-reduced features. The multilayer perceptron performs nonlinear transformations and combinations on the dimensionality-reduced features to obtain abstract semantic features. The fully connected layer receives the abstract semantic features and predicts indoor temperature and relative humidity.
[0109] Specifically, the formulas for predicting indoor temperature and relative humidity are as follows:
[0110] ;
[0111] ;
[0112] in, n represents the time step for future prediction; and These represent fully connected layers for temperature prediction and humidity prediction, respectively. Indicates multilayer sensor operation; This indicates the average pooling layer operation; This represents a one-dimensional convolutional layer operation; This represents the output of the improved iTransformer module; Indicates the predicted time is time; Indicates in Temperature prediction values at any given time. Based on the LSTM-iTransformer model, the LSTM module captures temporal features, while the iTransformer module mines global features, achieving accurate multi-step predictions of indoor temperature and humidity. Considering the model structure, sampling frequency, and the changing characteristics of indoor environmental data, this study sets the prediction range to no more than 72 time steps (i.e., 6 hours) in the future.
[0113] Specifically, the LSTM-iTransformer model used in this embodiment is implemented in Python, and toolkits such as Pandas, NumPy, SciPy, and Sklearn are used to process the dataset. The deep learning framework used is PyTorch, running on a Windows 10 operating system, equipped with an Intel i5-13600KF processor and 32GB of memory, and an NVIDIA GeForce RTX 2080 Ti graphics card. The software environment is Python 3.8.16, PyTorch version 1.13.0, and CUDA 11.7 is supported. The dataset used in this study is FlexHouse, derived from an experimental study at the Technical University of Denmark, focusing on the exploration of building thermodynamic characteristics, aiming to provide empirical data support for building energy performance analysis and optimization control strategies. This dataset covers building operation data and environmental parameters from February 21, 2019 to March 13, 2019. Indoor data was collected through high-precision sensors, including temperature and humidity in each room, with a collection frequency of once every 5 minutes to meticulously capture the dynamic changes in the indoor environment. Outdoor weather information includes key indicators such as outdoor temperature, wind speed, and radiation intensity, and is also collected every 5 minutes from authoritative meteorological data sources.
[0114] The environmental variables used in model training include indoor temperature (T_in, 9.41~25.22℃, mean 18.42℃), outdoor temperature (T_out, -0.30~4.36℃, mean 1.64℃), indoor humidity (Rh, 23.85%~36.42%, mean 30.60%), heater status (H, 0 / 1, mean 0.55), radiation intensity (G, -0.004~0.248 kW / m², mean 0.001), outdoor wind direction (Wd, 65.73°~357.55°, mean 186.72°), and wind speed (Ws, 0.60~6.81 m / s, mean 3.68 m / s).
[0115] The model uses mean squared error (MSE = (1 / n)∑(y_i - ŷ_i)²) as the loss function, employs the Adam optimizer (initial learning rate 0.001), and combines a learning rate decay strategy (multiplying by 0.9 every 10 epochs) and an early stopping mechanism (stopping training if the verification loss does not decrease for 5 consecutive epochs). The maximum number of training epochs is 100. The model structure integrates LSTM and an improved iTransformer module, generating predictions through forward propagation and updating parameters through backpropagation, effectively improving convergence and suppressing overfitting.
[0116] To verify the model's performance in predicting smart home environments, it was compared with classic models such as ARIMA, SVR, LSTM, and Transformer. In the comparative experiments, the ARIMA model performed the worst, with a temperature prediction MSE of 0.1995 and R² of -0.068, and a humidity prediction MSE of 0.1148 and R² of -0.214, even worse than simple mean prediction. The SVR model achieved some improvement through parameter optimization, with a temperature MSE of 0.0596 and R² of 0.929, and a humidity MSE of 0.0258 and R² of 0.942, showing acceptable accuracy but still with significant errors. The standard LSTM model had a temperature MSE of 0.0521 and R² of 0.807, but performed poorly in humidity prediction (MSE reaching 0.8036 and R² of 0.522), indicating its limited ability to model multiple variables. The Transformer model performed better than traditional methods with a temperature MSE of 0.0172 and R² of 0.887, but lagged behind in humidity prediction. While significant deviations remain in temperature prediction (MSE = 0.0319, R² = 0.546), the proposed LSTM-iTransformer achieves a low mean squared error (MSE) of 0.0095, a mean absolute error (MAE) of 0.0698, and a high coefficient of determination (R²) of 0.9992 for temperature prediction. For humidity prediction, the MSE is 0.0077, the MAE is 0.0539, and the R² reaches 0.9995. Therefore, the proposed LSTM-iTransformer method demonstrates significant advantages in both temperature and humidity prediction, with substantial reductions in MSE and MAE and an R² close to 1. This indicates that the model possesses extremely strong fitting ability and prediction accuracy, accurately capturing environmental change patterns and providing efficient and reliable technical support for precise control of smart homes.
[0117] like Figure 4 As shown, this embodiment also discloses an indoor environmental data prediction method and system based on LSTM-iTransformer, including:
[0118] Integration module 41 is used to integrate temperature data and humidity data monitored by indoor sensors and outdoor weather information provided by meteorological station to obtain integrated environmental information;
[0119] The temporal feature acquisition module 42 is used to input the integrated environmental information into the LSTM module to extract temporal features;
[0120] The global deep feature representation acquisition module 43 is used to input the temporal features into the improved iTransformer module, which includes a multi-head differential attention layer, a position encoding layer, and a multilayer perceptron, to obtain a vector result containing the global deep feature representation. Specifically, the multi-head differential attention layer calculates the difference between attention scores of the input temporal features to obtain an enhanced representation of the input sequence; the position encoding layer introduces the positional information of the sequence and performs positional encoding on the enhanced representation of the input sequence to obtain a feature representation with temporal positional information; the multilayer perceptron performs nonlinear transformation and feature fusion on the feature representation with temporal positional information through a nonlinear activation function to obtain a vector result containing the global deep feature representation.
[0121] The prediction module 44 is used to input the vector result containing global deep feature representation into a time series prediction model including an encoder layer, an average pooling layer, a multilayer perceptron, and a fully connected layer to predict indoor temperature and relative humidity. Specifically, the feedforward neural network structure of the encoder layer uses a one-dimensional convolutional layer to extract and model the local temporal features of the input sequence, obtaining a feature representation with local pattern awareness. The average pooling layer downsamples the feature representation with local pattern awareness to obtain dimensionality-reduced features. The multilayer perceptron performs nonlinear transformation and combination on the dimensionality-reduced features to obtain abstract semantic features. The fully connected layer receives the abstract semantic features and predicts the indoor temperature and relative humidity.
[0122] Although the invention has been specifically shown and described in conjunction with preferred embodiments, those skilled in the art should understand that various changes in form and detail may be made to the invention without departing from the spirit and scope of the invention as defined in the appended claims, all of which shall be within the scope of protection of the invention.
Claims
1. A method for predicting indoor environmental data based on LSTM-iTransformer, characterized in that, include: S1 integrates the temperature and humidity data monitored by indoor sensors with the outdoor weather information provided by the meteorological station to obtain integrated environmental information; S2, input the integrated environmental information into the LSTM module to extract temporal features; S3, the temporal features are input into the improved iTransformer module, which includes a multi-head differential attention layer, a position encoding layer, and a multilayer perceptron, to obtain a vector result containing global deep feature representation; wherein, the multi-head differential attention layer calculates the difference between attention scores of the input temporal features to obtain an enhanced representation of the input sequence; the position encoding layer introduces the position information of the sequence and performs position encoding on the enhanced representation of the input sequence to obtain a feature representation with temporal position information; the multilayer perceptron performs nonlinear transformation and feature fusion on the feature representation with temporal position information through a nonlinear activation function to obtain a vector result containing global deep feature representation; The multi-head differential attention layer calculates the difference between attention scores on the temporal features of the input to obtain an enhanced representation of the input sequence, specifically including: The input time series features are respectively compared with the parameter matrix W. Q W K and W V After a linear transformation, the vectors are projected onto the query vector Q, key vector K, and value vector V. The calculation formula is as follows: [Q1;Q2]=XW Q ; [K1;K2]=XW K ; V=XW V ; Where X represents the input temporal features; Q1 represents the query vector of the first group; K1 represents the key vector of the first group; Q2 represents the query vector of the second group; K2 represents the key vector of the second group; W Q W K and Let d = d model / h, where h is the number of heads; Calculate attention scores for both sets of query vectors and key vectors. For the first set, perform a dot product operation between Q1 and K1, then divide by... After scaling and processing with the softmax function, we obtain the first set of attention scores A1 and the second set of attention scores A2. The formula for calculating the first set of attention scores is as follows: The final attention score is obtained by subtracting the two attention scores and multiplying the result by the value vector V, as shown in the following formula: DiffAttn(X)=(A1-λA2)V; Where λ represents a learnable differential weight coefficient used to control the degree of difference; DiffAttn() represents the final attention score of the traditional differential attention layer; and λ represents a learnable vector; init ∈(0,1) are constants used to initialize λ; An enhanced representation of the input sequence is obtained based on the final attention score; S4 inputs the vector result containing global deep feature representation into a time series prediction model including an encoder layer, an average pooling layer, a multilayer perceptron, and a fully connected layer to predict indoor temperature and relative humidity. Specifically, the feedforward neural network structure of the encoder layer uses a one-dimensional convolutional layer to extract and model the local temporal features of the input sequence, obtaining a feature representation with local pattern awareness. The average pooling layer downsamples the feature representation with local pattern awareness to obtain dimensionality-reduced features. The multilayer perceptron performs nonlinear transformations and combinations on the dimensionality-reduced features to obtain abstract semantic features. The fully connected layer receives the abstract semantic features and predicts indoor temperature and relative humidity.
2. The indoor environmental data prediction method based on LSTM-iTransformer according to claim 1, characterized in that, In S2, the LSTM module includes two LSTM neural networks connected in sequence; the number of neurons in the first LSTM neural network is set to twice the feature dimension of the input environmental information, which is used to expand the expressive power of the input features; the number of neurons in the second LSTM neural network is the same as the feature dimension of the output of the first LSTM neural network, which is used to refine the expanded features.
3. The indoor environmental data prediction method based on LSTM-iTransformer according to claim 2, characterized in that, In S2, the two-layer LSTM neural network includes a forget gate, which determines whether to retain or discard information in the LSTM's memory cells. The calculation formula is as follows: f t =σ(W f ·[h t-1 ,x t ]+b f ); Where σ represents the Sigmoid function, used to map the input to the range of 0 to 1; W f The weight matrix of the forget gate; [h t-1 x t ] indicates concatenating the hidden state from the previous time step with the current input; b f Indicates the bias term; f t This represents the output of the forget gate at time t.
4. The indoor environmental data prediction method based on LSTM-iTransformer according to claim 1, characterized in that, A thermal response modulation function Ψ(ΔT) is embedded in the multi-head differential attention layer. walll The calculation formula is as follows: DiffAttn new (X)=[(A1-λA2)⊙Ψ(ΔT wall )]V; Where ⊙ represents element-wise multiplication; ΔT wall =T in -T wall_surface ΔT wall T represents the difference between indoor air temperature and wall surface temperature. wall_surface T represents the surface temperature of the wall. in τ represents the indoor temperature; τ is the thermal response time constant of the wall; β is the characteristic parameter of the thermally conductive material.
5. The indoor environmental data prediction method based on LSTM-iTransformer according to claim 1, characterized in that, In S3, the enhanced representation of the input sequence is positionally encoded, and the calculation formula is as follows: Where pos represents position; i represents dimension; d model Represents the dimension of the input features; PE (pos,2i) This represents the value of the even-numbered dimension of the encoded vector corresponding to position pos; PE (pos,2i+1) The additional value represents the odd-numbered dimension of the encoding vector corresponding to position pos.
6. The indoor environmental data prediction method based on LSTM-iTransformer according to claim 1, characterized in that, In S4, the formulas for predicting indoor temperature and relative humidity are as follows: Where j = 1, 2, ..., n represents the time step of future prediction; FC T and FC H These represent fully connected layers for temperature and humidity prediction, respectively; MLP represents multilayer perceptron operation; AP represents average pooling layer operation; Conv represents one-dimensional convolutional layer operation; H iTransformer This indicates the output of the improved iTransformer module; pred t+j This indicates that the predicted time is t+j. This represents the predicted temperature value at time t+j.
7. An indoor environmental data prediction system based on LSTM-iTransformer, characterized in that, include: The integration module is used to integrate temperature and humidity data monitored by indoor sensors with outdoor weather information provided by the meteorological station to obtain integrated environmental information; The temporal feature acquisition module is used to input the integrated environmental information into the LSTM module to extract temporal features; The global deep feature representation acquisition module is used to input the temporal features into an improved iTransformer module, which includes a multi-head differential attention layer, a position encoding layer, and a multilayer perceptron, to obtain a vector result containing the global deep feature representation. Specifically, the multi-head differential attention layer calculates the difference between attention scores on the input temporal features to obtain an enhanced representation of the input sequence; the position encoding layer introduces the positional information of the sequence and performs positional encoding on the enhanced representation of the input sequence to obtain a feature representation with temporal positional information; the multilayer perceptron performs nonlinear transformation and feature fusion on the feature representation with temporal positional information through a nonlinear activation function to obtain a vector result containing the global deep feature representation. The multi-head differential attention layer calculates the difference between attention scores on the temporal features of the input to obtain an enhanced representation of the input sequence, specifically including: The input time series features are respectively compared with the parameter matrix W. Q W K and W V After a linear transformation, the vectors are projected onto the query vector Q, key vector K, and value vector V. The calculation formula is as follows: [Q1;Q2]=XW Q ; [K1;K2]=XW K ; V=XW V ; Where X represents the input temporal features; Q1 represents the query vector of the first group; K1 represents the key vector of the first group; Q2 represents the query vector of the second group; K2 represents the key vector of the second group; W Q W K and Let d = d model / h, where h is the number of heads; Calculate attention scores for both sets of query vectors and key vectors. For the first set, perform a dot product operation between Q1 and K1, then divide by... After scaling and processing with the softmax function, we obtain the first set of attention scores A1 and the second set of attention scores A2. The formula for calculating the first set of attention scores is as follows: The final attention score is obtained by subtracting the two attention scores and multiplying the result by the value vector V, as shown in the following formula: DiffAttn(X)=(A1-λA2)V; Where λ represents a learnable differential weight coefficient used to control the degree of difference; DiffAttn() represents the final attention score of the traditional differential attention layer; and λ represents a learnable vector; init ∈(0,1) are constants used to initialize λ; An enhanced representation of the input sequence is obtained based on the final attention score; The prediction module is used to input vector results containing global deep feature representations into a time series prediction model, which includes an encoder layer, an average pooling layer, a multilayer perceptron, and a fully connected layer, to predict indoor temperature and relative humidity. Specifically, the feedforward neural network structure of the encoder layer uses one-dimensional convolutional layers to extract and model local temporal features of the input sequence, obtaining feature representations with local pattern awareness capabilities. The average pooling layer downsamples these feature representations to obtain dimensionality-reduced features. The multilayer perceptron performs nonlinear transformations and combinations on the dimensionality-reduced features to obtain abstract semantic features. The fully connected layer receives these abstract semantic features and predicts indoor temperature and relative humidity.
Citation Information
Patent Citations
Photovoltaic power ultra-short-term prediction method and system based on itransfomer
CN119312054A
Hybrid network 4D flight path prediction method based on LSTM and Transformer
CN120471313A