Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. % Karapatsias Vasileios (8155)
  2. % Sismanis Michail (8242)
  3. % Part B (non linear)
  4. % Timeseries 2018-2019 , AUTh
  5.  
  6. %% Initialize the dataset
  7. clc
  8. clear all;
  9. close all;
  10. addpath('functions_non_linear/');
  11. addpath('functions_linear/');
  12.  
  13.  
  14. fprintf("Importing the dataset.\n");
  15. dataset = importdata('dat11.dat');
  16. dataLength = length(dataset);
  17.  
  18. fprintf("Resampling every 6th day. . .\n");
  19. % myData = dataset(1:6:dataLength);
  20. myData = resample(dataset,1,6);
  21. dataLength = length(myData);
  22.  
  23. figure;
  24. clf
  25. plot(myData)
  26. title('Initial Timeseries (cont)')
  27. saveas(gcf,'partBb_figures/initial_contin.png')
  28.  
  29. figure;
  30. plot(myData,'.','markersize',6)
  31. title('Initial Timeseries (disc)')
  32. saveas(gcf,'partBb_figures/initial_disc.png')
  33.  
  34. figure;
  35. plot(myData)
  36. hold on
  37. plot(myData,'.','markersize',6)
  38. title('Initial Timeseries (both)')
  39. saveas(gcf,'partBb_figures/initial_both.png')
  40.  
  41. % Initial autocorrelation
  42. Maxtau = 100;
  43. alpha = 0.05;
  44. zalpha = norminv(1-alpha/2);
  45. autlim = zalpha/sqrt(dataLength);
  46.  
  47. figure;
  48. initialAutocorr = autocorrelation(myData, Maxtau,'Initial ');
  49. saveas(gcf,sprintf('partBb_figures/initial_autocorrelation.png'));
  50.  
  51.  
  52. % Trend Removal (First Differences)
  53. firstDiffResult = diff(myData,1);
  54. figure;
  55. clf
  56. plot(firstDiffResult)
  57. hold on
  58. plot(firstDiffResult,'.','markersize',6)
  59. xlabel('t')
  60. ylabel('x(t)')
  61. title('Detrended time series by first differences smooth')
  62. saveas(gcf,'partBb_figures/detrended_timeseries.png');
  63. % set(gcf, 'Visible', 'off');
  64.  
  65. %% 2d - 3d scatter diagrams
  66.  
  67. delays = embeddelays(firstDiffResult,3,1);
  68. plotd2d3(delays, 'Timeseries Scatter Plot');
  69.  
  70. %% Choose tau and m
  71.  
  72. % Detrended autocorrelation
  73. % r=0 or r = 1/e
  74. figure;
  75. firstDiffautocorr = autocorrelation(firstDiffResult, Maxtau,'Detrended');
  76. hold on;
  77. plot([0 Maxtau+1],0*[1 1],'-','linewidth',0.5)
  78. saveas(gcf,sprintf('partBb_figures/detrended_autocorrelation.png'));
  79.  
  80. % Mutual Information (first local minima)
  81. figure;
  82. mutM = mutualinformation(firstDiffResult, Maxtau, [],'','.-');
  83. saveas(gcf,sprintf('partBb_figures/mutual_information.png'));
  84. tau = 1;
  85. mmax = 10;
  86.  
  87. % False Nearest Neighbors
  88. figure;
  89. fnnM = falsenearest(firstDiffResult,tau,mmax,[],[],'My');
  90. saveas(gcf,sprintf('partBb_figures/fnn.png'));
  91.  
  92. %% Correlation dimension
  93. m = 5;
  94. [rcM,cM,rdM,dM,nuM] = correlationdimension(firstDiffResult,tau,m,'tau=1','m=5');
  95.  
  96. %% Prediction
  97.  
  98. numOfValidation = floor(0.4*dataLength);
  99. numOfTraining = dataLength-numOfValidation;
  100.  
  101. k = 15;
  102. q = 10;
  103. Tmax = 20;
  104.  
  105. figure;
  106. [nrmseV,preM] = localfitnrmse(firstDiffResult,tau,m,Tmax,k,q,' ');
  107.  
  108. figure;
  109. [nrmseP,preP] = localpredictnrmse(firstDiffResult,numOfValidation,tau,m,Tmax,k,q,' ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement