-
Notifications
You must be signed in to change notification settings - Fork 23
/
ClassifyOcclusionPart.asv
142 lines (133 loc) · 3.91 KB
/
ClassifyOcclusionPart.asv
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function [cClass, SCI, Outxp] = ClassifyOcclusionPart(y, Reconstructed)
global A;
global Class;
global TrainSize;
global TestImageSize;
SCI = 0;
y = reshape(cast(y(:,:), 'double'), TestImageSize);
Parts = '';
%Parts = PartitionPart(y, 2);
%Parts = [Parts PartitionPart(y, 4)];
Parts = [Parts PartitionPart(y, 16)];
Parts = [Parts PartitionPart(X, 8, sqrt(0.5))];
Parts = [Parts PartitionPart(X, 4, sqrt(0.25))];
Parts = [Parts PartitionPart(X, 2, sqrt(0.125))];
%Parts = [Parts PartitionPart(y, 16)];
nParts = size(Parts,2);
%Classes = zeros(1, nParts);
%xps = zeros(size(Class,2), nParts);
xp = zeros(A.nElements, 1);
for i=1:nParts
[xp0, Outxp] = SolveL1(A.GetPart(i), Parts{i}, 0);
xp = xp + xp0;
end
tic
vMin = -1;
iMin = 0;
for i = 1: size(Class,2) % so lop
val = 0;
CVector = GetClassVector((i-1)*TrainSize+1, i*TrainSize, xp);
%y0 = A * CVector;
%val = abs(pdist([yR y0]'));
val = 1/norm(CVector);
if(vMin <0 | vMin>val)
vMin = val;
iMin = i;
end
end
toc
cClass = iMin;
%Classes(i) = cClass;
% iMax = -1;
% vMax = 0;
% for i=1:6
% count = 0;
% for j=1:6
% if(Classes(i) == Classes(j))
% count = count+1;
% end
% end
% if(count > vMax)
% vMax = count;
% iMax = i;
% end
% end
% cClass = iMax;
end
function [xp Outxp e1] = SolveL1(A, y, Reconstructed)
%global Test;
lambda = 1000;
%y = A*x;
% initial guess = min energy
%y = zeros(size(sample,1));
%for i =1:size(sample,1)
%y(i,1) = sample(i,1);
%end
%B = A;
%y = A'*y;
%A = A'*A;
%x0 = A'*y;
% solve the LP
B = [A eye(size(A,1))];
tic
%xp = l1eq_pd(x0, A, [], y, 1e-3);
%xp = LassoConstrained(A,y,lambda,'mode',2);
%[xp wp iteration] = LassoBlockCoordinate(A,y,lambda);
%[xp wp iteration] = LassoBlockCoordinate(B,y,lambda);
%[xp it] = SolveLasso(B, y, size(B,2), 'lars');
%[xp it] = SolveOMP(B, y, size(B,2));
%[xp it] = LassoNonNegativeSquared(B,y,lambda);
%[xp wp iteration] = LassoBlockCoordinateOri(B,y,lambda);
%[xp it] = LassoGaussSeidel(B,y,lambda)
% sparseSupport = randperm(size(B,2));
% x0=zeros(size(B,2),1);
% k = ceil(0.1*size(B,2));
% x0(sparseSupport(1:k))=randn(1,k);
% x0 = x0 / norm(x0);
% [xp, it] = SolveHomotopyB(B, y, ...
% 'maxIteration', 1000,...
% 'isNonnegative', false, ...
% 'lambda', 5e-7, ...
% 'tolerance', 5e-7);
% global InvX_X;
% global FirstRidgeRegression;
% if (FirstRidgeRegression == 1)
% tic
% XX = B' * B;
% InvX_X = inv(XX);
% toc
% FirstRidgeRegression = 0;
% clear XX;
% else
% end
%
% x0 = InvX_X*(B'*y);
x0 = (B'*B )\(B'*y);
xp = l1eq_pd(x0, B, [], y, 5e-2, lambda);
toc
Outxp = xp;
e1=xp(size(A,2) + 1:size(xp,1),1);
xp = xp(1: size(A,2));
end
function [CVector] = GetClassVector(leftIndex, rightIndex, orgVector)
% scale = 0;
% first = 1;
% max = 0;
% minVal = min(orgVector(:,1));
% if(minVal == 0)
% minVal = 1e-8;
% end
% for j = 1: size(orgVector,1)
% if(j<leftIndex || j>rightIndex)
% if(first)
% first = 0;
% max = abs(orgVector(j,1));
% elseif(max < orgVector(j,1))
% max = abs(orgVector(j,1));
% end
% end
% end
% scale = max / minVal;
CVector = zeros(size(orgVector,1), 1);
CVector(leftIndex:rightIndex, 1) = orgVector(leftIndex:rightIndex, 1);
end