saker
unknown
matlab
3 years ago
3.5 kB
4
Indexable
addpath '/Users/noahakesson/MATLAB-Drive/Comp2/Tidserie/functions' addpath '/Users/noahakesson/MATLAB-Drive/Comp2/Tidserie/data' addpath '/Users/noahakesson/MATLAB-Drive/Comp2/Tidserie/projDatafiles' %% clc clear all close all %% debugging creating own data % For debugging, try generating data that has similar characteristics. % N = 10000; extraN = 100; time = 1:N; % C = [ 1 ]; % A = conv([1 -1],[ 1 0.37 ]); % e = randn( N+extraN, 1 ); % data = filter( C, A, e ); data = data(extraN+1:end) + 1000; % figure % plot(data) % noLags = 100; %% load('utempSla_9395.dat') date=utempSla_9395(:, 1); hour=utempSla_9395(:, 2); data=utempSla_9395(:, 3); %% behövs bara för att ta fram datum %sve_date9395 = utempSla9395.VarName1; %% interpolate data % Remove and interpolate the zeros data = remove_and_interpolate_zeros(data); % Print the interpolated data plot(data(10000:11680)) %% %M-data l=24*7*10; start_M=(length(data)/2)+140; last_M=start_M+l; review_Kstad(data(start_M:last_M), 200) %review_Kstad(utempSla_9395(:, 3), 200) %V-data l2=24*7*2; start_V=last_M; last_V=start_V+l2; %Hoppa över-data l3=24*7*25; start_T=last_V; last_T=start_T+l3; %Test-data l4=24*7*2; start_T=last_T; last_T=start_T+l4; review_Kstad(data(start_T:last_T), 200) %% creat arrays containing the different sets of data data_modeling = data(start_M:last_M); data_validation = data(start_V-24:last_V); data_prediction = data(start_T:last_T); data_comb_mod_val = data(start_M:last_V) %% Lets form the k-step prediction. k=1 % Define the number of steps to look back stepsBack = 24; % Create an array to hold the predicted values yhatk = zeros(length(data_validation),1); % Loop through the input data and make predictions for i = 1:length(data_validation) % If we are on the first few values, we can't predict anything if i <= stepsBack yhatk(i) = 0; else % Make the prediction by using the value from 24 steps back yhatk(i) = data_validation(i - stepsBack); end end % Print the predictions yhatk % Predict future values %data_validation_differentiated_temp = data_validation_differentiated(24:end) data_validation = data_validation(25:end); yhatk = yhatk(25:end) ehat = data_validation - yhatk; checkIfWhite( ehat ); var(ehat) %% Lets have a look at the prediction, comparing it to the true data. % Looking at the figure, note that: % 1) The prediction appears to be shifted k step to the data (it should be, so this is correct). % 2) The inital k predicted values are zeros due to the zeros in the G polynomial. k=1 noLags = 100 figure plot(data_validation) hold on plot(yhatk) hold off %axis([time(1) time(end) 0.8*min(data(10:end)) 1.2*max(data(10:end)) ]) legend('True data', sprintf('%i-step predition', k), 'Validation starts', 'Location','NW') title('US tobacco production') %% How does the model work? % We focus only on the validation data. Note that we now also remove the % inital corrupted samples due to the filtering. % Note that the prediction residual should only be white if k=1. figure acfEst = acf( ehat, noLags, 0.05, 1 ); title( sprintf('Prediction residual, %i-step prediction', k) ) fprintf('This is a %i-step prediction. Ideally, the residual should be an MA(%i) process.\n', k, k-1) checkIfWhite( ehat ); %% What does the D'Agostino-Pearson's K2 test indicate? % As the PACF should ring for an MA(k-1) process, we only check the ACF. checkIfNormal( acfEst(k+1:end), 'ACF' );
Editor is loading...