-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCSRKDApredict.m
71 lines (60 loc) · 2.1 KB
/
CSRKDApredict.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
function [accuracy,predictlabel,elapse] = CSRKDApredict(fea, gnd, model)
% SRKDApredict: Spectral Regression Kernel Discriminant Analysis Prediction
% SRKDApredict use SRKDA as a classifier. It used the nearest
% center rule in the SRKDA subspace for classification.
%
% [predictlabel,accuracy,elapse] = SRKDApredict(fea, gnd, model);
%
% Input:
%
% fea - data matrix. Each row is a data point.
% gnd - Label vector of fea.
% model - model trained by SRKDAtrain.m
%
% Output:
%
% accuracy - classification accuracy
% predictlabel - predict label for fea
% elapse - running time.
%
% Examples:
%
%
% See also SRKDAtrain, KSR, KSR_caller
%
%Reference:
%
% [1] Deng Cai, Xiaofei He, and Jiawei Han. "Speed Up Kernel Discriminant
% Analysis", The VLDB Journal, vol. 20, no. 1, pp. 21-33, January, 2011.
%
% [2] Deng Cai, Xiaofei He and Jiawei Han, "SRDA: An Efficient Algorithm for
% Large Scale Discriminant Analysis" IEEE Transactions on Knowledge and
% Data Engineering, vol. 20, no. 1, pp. 1-12, January, 2008.
%
% [3] V. Sindhwani, P. Niyogi, M. Belkin, "Beyond the Point Cloud: from
% Transductive to Semi-supervised Learning", ICML 2005.
%
% version 2.0 --December/2011
% version 1.0 --May/2006
%
% Written by Deng Cai (dengcai AT gmail.com)
%
MAX_MATRIX_SIZE = 8000; % You can change this number based on your memory.
nTrain = size(model.Landmark,1);
nTest = size(fea,1);
nBlock = ceil(MAX_MATRIX_SIZE*MAX_MATRIX_SIZE/nTrain);
Embed_Test = zeros(nTest,size(model.projection,2));
for i = 1:ceil(nTest/nBlock)
if i == ceil(nTest/nBlock)
smpIdx = (i-1)*nBlock+1:nTest;
else
smpIdx = (i-1)*nBlock+1:i*nBlock;
end
KTest= constructKernel(fea(smpIdx,:),model.Landmark,model.options);
Embed_Test(smpIdx,:) = KTest*model.projection;
clear KTest;
end
D = EuDist2(Embed_Test,model.ClassCenter,0);
[dump, idx] = min(D,[],2);
predictlabel = model.ClassLabel(idx);
accuracy = 1 - length(find(predictlabel-gnd))/nTest;