Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Karapatsias Vasileios (8155)
- % Sismanis Michail (8242)
- % Part B (non linear)
- % Timeseries 2018-2019 , AUTh
- %% Initialize the dataset
- clc
- clear all;
- close all;
- addpath('functions_non_linear/');
- addpath('functions_linear/');
- fprintf("Importing the dataset.\n");
- dataset = importdata('dat11.dat');
- dataLength = length(dataset);
- fprintf("Resampling every 6th day. . .\n");
- % myData = dataset(1:6:dataLength);
- myData = resample(dataset,1,6);
- dataLength = length(myData);
- figure;
- clf
- plot(myData)
- title('Initial Timeseries (cont)')
- saveas(gcf,'partBb_figures/initial_contin.png')
- figure;
- plot(myData,'.','markersize',6)
- title('Initial Timeseries (disc)')
- saveas(gcf,'partBb_figures/initial_disc.png')
- figure;
- plot(myData)
- hold on
- plot(myData,'.','markersize',6)
- title('Initial Timeseries (both)')
- saveas(gcf,'partBb_figures/initial_both.png')
- % Initial autocorrelation
- Maxtau = 100;
- alpha = 0.05;
- zalpha = norminv(1-alpha/2);
- autlim = zalpha/sqrt(dataLength);
- figure;
- initialAutocorr = autocorrelation(myData, Maxtau,'Initial ');
- saveas(gcf,sprintf('partBb_figures/initial_autocorrelation.png'));
- % Trend Removal (First Differences)
- firstDiffResult = diff(myData,1);
- figure;
- clf
- plot(firstDiffResult)
- hold on
- plot(firstDiffResult,'.','markersize',6)
- xlabel('t')
- ylabel('x(t)')
- title('Detrended time series by first differences smooth')
- saveas(gcf,'partBb_figures/detrended_timeseries.png');
- % set(gcf, 'Visible', 'off');
- %% 2d - 3d scatter diagrams
- delays = embeddelays(firstDiffResult,3,1);
- plotd2d3(delays, 'Timeseries Scatter Plot');
- %% Choose tau and m
- % Detrended autocorrelation
- % r=0 or r = 1/e
- figure;
- firstDiffautocorr = autocorrelation(firstDiffResult, Maxtau,'Detrended');
- hold on;
- plot([0 Maxtau+1],0*[1 1],'-','linewidth',0.5)
- saveas(gcf,sprintf('partBb_figures/detrended_autocorrelation.png'));
- % Mutual Information (first local minima)
- figure;
- mutM = mutualinformation(firstDiffResult, Maxtau, [],'','.-');
- saveas(gcf,sprintf('partBb_figures/mutual_information.png'));
- tau = 1;
- mmax = 10;
- % False Nearest Neighbors
- figure;
- fnnM = falsenearest(firstDiffResult,tau,mmax,[],[],'My');
- saveas(gcf,sprintf('partBb_figures/fnn.png'));
- %% Correlation dimension
- m = 5;
- [rcM,cM,rdM,dM,nuM] = correlationdimension(firstDiffResult,tau,m,'tau=1','m=5');
- %% Prediction
- numOfValidation = floor(0.4*dataLength);
- numOfTraining = dataLength-numOfValidation;
- k = 15;
- q = 10;
- Tmax = 20;
- figure;
- [nrmseV,preM] = localfitnrmse(firstDiffResult,tau,m,Tmax,k,q,' ');
- figure;
- [nrmseP,preP] = localpredictnrmse(firstDiffResult,numOfValidation,tau,m,Tmax,k,q,' ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement