### Blog: SolarSVM: How Machine Learning can help Global Warming

Global warming and climate change are at the worst they have been, and a solution to the problem of supplying energy to the world effectively and in a sustainable way is nowhere to be found. A key issue with sustainable energy is the lack of consistency in the output of the energy sources. For example, in wind energy, the energy output of the wind turbines depend heavily on the strength of the winds at that particular point in time. As such, when the strength and direction of wind changes according to weather patterns, so does the energy output. This makes it very challenging to use energy from wind turbines as a major output of energy for homes and industries.

The same issue exists in solar energy. Even as we are making good progress in improving the efficiency of our solar cells, by even using photonic technologies, we are limited by the uncertain nature of the energy output due to changes in solar irradiance levels throughout the day. Therefore, we need to come up with some sort of a system to predict when solar irradiance will be low or high and use that information to choose how much of the total energy demand should be met with solar energy (and other sustainable energy sources).

#### How ML can help

Predicting short term changes in a time series with noise and nonstationarity is essentially bread and butter for machine learning. It is exactly for these problems that machine learning are used for. That is why I believe we can use machine learning to develop model that predict short term changes in solar irradiance and use that for our energy needs.

#### SolarSVM

SolarSVM is a project that I worked on a while ago, where I used dimensionality reduction and SVM regression to predict the short term changes in the solar irradiance levels, with an exploration of how to use the predictions to maintain overall energy supply whilst maximizing the use of sustainable energy resources. The interested reader can read the full paper, available on SSRN, **here**.

The outline of the model is as follows:

- Acquire weather data including wind speed, direction, temperature and pressure.
- Use t-SNE to extract features from the dataset.
- Apply SVM regression to predict the solar irradiance values in the future.
- Use the predictions to allocate how much of the energy supply should be from sustainable energy sources.

I will now go through the individual components of the model.

#### Weather Data

I struggled for quite a while to find adequate weather data with solar irradiance values. However, the data that I used from a Kaggle dataset posted by NASA with weather and solar irradiance measures. Here is a snapshot of the dataset:

The data is hourly weather data and consisted of approximately 33000 rows of data. The relative lack of data (in the context of machine learning) means that the model that I use cannot be too complicated. Furthermore, the number of features used should be limited as adding extra features, that do not necessarily provide information regarding the dynamics of solar irradiance would only serve as unnecessary noise that is going to deter the performance of the model. Therefore, I chose SVM regression as the model to use, and even then, I tried to limit the number of features used to a minimum.

#### Dimensionality Reduction using t-SNE

This brings us to the issue of dimensionality. After using past values as my features, I ended up with a total of 25 features per row, and that meant that realistically, my model did not have enough data to effective model the dynamics of the solar irradiance. Also, there is no guarantee that the features are all of equal importance and of any importance at all. Although there are several methods to reduce the dimensions of the problem, such as PCA or multifactor modelling, I opted for manifold learning for two reasons:

- Nonlinear relationships can be captured that will otherwise be missed.
- Highly correlated data such as weather data would be decomposed into smaller dimensional uncorrelated data.

Therefore, I chose to apply manifold learning algorithms to decompose the 25 dimensional feature space into 3 dimensional feature space.

#### Short Revision of t-SNE

For those who are not familiar with the t-SNE algorithm, it stands for t-distributed Stochastic Neighbor Embedding. The algorithm essentially models the input data in the full feature space using a t-distribution over the distance between the adjacent points, to get a probability distribution over the feature space. Then, it tries to sample points in the lower dimensional space with certain probabilities such that the Kullback-Leibler divergence between the two data sets are minimized. Further explanation of the method can be found in my paper.

#### SVM Regression

Now that we have the features and data in a more manageable dimensional space, we can proceed to use various models to predict the solar irradiance. In this case, I used the SVM regression model to predict the solar irradiance. The SVM regression essentially finds linear functions that have error that is below a certain margin. Furthermore, the function is optimized such that the weights in the function are minimized, so to get the ‘simplest’ solution possible. This prevents the model from overfitting to the data and producing a complicated model that only works in sample. Also, I used the kernel trick to be able to model in a higher dimensional space, before mapping the function back to the original dimensional space. Again, full details are provided in the paper.

#### Results

We can now proceed to discuss the key findings in the results. The following graphs show the predictive power of the model.

Key findings to note are the following:

- The prediction is erratic in periods of low radiation, i.e at night. This is not an issue in our application, but might suggest the inherent issue with using machine learning. The weights of a machine learning algorithm can never perfectly predict that given certain conditions, the radiation will be 0. This is due to the non-constant conditions for which radiation can be 0. It raises the issue of lack of one-to-one correspondence of the regression function.
- Compared to days with smooth changes in the radiation, the predicted changes oscillate about the actual value of the radiation. This is illustrated more clearly in Figure 2.
- Over short intervals, it becomes clear the nature of the predictions. The predictions are akin to lag predictions in time series analysis, as they follow the trend with a small lag. However, this lag is not constant and in most time periods, the lag does not affect the predictive power of the machine learning algorithm. This is again illustrated clearly in Figure 2.

One thing to note is that this model serves to demonstrate the predictive power of machine learning for these problems. One can vastly improve the accuracy and reactive nature of the model by acquiring more data and fitting more sophisticated models. I was however limited by the data that I could find.

#### Exploration of Energy Balancing

Now that we have a model in place for predicting the future values of the solar irradiance, we can proceed to explore how we can use this information to then build a system that chooses how much of the energy demand to be met using solar energy. Obviously, this procedure need not be restricted to solar energy, but can be extending to many other sustainable energy resources.

Due to the inherently stochastic nature of the variables we deal with, either because they are stochastic due to measurement noise or fundamentally stochastic, it seems appropriate to borrow ideas from stochastic optimal control theory to balance the energy demand with supply.

The key issue is determining how the level of solar irradiance affects the energy output from the solar cells. Although this might be a deterministic relationship, we should allow for stochastic relationship as there might be some short term factors that affect the output efficiency of the solar cells. Consequently, letting the function that determines the output energy from solar cells be f(r), and r being the irradiance, with h(t) being the policy function that we want to control, we get the following stochastic optimal control problem

Where the value function V(P(t)) is the difference between the current energy output and the required energy output (demand basically). Now, we can solve this problem by applying the Hamilton Jacobi Bellman equations, which would give

Sadly, HJB equations are almost always analytically intractable (unless the problem is very well and simply defined). However, we can use numerical methods and simulations to build the optimal policy.

#### Reinforcement Learning?

One approach that I have been thinking about recently is using Reinforcement Learning instead of HJB equations to solve for the optimal policy for minimizing the non renewable energy usage. It seems promising as the problem is very alike other RL problems. However, I am limited by the amount of data I have to be able to effectively investigate this problem. If any of you have access to weather data that would be useful for me to try RL in this problem, do not hesitate to contact me. I will be more than happy to attempt this approach.

#### Conclusion

Human need for energy is unlikely to decrease to the point that using coal and fossil fuels will suffice as energy sources without damaging the Earth’s climate. Therefore, we are forced to act and incorporate alternative energy sources. So, we need to look at technology and AI to give us the tools required to develop and maintain an infrastructure that will help the energy demands to be met, while also minimizing the carbon footprint generated by people and industries.

## Leave a Reply