Help with ANFIS time series prediction
Show older comments
Hello,
I am trying to use ANFIS to perform time predictions on some data. More precisely, I want to make prediction on a set of data based on the past values of the same data. I first generate my time series based on the original data and the delays I want to use:
load('TrainingData.mat'); % Vector 'x' is loaded with original data
Delays = [1 2 3 4 5 6 7 8 9];
DelayNum = length(Delays);
[Inputs, Targets] = CreateTimeSeriesData(x, Delays);
Inputs = Inputs';
Targets = Targets';
The "Inputs" vector contains [x(t-1), x(t-2), x(t-3) ... x(t-9)] on each column, according to the delays vector I chose, for t from 0 to N, where N is the size of x. "Targets" is a vector composed by x(t) with t = 0 to N again. I then divide the time series into two: one for training (TrainInputs, TrainTargets) and another one for validation (ValInputs, ValTargets). Next step is generating the FIS using genfis3 and train the system with ANFIS passing some additional options:
fis = genfis3(TrainInputs, TrainTargets);
opt = anfisOptions;
opt.ValidationData = [ValInputs ValTargets];
opt.InitialFIS = fis;
fis = anfis([TrainInputs TrainTargets],opt);
The reason I am using genfis3 is that every time I try and use genfis, MATLAB gives me the ever feared "Loop is too big" error and proceeds to eat up all of my RAM to the point where I have to force-reset the computer.
Now, prediction is the last and most tricky step. Its the one I am in doubt about. After doing error calculations and plots to check if FIS training performance is good, which it seems to achieve almost everytime, I generate a new time series based on another set of data, PredictionData:
load('PredictionData.mat');
Limit = 150; %This is the number of points where I assume data generation for the "PredictionData" set has stopped. I have to predict the rest of the data (which is until data point number 315).
xPred = x(1:Limit);
xPredTotal = x;
[PredInputs, PredTargets] = CreateTimeSeriesData(xPred, Delays);
PredInputs = PredInputs';
PredTargets = PredTargets';
Lastly, I use an evalfis loop to predict a future value for the inputs, and feedback the predicted value into evalfis again, and so on:
PredSteps = 315 - Limit;
PredInput = PredInputs(length(PredInputs),:);
PredOutputs = zeros(1, PredSteps);
for i = 1:PredSteps
PredOutputs(i) = evalfis(PredInput,fis);
PredInput = ProcessInput(PredInput, PredOutputs(i));
end
The results unfortunately don't look very good:

By looking at the final results, what I imagine is that the FIS prediction (in red) is just following the training data pattern (in cyan) with a time shift of ~80 points late. My first guess, of course, is that overfit is happening. That is why I added the whole validation data thing, but that almost didn't make any difference. In the help and doc sections of anfis, evalfis and anfisOptions, that is the only hint I found about reducing the chance of overfitting in ANFIS, so it seems I ran out of options.
So my questions are: is the prediction process correct? In case it is and the results I am seeing are the ones the FIS is supposed to produce, what can I do to make it a little more "reactive" and more responsive to prediction data?
Thanks,
Jonas
Answers (0)
Categories
Find more on Fuzzy Logic Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!