-
Notifications
You must be signed in to change notification settings - Fork 1
/
runProposedMVSC.m
executable file
·138 lines (120 loc) · 4.03 KB
/
runProposedMVSC.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
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
function runProposedMVSC()
%
% runProposedMVSC()
%
dbstop if error
maxiter = 1; % run testing for this many times
outpath = 'output';
% ***** Full version
% dbnames = {'handwritten', 'Caltech101-7', 'Caltech101-20', 'NUSWIDEOBJ','Reuters'};
% rvalues = [10.^0.5, 10.^0.5, 10.^0.5, 10.^1.1, 10.^1.3];
% ***** Small demo
dbnames = {'handwritten'};
rvalues = [10.^0.5];
for dbID = 1:length(dbnames);
dbname = dbnames{dbID};
[X, truth, nc] = loaddata(dbname);
if ~exist(outpath, 'dir'),
mkdir(outpath);
end
% ***** Parameter setting
% opts.p = 200;
opts.p = 400;
opts.r = 5;
opts.kmMaxIter = 30;
opts.maxWghtIter = 50;
% opts.wr = 0;
opts.thresh = 1e-6;
opts.kertype = 'Gaussian';
if strcmp(dbnames, 'Reuters'),
opts.kertype = 'Linear';
end
% rand('twister',5489)
%[r, bestAC] = serchBestR(X, truth, nc);
% r = 10.^0.7; % UCI Handwritten 6 view
% r = 10.^1.7; % Reuters
% r = 10.^1.1; % Caltech-7
% r = 10.^1.7; % nus_wide
% r = 10.^0.1; % MNIST
r = rvalues(dbID);
%===================================================================
% Experiment
%***** Bipartite clustering compute all results
X = X(1);
[mFBase mP mR mNMI mRI mPrt mAC mTime] = deal([]);
j = 1;
if min(truth) ==0, truth = truth + 1; end
for i = 1:maxiter,
i
opts.wr = r;
tidID = tic;
[res, markslbl, marks, obj, Zv, alpha] = multiviewBiSC(X, nc, opts);
if min(res) ==0, res = res + 1; end
elapseTime = toc(tidID);
%figure(2); plot(obj); title('Objective function values (BiSC)')
res = bestMap(truth,res);
AC = length(find(truth == res))/length(truth)
MIhat = MutualInfo(truth,res)
[purityprt] = purity(res, truth , nc)
%[mynmi] = nmi(gnd, res)
[~, mynmi] = compute_nmi(truth, res)
[ARI]=RandIndex(truth,res)
[Fmeasure,Precision, Recall] = compute_f(res, truth)
[mFBase(j, i) mP(j, i) mR(j, i) mNMI(j, i)...
mRI(j, i) mPrt(j, i) mAC(j, i) mTime(j, i)] = ...
deal(Fmeasure,Precision, Recall, mynmi, ARI, purityprt, AC, elapseTime);
%[res] = outofsample(Zv, markslbl, nc);
end
fn = fullfile(outpath, sprintf('MMVCC_%s.mat', dbname));
save(fn, 'mFBase', 'mP', 'mR', 'mNMI', 'mRI', 'mPrt', 'mAC', 'mTime');
end
% *************************************************************************
function [bestr, bestAC] = serchBestR(X, truth, nc)
%
% function [bestr, bestAC] = serchBestR(X, truth, nc)
%
bestAC = -inf;
bestr = 0;
X = 0;
if min(truth) ==0, truth = truth + 1; end
%***** Bipartite clustering search best parameters
for r = 10.^(0.1:0.2:2),
opts.wr = r;
tic;[res, markslbl, marks, obj, Zv, alpha] = multiviewBiSC(X, nc, opts);toc
if min(res) ==0, res = res + 1; end
figure(2); plot(obj); title('Objective function values (BiSC)')
res = bestMap(truth,res);
AC = length(find(truth == res))/length(truth)
MIhat = MutualInfo(truth,res)
[purityprt] = purity(res, truth , nc)
%[mynmi] = nmi(gnd, res)
[~, mynmi] = compute_nmi(truth, res)
[Fmeasure,Precision, Recall] = compute_f(res, truth)
if bestAC < purityprt,
bestAC = purityprt;
bestr = r;
end
end
% bestAC
% bestr
% *************************************************************************
function [res] = outofsample(Zv, markslbl, nc)
%
% function outofsample()
%
disp('Out-of-sample problem')
[nSmp, p, numView] = size(Zv);
truth = 0;
Z = sum(bsxfun(@times, Zv, alpha.^opts.wr), 3);
% Z = sum(bsxfun(@times, Zv, alpha), 3);
% Z = sparse(Z);
Z = sparse(double(Z > 0));
A = bsxfun(@eq, markslbl, 1:nc);
f = Z*A;
[~, res] = max(f, [], 2);
res = bestMap(truth,res);
AC = length(find(truth == res))/length(truth)
MIhat = MutualInfo(truth,res)
[purityprt] = purity(res, truth , nc)
[mynmi] = nmi(truth, res)
[Fmeasure,Precision, Recall] = compute_f(res, truth)