-
Notifications
You must be signed in to change notification settings - Fork 1
/
runPTA_v2.m
66 lines (60 loc) · 2.69 KB
/
runPTA_v2.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% This is a demo for the PTA and PTGP algorithms. If you find the %
% code useful for your research,please cite the paper below. %
% %
% Dong Huang, Jian-Huang Lai, and Chang-Dong Wang. Robust ensemble %
% clustering using probability trajectories, IEEE Transactions on %
% Knowledge and Data Engineering, 2016, 28(5), pp.1312-1326. %
% %
% The code has been tested in Matlab R2014a and Matlab R2015a on a %
% workstation with Windows Server 2008 R2 64-bit. %
% %
% https://www.researchgate.net/publication/284259332 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [results_al, results_cl, results_sl] = runPTA_v2(S, ks)
% Input: the co-association matrix
% and the numbers of clusters.
% Output: clustering results by PTA-AL, PTA-CL, and PTA-SL, respectively.
N = size(S,1);
d = stod2(S); clear S %convert similarity matrix to distance vector
% single linkage
Zsl = linkage(d,'single');
% complete linkage
Zcl = linkage(d,'complete');
% average linkage
Zal = linkage(d,'average'); clear d
results_sl = ones(N, numel(ks));
results_cl = ones(N, numel(ks));
results_al = ones(N, numel(ks));
disp('.');
for i = 1:numel(ks)
K = ks(i);
disp(['Obtain ',num2str(K),' clusters by PTA-AL\CL\SL.']); tic;
results_sl(:,i) = cluster(Zsl,'maxclust',K);
results_cl(:,i) = cluster(Zcl,'maxclust',K);
results_al(:,i) = cluster(Zal,'maxclust',K);toc;
end
disp('.');
function d = stod2(S)
%==========================================================================
% FUNCTION: d = stod(S)
% DESCRIPTION: This function converts similarity values to distance values
% and change matrix's format from square to vector (input
% format for linkage function)
%
% INPUTS: S = N-by-N similarity matrix
%
% OUTPUT: d = a distance vector
%==========================================================================
% copyright (c) 2010 Iam-on & Garrett
%==========================================================================
N = size(S,1);
s = zeros(1,N*(N-1)/2);
nextIdx = 1;
for a = 1:N-1 %change matrix's format to be input of linkage fn
s(nextIdx:nextIdx+(N-a-1)) = S(a,[a+1:end]);
nextIdx = nextIdx + N - a;
end
d = 1 - s; %compute distance (d = 1-sim)