-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathgrowclusters.m
More file actions
57 lines (54 loc) · 1.54 KB
/
growclusters.m
File metadata and controls
57 lines (54 loc) · 1.54 KB
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
function [H] = growclusters(nworkers,A,method,seeds,varargin)
% GROWCLUSTERS Expand seed sets into clusters based on the PPR method
%
% [H,setdata] = growclusters(A,seeds,...)
% takes a vector of seeds, or a cell array of seed sets.
% as well as options for the ppr cluster routine
% and returns the best cluster found by exploring around
% the seed. Note that this does not neessarily contain
% the seed itself.
n = size(A,1);
if ~iscell(seeds), seeds=num2cell(seeds); end
ns = numel(seeds);
%fprintf('Computing %sgrow clustering ... for %i seeds\n', method,ns);
H = sparse(n,ns);
%% single thread
if nworkers==1
for i=1:ns
seed = seeds{i};
switch method
case 'ppr'
[curset,~,~,~,~] = pprgrow(A,seed,varargin{:});
case 'vppr'
[curset,~,~,~,~] = vpprgrow(A,seed,varargin{:});
case 'hk'
[curset,~,~,~,~] = hkgrow(A,seed);
otherwise
error('need a method name')
end
H(curset,i) = 1;
end
%% multiple workers
else
h = cell(ns,1);
parpool(nworkers)
parfor i=1:ns
seed = seeds{i};
switch method
case 'ppr'
[h{i},~,~,~,~] = pprgrow(A,seed,varargin{:});
case 'vppr'
[h{i},~,~,~,~] = vpprgrow(A,seed,varargin{:});
case 'hk'
[h{i},~,~,~,~] = hkgrow(A,seed);
otherwise
error('need a method name')
end
end
delete(gcp);
tic
for i=1:ns
H(h{i},i)=1;
end
toc
end