1. Introduction
In the era of advancing technology, the integration of artificial intelligence (AI) and distributed measurement systems (DMSs) has emerged as a groundbreaking approach for developing smart and efficient infrastructures. This convergence holds significant potential, especially in the construction industry, where optimizing resources and enhancing sustainability are key objectives. One of the most critical aspects of modern power systems is the forecasting of electrical quantities, which plays a vital role in improving energy management, reducing operational costs, and enhancing grid stability [
1].
Forecasting techniques are typically categorized based on time horizon: very short-term (minutes to hours), short-term (hours to days), now-casting (real-time prediction), and long-term (months to years). Among these, short-term load forecasting is the most widely applied approach in energy consumption prediction [
2]. Traditional methods such as Autoregressive Integrated Moving Average (ARIMA) and Autoregressive Moving Average with Exogenous Inputs (ARMAX) have been commonly used for energy forecasting [
3]. These time series methods rely on historical data and often struggle to capture nonlinear relationships [
4].
More recently, machine learning (ML) and deep learning (DL) techniques, such as Long Short-Term Memory (LSTM) networks, Gated Recurrent Units (GRUs), and transformer-based models, have shown superior performance in uncovering complex patterns in energy consumption data [
5]. Moreover, ensemble learning methods, including Random Forest (RF) and Gradient Boosting techniques like eXtreme Gradient Boosting (XGBoost) and Light Gradient Boosting Machine (LightGBM), have demonstrated robust predictive capabilities by leveraging multiple weak learners to improve accuracy [
6]. Support Vector Machines (SVMs), known for their effectiveness in handling high-dimensional spaces and nonlinear relationships through kernel functions, have also been successfully applied in energy forecasting, offering competitive performance in certain scenarios [
7].
Additionally, Convolutional Neural Networks (CNNs), originally designed for image processing, have been increasingly applied in energy forecasting due to their ability to automatically extract spatial and temporal features from raw time series data. By leveraging convolutional layers to detect local dependencies and hierarchical patterns, CNNs can enhance forecasting accuracy [
8].
In this context, Digital Twins (DTs) play a crucial role in energy management by offering a real-time digital replica of physical assets [
9,
10]. DTs are powerful tools for predictive maintenance, enhancing sustainability, increasing efficiency, and supporting informed decision making [
11]. By accurately forecasting energy consumption and detecting anomalies, DTs can predict maintenance needs, helping to prevent equipment failures and minimize downtime [
12].
The effectiveness of DTs depends heavily on the forecasting models used to represent system behavior. Integrating AI within DT frameworks significantly enhances their predictive capabilities, enabling facility managers to optimize energy distribution, detect anomalies, and anticipate potential failures [
13]. In the realm of energy monitoring, the integration of the Internet of Things (IoT) with DL models has been shown to enable the real-time monitoring and control of energy resources across residential buildings [
14]. Similarly, DTs have been demonstrated to improve energy efficiency and occupant comfort in public and commercial buildings by replacing rule-based heating and ventilation systems with model predictive control [
15].
Additionally, the accuracy of collected data plays a crucial role. Since instrument transformers (ITs) are the primary sources for voltage and current measurements in acquisition systems, their selection is critical and must align with the target uncertainty requirements of the final application. Achieving reliable data collection also requires addressing the non-ideal characteristics of signals, which can be influenced by environmental factors such as temperature and humidity. Consequently, as demonstrated in the literature, techniques for IT modeling, calibration, and compensation are essential to mitigate these influences and ensure measurement accuracy [
16,
17]. Of course, the contribution to the uncertainty due to the involved algorithms must be considered as well. However, it is well known that such a contribution is typically negligible, or at least one or more orders of magnitude lower than those of ITs [
18].
Compared to the current literature, as noted in two general reviews [
19,
20] and a review on data-driven techniques [
21], this paper presents a comprehensive solution integrating features that are often addressed individually.
Building on the results from [
22], this paper focuses on an AI-driven forecasting framework for electrical quantities in an educational building using a DMS to collect data on voltage, current, and power consumption. The proposed framework employs an LSTM network to enhance forecasting accuracy and reliability across multiple nodes within the building. Extensive experimental testing has been conducted to fine-tune the model, focusing on data quality assessment and correlation analysis. A key feature of this research is the exploration of model generalization within the DMS. Specifically, models trained on data from one node are tested on data from another node, allowing the system to compensate for missing data at a node by predicting values from other locations, thus supporting scalability across the building.
In addition to forecasting, the study evaluates the practical limitations and implementation challenges of integrating AI into distributed energy systems to support the future development of a DT for the building. The insights from this work lay the foundation for DT-based optimization strategies, enabling predictive maintenance, enhanced energy efficiency, and adaptive decision making.
This paper presents a comprehensive solution for AI-driven energy forecasting, addressing key challenges in the field:
Development of an AI-based forecasting model leveraging the LSTM network optimized for electrical quantities prediction.
Evaluation of model performance across the DMS, ensuring reliable and scalable monitoring across different electrical nodes.
Exploration of model generalization within the DMS to compensate for missing data at nodes by testing models trained on data from other nodes.
Identification of practical implementation challenges, including sensor installation, AI model optimization, and real-world data acquisition constraints.
Exploration of the trade-offs between forecasting accuracy, computational complexity, and ease of deployment, making the approach adaptable to different infrastructures.
Taken singularly, the contribution might not be considered a big step forward in research. However, their integration and exploitation are the key added values that provide useful insights to the scientific community.
The paper’s structure is as follows:
Section 2 gives an overview of the concepts needed to enhance the comprehension of the work and the related state of the art.
Section 3 summarizes the use case and provides descriptions of the DMS and the LSTM network.
Section 4 details the evaluation approach. Subsequently,
Section 5 presents the results and their discussion. Finally,
Section 6 concludes the work.
2. Background
The DT concept, though relatively new, is rapidly gaining traction across sectors. Defined in IEC 30173 [
23] as a “digital representation of a target entity with data connections enabling convergence between physical and digital states at a synchronized rate,” DTs are increasingly applied beyond their origins in manufacturing and aerospace to sectors like power systems [
24,
25]. While complete power grid digitalization is challenging, progress is underway, as demonstrated by this study, which aims to move towards the energy DT by forecasting power consumption and managing renewable energy sources.
Time series forecasting is essential in this context, with AI models showing superior performance in energy management systems [
26,
27]. ML and DL algorithms, such as RF, Support Vector Regression (SVR), and LSTM networks, are widely applied for energy forecasting due to their ability to capture complex data relationships. Studies like [
28,
29,
30] showcase applications of RF, SVR, and DL models in predicting electricity demand across different intervals. Additionally, ref. [
31] proposes a CNN for the electricity consumption estimation of a building in Canada.
Hybrid approaches that combine statistical methods with ML are also emerging, leveraging the strengths of both for enhanced forecasting accuracy. Traditional statistical models, such as ARIMA and ARMAX, are well suited for capturing long-term dependencies and seasonality in time series data. For instance, ARIMA-LSTM models have been widely used to exploit ARIMA’s ability to handle linear trends while allowing LSTM to capture complex nonlinear dependencies [
32]. Similarly, in [
33], ARMAX is combined with Neural Network (NN) to enhance predictive accuracy. Other hybrid approaches, such as Wavelet Transform–ARIMA (WT-ARIMA), further refine forecasting capabilities by decomposing time series data into different frequency components before applying statistical models [
34]. These methods offer improved generalization, better handling of missing data, and reduced overfitting, making them highly effective for energy forecasting applications.
Despite the variety of techniques available, this study opts for the use of LSTM networks. LSTM has become a widely accepted method in the field, with a strong track record of success in energy forecasting, ensuring its reliability for this study. With this regard, note that the primary emphasis of this work is not on the forecasting method itself but on the development and evaluation of a comprehensive framework. The proposed approach lays the groundwork for DT technology while also addressing the analysis of data from the DMS and ensuring the model’s transferability across different nodes.
3. Materials and Methods
3.1. Overview of the Building
The framework is developed for short-term electrical consumption forecasting at the “Bertalia-Lazzaretto” Engineering Faculty of the University of Bologna, a 230,000 m
2 complex hosting classrooms, offices, and labs. A DMS, supported by the iOtto interface from Onit [
35], gathers data from diverse spaces and equipment, making this an ideal setting for AI-driven forecasting. With 440 kW of rooftop photovoltaic panels, integrating consumption forecasts into a DT framework enables matching energy use with solar production, optimizing energy efficiency and sustainability.
3.2. The Distributed Measurement System and Data Collection
The deployed DMS facilitates the acquisition of diverse electrical parameters at various locations throughout the building. The block diagram presented in
Figure 1 describes the structure of measurement nodes and sub-nodes. Specifically, transformer TR2 serves as the power source for two structures (Buildings 342 and 346) within the complex. Low Voltage (LV) switchboards A and B distribute power to the departments (including offices and meeting rooms) and laboratories. Switchboard C provides electricity to the lecture rooms and the building’s cafeteria, which have appliances such as ovens and refrigerators. The green symbol indicates the measurement points, while the served areas are depicted in blue.
At each point, voltage, current, active and reactive power, current and voltage Total Harmonic Distortion (THD) coefficient, and power factor measurements are acquired in every phase. The frequency of the system is also measured. The measurement instrumentation includes an EM2389 energy meter and DM3TA series Current Transformers (CTs). The meter has an accuracy of 1% on active power measurements. The installed CTs belong to class 0.5. The LV and the Medium Voltage (MV) substations are pictured in
Figure 2. Considering the installed equipment, any algorithm or method to be developed must consider the constraints in terms of resolution. The acquired data are collected every 15 min throughout the day. Data have been stored since the 6 June 2023.
3.3. Long Short-Term Memory Model
The LSTM model is an artificial (recurrent) NN that supports bidirectional data flow (from input to output and vice versa), designed to capture long-term dependencies in sequential data. LSTM networks have memory cells and gating mechanisms (forget, input, and output gates) that control information flow, allowing them to retain or discard data selectively, making them ideal for time series modeling [
36].
Figure 3 depicts a general scheme of an LSTM cell, the core of an LSTM network. C(t − 1) and C(t) represent the previous and current cell states, while h(t − 1) and h(t) are the previous and current hidden states, and x(t) is the current input [
37]. The gates (forget, input, and output) use Sigmoid and Hyperbolic Tangent (Tanh) activation functions to manage information flow. The Sigmoid function limits outputs between 0 and 1, indicating how much information to retain or discard, while Tanh constrains values between −1 and 1, preventing values from becoming excessively large or small [
38]. The model has been implemented using the PyTorch library (version 2.4.0) in Python programming language (version 3.12.4).
The LSTM architecture consists of two LSTM layers, which help capture more complex temporal dependencies. The hidden size was set to 64 units, providing a good balance between learning capacity and computational efficiency. The model was optimized using the Adam algorithm with a learning rate of 0.001, chosen to ensure stable convergence during training. The model was trained for 50 epochs with a batch size of 256, which allows for efficient parallel processing and reduced training time, and the loss function used was the Mean Squared Error (MSE).
3.4. Data Preprocessing
The data gathered from the DMS described in the previous section was used to train and test the LSTM network. This dataset includes acquisition timestamps along with values for active power, current, and voltage.
To optimize the model’s performance, input data underwent preprocessing. Initially, the timestamp feature was subjected to circular encoding, a technique specifically designed for handling time features in datasets. Circular encoding represents cyclical variables within a continuous circular space by mapping them into a circle using trigonometric functions such as sine and cosine. For instance, when encoding the time of day, each hour is projected in a unit circle, where the sine and cosine values represent the angular position of the hour hand. Subsequently, any missing data were replaced with interpolated values. Additionally, all the readings were 0 to 1 normalized.
Finally, the training and testing datasets were constructed, with the last week of each month reserved for testing and the remaining weeks allocated for training. After this split, a sliding window approach was applied to segment the data into input–output sequences, enabling the model to learn temporal dependencies effectively. Further details on the chosen input and output sequence lengths will be provided in the next section.
3.5. Framework
Implementing DT concepts requires a robust, flexible infrastructure for integrating data from diverse sources (e.g., the DMS) and enabling modular extensions. Users should be able to add modules for tasks like data analytics, AI-based forecasting, and visualization. The AI model needs to provide accurate energy consumption forecasts, and the DMS must offer continuous, high-resolution data acquisition. This framework achieves these aims, leveraging the LSTM network’s capacity to analyze sequential data and predict trends, while the DMS collects detailed electrical parameters from various building points.
To support these requirements, the ExamonX [
39] framework was selected. Designed for IoT monitoring and predictive maintenance, ExamonX integrates components for data flow and processing, with Cassandra for database management, KairosDB for time-series support, and Grafana for visualization. ExamonX includes a software development kit for creating publisher applications, which adapt and send external data to the system.
Figure 4 illustrates the ExamonX architecture, with an AI forecasting module (housing the LSTM model) and two publishers. The “monitoring publisher” inputs data from the DMS, while the “forecasting publisher” inputs data generated by the AI module. This design separates data sources from processing algorithms, ensuring scalability and modularity, and allowing easy expansion for future features. All the data and analytics are accessible through Grafana’s web interface.
4. Test Description
4.1. Performance Across DMS Points and Quantities
The performance of the LSTM network in forecasting trends of electrical quantities was evaluated at various points throughout the DMS. Specifically, TR2, LV Switchgear (LVS)-A, -B, and -D were considered as measurement points. The selection of measurement points was based on the distribution of electrical loads across the building. TR2 was chosen as a measurement point because it is the upstream transformer, providing power to the entire system. LVS-A and LVS-B were selected because they feed the same section of the building, specifically, the departments and laboratories, which include heavy machinery that can significantly influence energy consumption patterns. Lastly, LVS-D was included, as it feeds a separate building, allowing for an analysis of energy consumption in a different part of the facility.
As described in
Section 3, the dataset includes measurements taken every 15 min of active power, current, and voltage at the selected points, spanning from 6 June 2023 to 17 October 2024, totaling 47,485 data points for each quantity at each reading point. The choice of quantities was made to select key parameters both for forecasting energy consumption and for monitoring power quality. Specifically, the active power measurement represents the total active power across all three phases, as it is essential to consider the overall power consumption of the building rather than focusing on individual phase values. The current measurement is taken from phase one as it provides a representative indication of the electrical load in that phase. The voltage is measured between phase one and neutral, which is critical for monitoring the system’s voltage stability.
The initial phase of testing focused on evaluating the performance of the model for different input sequence lengths and forecast horizons at the TR2 measurement point. The objective was to determine how variations in input sequence length affected model performance. Once this parameter was optimized for TR2, the results were extended to the other measurement points.
4.2. Data Correlation Analysis
To better understand the relationships between the predicted electrical quantities, the Pearson correlation has been computed among these variables for each considered reading point. Correlation analysis is valuable in revealing how changes in one variable might be associated with changes in others, providing insights into the system’s dynamics and dependencies.
The Pearson correlation coefficient
r is a statistical measure that quantifies the strength and direction of the linear relationship between two variables [
40]. The coefficient ranges from −1 to 1, where
r = 1: Perfect positive linear correlation (as one variable increases, the other does as well).
r = 0: No linear correlation.
r = −1: Perfect negative linear correlation (as one variable increases, the other decreases).
The Pearson correlation coefficients were calculated pairwise for power, current, voltage, and frequency at all the considered measurement points (TR2, LVS-A, LVS-B, and LVS-D).
4.3. Model Transferability: Testing on Correlated Points
To comprehensively evaluate the predictive model and its potential within the considered DMS, an additional assessment was conducted. Given the correlation between the variables measured at different points in the system, the possibility of leveraging data from one point to predict measurements at another was explored. Initially, the LSTM network was trained using data from the LVS-A measurement point. Subsequently, the trained model was used to forecast the electrical quantities at a different measurement point, specifically LVS-B. This step was designed to assess the model’s transferability and its ability to predict trends across various locations within the system, even when trained on data from a distinct reading point. The objective was to determine how well the model could be extended to other parts of the DMS, particularly for locations with limited or no historical data, and to evaluate its generalizability across the system.
4.4. Comparison with State-of-the-Art Methods
Finally, the LSTM model results were compared with those obtained from the widely used ML and traditional methods, specifically, RF, ARIMA, and CNN. The comparison was made based on the same test cases as the initial LSTM model evaluation. For the sake of brevity, only the TR2 measurement point acquisitions (power, current, and voltage) were used.
The ARIMA model was implemented using the statsmodels Python library (version 0.14.4). The order of the ARIMA model was set to (p = 5, d = 1, and q = 0) for the autoregressive, differencing, and moving average components, respectively. The seasonal component was initially considered in the model but was later omitted due to its significant impact on training times.
The Random Forest model was implemented using the scikit-learn Python library (version 1.6.0). The model was configured with 100 estimators (trees).
For the CNN model, a custom architecture was defined using PyTorch (version 2.4.0). The model consisted of two 1D convolutional layers, with 32 and 64 output channels, respectively, and kernel sizes of 3. These were followed by max-pooling layers to down-sample the feature maps. After the convolutional layers, the output was flattened and passed through two fully connected layers, with the final layer outputting the predicted values. The number of hidden units in the fully connected layers was set to 64. The model used Rectified Linear Unit (ReLU) activation after each convolutional and fully connected layer, and the Adam optimizer was used for training with a learning rate of 0.001. The model was trained for 50 epochs with a batch size of 256, and the loss function used was MSE, as for the LSTM model.
4.5. Evaluation Metrics
Various metrics are used to evaluate model performance in energy consumption forecasting, including Mean Absolute Error (
MAE), Mean Absolute Percentage Error (
MAPE), Root Mean Square Error (
RMSE), and the Coefficient of Determination (
R2) [
41].
MAE is defined as follows:
where
is the total number of estimations,
the reference value, and
the estimated value.
MAE metric measures the average of the absolute differences between predictions and actual values.
RMSE is defined as follows:
where quantities have been already defined.
RMSE calculates the square root of the average of the squared differences between predictions and actual values, offering a measure of the standard deviation of errors.
MAPE, defined as
assesses the accuracy of predictions by averaging the absolute percentage errors relative to actual values.
Lastly, the
R2 score is defined as follows:
where
is the mean of the actual values. The
R2 score indicates the proportion of variance in the dependent variable (output feature) explained by the independent variables (input features) of the model.
R2 scores range from 0 to 1, with higher values indicating better predictive ability. Four different metrics were selected to exploit their different meaning to have a comprehensive evaluation of the forecasting approach.
6. Conclusions
This study presents a robust AI-based solution for enhancing energy management in educational buildings through a distributed measurement system. By forecasting critical electrical quantities—such as voltage, current, and power—the approach provides real-time insights that support efficient energy use, renewable integration, and operational cost reduction. The system’s capacity to forecast even in the presence of missing data demonstrates its resilience and utility in dynamic environments. The paper highlights the importance of reliable data collection, addressing the uncertainties related to instrument transformers and environmental influences, which are vital for maintaining measurement accuracy. Through extensive experimental testing and validation, the model proves effective in optimizing the performance of distributed measurement systems. Overall, the integration of AI in this infrastructure offers a promising foundation for the development of DT, enhancing energy management, predictive maintenance, and operational insights. By combining diverse technological elements—AI, distributed sensing, data management, and cloud systems—into a cohesive framework, this work contributes a comprehensive approach to sustainable energy management in complex infrastructures.