# Optimizing Energy Forecasting Using ANN and RF Models for HVAC and Heating Predictions
## 2 Methodology
### Model Development (ANN)  
Artificial Neural Networks (ANNs) have rapidly become a revolutionary machine learning method as they are designed based on biological neural networks. ANNs are information processing systems that organize a series of artificial neurons in a layered structure, which usually consists of three main layers (input, hidden, and output layers). Each neuron processes the information in a set of weighted inputs combined with a nonlinear activation function. This allows ANNs to recognize complex patterns or relationships within the data. Due to their inherent flexibility, ANNs can be used in a variety of fields such as computer vision, speech recognition, natural language processing, and financial modeling. They excel at recognition tasks because they can model complicated nonlinear relationships in the data and generalize well. Most ANNs are trained using backpropagation algorithms, which adjust the ANN weights using training data to reduce the prediction error. This incremental optimization of weights is based on reducing the cost function, which develops the performance of the ANN based on the dataset size for training [38; 39; 40].  
Mathematical Model (ANN)  
The ANN model developed for the Lucia Building in Valladolid incorporates 11 input variables, while the model for the FUHEM Building in Madrid accounts for similar energy demand drivers. These inputs include historical energy consumption data, weather parameters, and occupancy-related indicators, all of which directly influence heating, which is particularly relevant given Valladolid's colder climate. The careful selection of these variables was critical as they directly correlate with heating requirements and energy consumption patterns. The model is designed to provide precise energy demand forecasts, enabling building management systems to optimize energy use and improve sustainability through data-driven decisions [41].  
The ANN architecture consists of two hidden layers designed for distinct purposes. The first hidden layer extracts key patterns from input data, while the second enhances the model's ability to generalize these patterns to unseen data. Both layers employ ReLU (Rectified Linear Unit) activation functions to effectively model complex nonlinear relationships in the data. The output layer utilizes a linear activation function to generate continuous energy demand forecasts, making the model suitable for real-time energy management applications. For network training, we implemented the Levenberg-Marquardt algorithm, a robust approach for nonlinear least squares optimization. This algorithm synergizes gradient descent and Gauss-Newton methods, offering both rapid convergence and training efficiency. During training, connection weights between neurons are iteratively adjusted to minimize the discrepancy between predicted and actual energy demand values. The model was trained on 2020 data, with separate training and validation subsets used to monitor performance and prevent overfitting [42].  
The ANN model developed for the Lucia building addresses Europe's growing energy demands, particularly in colder climate regions. By analyzing historical data through neural networks, the model provides actionable insights to facility managers, enabling more efficient energy use and cost optimization while supporting sustainable energy practices. An Artificial Neural Network with two hidden layers can be described mathematically as in Table 3[43].