forked from alok-ai-lab/DeepInsightTab2Image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalization.m
80 lines (73 loc) · 2.27 KB
/
normalization.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
function [Parm,model] = normalization(Parm,model)
% [Parm,model] = normalization(Parm)
% (when using training data)
%
% data = normalization(data,model);
% (when using test or validation data).
%
% Norm-1 or Norm-2 as per DeepInsight, 2019 paper
if nargin==1
layer=size(Parm.Xtrain,3);
elseif nargin==2
data = Parm;
clear Parm
Parm.Norm = model.Parm.Norm;
layer = model.C;
end
switch Parm.Norm
case 1
fprintf('\nNORM-1\n');
%########### Norm-1 ###################
for dsz=1:layer
if nargin==1
model.Max{dsz}=max(Parm.Xtrain(:,:,dsz)')';
model.Min{dsz}=min(Parm.Xtrain(:,:,dsz)')';
Parm.Xtrain(:,:,dsz)=(Parm.Xtrain(:,:,dsz)-model.Min{dsz})./(model.Max{dsz}-model.Min{dsz});
else
data(:,:,dsz) = (data(:,:,dsz)-model.Min{dsz})./(model.Max{dsz}-model.Min{dsz});
end
end
if nargin==1
Parm.Xtrain(isnan(Parm.Xtrain))=0;
else
data(isnan(data))=0;
data(data>1)=1;
data(data<0)=0;
end
case 2
fprintf('\nNORM-2\n');
%########### Norm-2 ###################
for dsz=1:layer
if nargin==1
model.Min{dsz}=min(Parm.Xtrain(:,:,dsz)')';
Parm.Xtrain(:,:,dsz)=log(Parm.Xtrain(:,:,dsz)+abs(model.Min{dsz})+1);
else
indV = data(:,:,dsz)<model.Min{dsz};
for j=1:length(model.xp)
data(j,indV(j,:),dsz)=model.Min{dsz}(j);
%Parm.Xtest(j,indT(j,:),dsz)=model.Min{dsz}(j);
end
data(:,:,dsz) = log(data(:,:,dsz)+abs(model.Min{dsz})+1);
end
%Parm.Xtest(:,:,dsz)=log(Parm.Xtest(:,:,dsz)+abs(model.Min)+1);
if nargin==1
model.Max{dsz}=max(max(Parm.Xtrain(:,:,dsz)));
Parm.Xtrain(:,:,dsz)=Parm.Xtrain(:,:,dsz)/model.Max{dsz};
else
data(:,:,dsz) = data(:,:,dsz)/model.Max{dsz};
%Parm.Xtest(:,:,dsz) = Parm.Xtest(:,:,dsz)/model.Max;
end
end
if nargin==2
data(data>1)=1;
%Parm.Xtest(Parm.Xtest>1)=1;
end
end
if nargin==2
Parm=data;
if nargout==2
disp('Warning: model file is from deepinsightTab2Img!');
disp(['The function deepinsighConv does not provide a new ' ...
'model struct!']);
end
end