## 4 Data-Driven and Contextual Optimisation Forecasting Algorithm
### Contextual Optimisation  
The second part of the DCF algorithm optimised the accuracy of the data-driven predictions using the contextual information of solar irradiance. This information was derived from comparing the forecasted values to the measured values, thus not relying on a specific location/time. As shown in Figure 4, optimisation had three steps. It was observed that the data-driven approaches forecasted negative values, so these negative values were eliminated. Then, the forecasted values were amended based on the time of sunrise and sunset, (a similar approach were taken in [19] daytime forecasting). Here, we used two approaches: one static, in which night hours were defined from 8 p.m. to 6 a.m., and one dynamic which determined the hours of sunset and sunrise. The static approach was implanted by [PERSON] and [PERSON], producing good results [28]. The dynamic approach is a more accurate representation of reality and thus can be more flexibly implemented in any location. However, it requires additional computational power. The last step was the seasonal adaptation in which we amended the forecasted values in the long-term model according to the month of the year. FBP generated large negative values for both long- and short-term predictions. For all negative predictions (which only occurred in winter), the target value was zero. This shows that FBP only forecasted negative values during the night hours, as shown in Figure 5. In summer, all night hour predictions were positive. As there could not be negative irradiance and most negative predictions occurred at night, all negative values were eliminated and set to zero. The SVM model also predicted some negative values (around 5% for short-term and 50% for long-term). For most predictions with negative values, the target value was zero. For the non-zero target values, the radiation was very low (maximum of 15 W/m2). Therefore, here too, all negative values were set to zero. After eliminating the negative values, all values between 8 pm and 6 am were set to zero, as they were considered night hours [28]. However, this static approach does not represent that sunrise and sunset hours vary over the year. Therefore, the sunset and sunrise for every day of the year were determined and subsequently used to set all values between sunset and sunrise to zero. Both static and dynamic methods were implemented to compare their impact on the model accuracy. A seasonal adaptation was created for the long-term models, as a general trend was detected. For instance, the long-term FBP model would overpredict in summer and underpredict in winter, especially for the model without extraterrestrial radiation. Further, there was over- and underprediction trends in both seasonal and daily forecasts. For example, in some months, morning and evening hours were underpredicted, while the noon hours were overpredicted, as shown in Figure 6. The seasonal adaptation aimed to prevent these general trends of over- and underpredicting. The model with extraterrestrial radiation displayed less of a yearly seasonal trend; however, the daily trend still existed. Figure 4: Contextual optimisation block diagram showing the three main steps. Figure 5: Three days of long-term FBP prediction displaying negative values at night. For the seasonal adaptation, for every hour of the day within each month (e.g., the 6 th hour of every day in January), all values from previous years were collected. The average of these target values for the particular hour was taken for each month, as shown in Figure 7. The same was carried out for the predicted values. Three different versions of average were used: the mean (V1), the median (V2), and the mean of median and mean (V3). The seasonal adaptation adjusted the values according to the month of the year by increasing/decreasing every predicted value that was on average lower/higher than the target values of the same hour of the day of that month in past years.