-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP4_examineCasesInterpLinear.m
93 lines (78 loc) · 2.64 KB
/
P4_examineCasesInterpLinear.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
clc;
clearvars -except id
close all;
if ~exist('id','var')
id=1;
end
idstr = sprintf('%03d',id);
% datasetfolder='CSV/Selected/';
% dataset='ProcessedDataset001/';
% resultsfolder='CSV/Selected/Results/';
% datasettarget='dataset001';
datasetfolder='CSV/';
dataset=['ProcessedDataset' idstr '/'];
resultsfolder='CSV/Results/';
datasettarget=['dataset' idstr];
writecompleted=true;
completedfolder=[datasetfolder dataset 'Completed/'];
Data=csvread([datasetfolder dataset 'initial.csv']);
Omega=zeros(size(Data));
resultsCollection=[];
H=dir([datasetfolder dataset '*.csv']);
H=H(2:end,:);
for k=1:length(H)
% for k=1:20
fnm=H(k).name;
spl = strsplit(fnm,'.');
spl2=strsplit(spl{1},'_');
missing=str2num(spl2{3});
permnumber=str2num(spl2{4});
Case=csvread([datasetfolder dataset fnm]);
y=reshape(Case,1,[]);
nz=find(y);
y=[y(nz(1)) y y(nz(end))]; %padding
x=linspace(1,length(y),length(y));
xq=1:length(y);
x(y==0)=[];
y(y==0)=[];
Result = interp1(x,y,xq);
Result=Result(2:end-1);
xq=1:length(Result);
GroundTruth=reshape(Data,1,[]);
if writecompleted
completed=reshape(Result,size(Data));
csvwrite([completedfolder 'completed_linear_' fnm],completed);
end
deltaGroundTruth=GroundTruth(2:(end))-GroundTruth(1:(end-1));
deltaResult=Result(2:(end))-Result(1:(end-1));
PE=norm(GroundTruth-Result)/norm(GroundTruth);
NMSE=(mean((GroundTruth-Result).^2)/mean((GroundTruth-mean(GroundTruth)).^2));
NRMSE=sqrt(NMSE);
PEDelta=norm(deltaGroundTruth-deltaResult)/norm(deltaGroundTruth);
NMSEDelta=(mean((deltaGroundTruth-deltaResult).^2)/mean((deltaGroundTruth-mean(deltaGroundTruth)).^2));
Bins=linspace(40.5,179.5,140);
Ghist=histogram(GroundTruth,Bins);
GhistV=Ghist.Values;
GhistV=GhistV/sum(GhistV);
Rhist=histogram(Result,Bins);
RhistV=Rhist.Values;
RhistV=RhistV/sum(RhistV);
dHist=100*(mean((GhistV-RhistV).^2)/mean((GhistV-mean(GhistV)).^2));
%GFreq=10*log10(abs(fft(GroundTruth).^2));
%GFreq=GFreq(1:((length(GFreq)/2)+1));
%RFreq=10*log10(abs(fft(Result).^2));
%RFreq=RFreq(1:((length(RFreq)/2)+1));
figure(3)
plot(GhistV)
hold on
plot(RhistV)
hold off
PE=100*PE;
PEDelta=100*PEDelta;
NMSE=100*NMSE;
NMSEDelta=100*NMSEDelta;
NRMSE=100*NRMSE;
resultsCollection=[resultsCollection; [missing NMSE NRMSE PE dHist] ];
disp(['Missing : ' num2str(missing) ' NMSE : ' num2str(NMSE) ' NRMSE : ' num2str(NRMSE) ' PE : ' num2str(PE) ' dPE : ' num2str(PEDelta) ' dNMSE : ' num2str(NMSEDelta) ' Hist : ' num2str(dHist) ]);
end
csvwrite([resultsfolder datasettarget '_linear.csv'],resultsCollection);