## 2 Materials and Methods
### CEEMDAN-CNN-ATT-LSTM Model
2:Step 1: CEEMDAN Decomposition of Irradiance
3: Initialize CEEMDAN parameters: trials, noise level, siftings
4: Apply CEEMDAN to decompose the irradiance data \(\mathbf{h}\) into Intrinsic Mode Functions (IMFs) and a residue
5: Append IMFs and residue to the feature set \(\mathbf{X}\)
6:Initialize:
7: Load configuration parameters: hidden layers \(hl\), batch size \(bs\), epochs \(e\), patience \(p\)
8: Initialize model \(M=model(hyperparameters)\)
9: Apply weight initialization \(M.apply(initialize\_weights)\) and move model to device
10: Define loss criterion \(\mathcal{L}=\mathrm{L1 Loss}()\)
11: Define optimizer \(O=\mathrm{Adam}(M.parameters(),lr=Lr)\) and scheduler
12: Initialize variables: best_val_loss = \(\infty\), patience_counter = 0
13: Load \(X_{training}\), \(X_{test}\), \(X_{val}\) and irradiance history \(h\)
14: Create DataLoader iterators for training, validation, and test data with batch size \(bs\)
15:for each epoch \(e\)do
16:Training Phase:
17: Set model to training mode
18: Initialize training loss to zero
19:for each batch in \(X_{training}\)do
20: Zero the parameter gradients
21:\(output=M(inputs,h)\)
22: Compute loss \(\mathcal{L}=criterion(output,targets)\)
23: Add L1 regularization \(\mathcal{L}_{reg}=\mathcal{L}+\lambda\cdot L1_{norm}(params)\)
24: Perform backpropagation \(\mathcal{L}_{reg}.backward()\)
25: Clip gradients and update model parameters
26: Accumulate training loss \(\mathcal{L}_{train}+=\mathcal{L}_{reg}\)
27:endfor
28: Compute average training loss \(\mathcal{L}_{train\_avg}=\mathcal{L}_{train}/\)number of batches
29:Validation Phase:
30: Set model to evaluation mode
31: Initialize validation loss to zero
32:for each batch in \(X_{val}\)do
33: Disable gradient computation
34:\(output_{val}=M(val\_inputs,val\_history)\)
35: Compute loss \(\mathcal{L}_{val}=criterion(output_{val},val\_targets)\)
36: Accumulate validation loss \(\mathcal{L}_{val}+=\mathcal{L}_{val}\)
37:endfor
38: Compute average validation loss \(\mathcal{L}_{val\_avg}=\mathcal{L}_{val}/\)number of batches
39:Early Stopping:
40:if\(\mathcal{L}_{val\_avg}<\) best_val_loss then
41: Update best_val_loss = \(\mathcal{L}_{val\_avg}\)
42: Save model parameters and reset patience_counter = 0
43:else
44: Increment patience_counter \(+=1\)
45:endif
46:if patience_counter \(>\)\(p\)then
47: Break training loop early
48:endif
49:endfor
```  
**Algorithm 1** Training and Prediction with CNN-LSTM-MultiHeadAttention Model```
1:Test the model using \(X_{test}\)
2: Set model to evaluation mode
3: Initialize test loss to zero
4: Initialize lists for predictions, actual values, and dates
5:for each batch in \(X_{test}\)do
6: Disable gradient computation
7:\(output_{test}=M(test\_inputs,test\_history)\)
8: Compute test loss \(\mathcal{L}_{test}=criterion(output_{test},test\_targets)\)
9: Accumulate test loss \(\mathcal{L}_{test}+=\mathcal{L}_{test}\)
10: Store predictions and actual values for future analysis
11:endfor
12: Compute average test loss \(\mathcal{L}_{test\_args}=\mathcal{L}_{test}/\)number of batches
13:Post-processing:
14: Apply EWMA smoothing to the test loss
15: Apply sliding window anomaly detection to identify possible faults
16: Compute evaluation metrics: RMSE, MAE, R2, MAPE
17: Save predictions, actual values, and metrics for reporting
18:Output:
19: Final model performance metrics and saved model for deployment or further analysis
```

**Algorithm 2** Prediction with CNN-LSTM-MultiHeadAttention Model

### Data Splitting

The dataset was divided into two parts for the forecasting model's input, taking into account the area's specific climatic conditions, which have two distinct seasons: summer and winter. Since we have data for an entire year, different periods are used for the model's training, validation, and testing. For the winter season, data from December to May 2023 are used for training, January 2024 for validation, and February 2024 for testing the model with unseen data.