Feedforward Neural Network with Sliding Windows approach to forecast output values
10 views (last 30 days)
Show older comments
Luciano Manuel
on 10 Dec 2024
Commented: Luciano Manuel
on 17 Dec 2024
Dear friends,
I'm a PhD student of Agricultural, Nutrion and Environment, so my background is not so fond in artificial intelligence and machine learning. Nonetheless I'm working with artificial neural network applied in livestock and zootechnics. Most of my MATLAB knowledge has been obtained through selflearning and MATLAB courses
At the moment I have figured out how to create a FNN (regression) models with an acceptable value of accuracy (I used R^2 to evaluate the models; futhermore, this value have been mediated hourly). To clarify, these nets have been trained with an input matrix of 9 variables (with a variable numbers of string, correspondig to a different time series of sampling) and with a single output that I need to predict. My next step of my PhD aim is to create accurate models able to make predictions.
After an evaluation of the state of art, I have chosen to make same trials with a sliding windows approach. Now let's go further with string and codes.
1) First of all, I create my ANN:
net=feedforwardnet([ neurons and hidden layers have been assessed in previous trials ])
2) Training:
[net,tr]=train(net,input,output) - If the R^2 is acceptable, I deemed the net sufficient and I went to the next step
3) Prediction:
pred=net(input) - With this string I obtained a matrix of prediction with the same amount of string
The work is not yet completed because I need to do a step further. The question is: Can this net be able to forecast my output in the future? (After 24, 48, or 72h from the sampling of the inputs, for example?)
As I have said in the title, the solution that I have chosen for my question is the sliding windows (I'm open to other solution as well). I have scavenged internet to obtain some suggestions. This is the code with I'm struggling:
% Number of predictions to generate
window_size = 720; % Size of the sliding window - Should it be the same value of the input matrix?
num_predictions = 24; % For example, predict 24 hours/future values
% Initial input for predictions
current_input = input(end-window_size+1:end); % Last time window
% Array to store results
predictions = zeros(1, num_predictions);
for i = 1:num_predictions
% Next prediction
next_prediction = sim(net, input);
% Save the prediction
predictions(i) = next_prediction;
% Update input window
current_input = [current_input(2:end), next_prediction];
end
An error popped up:
Unable to perform assignment because the left and right sides have a different number of elements.
I can't figured out if I'm totally out of the road with the aformentioned code and approach or I'm close to achieve something.
Thanks to you all.
Best regards,
Manuel
0 Comments
Accepted Answer
colordepth
on 16 Dec 2024
Edited: colordepth
on 16 Dec 2024
To forecast future values using neural networks with a sliding window approach, you may want to consider models that are specifically designed for time series data. Feedforward neural networks might not be the best choice for time series forecasting due to their lack of temporal context. Instead, you might benefit from using models like Long Short-Term Memory (LSTM) networks, which are better suited for capturing temporal dependencies in data.
I recommend exploring the following resources to enhance your understanding of time series forecasting with deep learning in MATLAB. These guides introduce the key concepts and methodologies involved in timeseries forecasting:
More Answers (0)
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!