-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhkgrow1.m
52 lines (43 loc) · 1.64 KB
/
hkgrow1.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
function [bestset,bestcond,bestcut,bestvol] = hkgrow(A,vert,varargin)
% HKGROW Grow a cluster around a vertex using a heatkernel-pagerank algorithm
%
% [bestset,cond,cut,vol] = hkgrow(A,vert) computes exp(t*P)*v where
% v is either a single column of the identity or a group of columns of the
% identity and then extract a cluster. The algorithm uses various values of
% t and returns the best conductance cluster among any of them.
%
% ... hkgrow(A,verts,'key',value,'key',value) specifies optional argument
%
% 'neighborhood' : [false | true] to use the neighborhood of the given
% vertex as the seed. The default is false.
%
% 'debug' : [false | true] to enable debugging info. The default is
% false.
% Kyle Kloster
% Purdue University, 2014
p = inputParser;
p.addOptional('debug',false,@islogical);
p.addOptional('neighborhood',false,@islogical);
p.addOptional('t',20);
p.addOptional('eps',1e-4);
p.parse(varargin{:});
debugflag = p.Results.debug;
if p.Results.neighborhood
neighs = find(A(:,vert));
vert = union(vert,neighs);
end
bestcond = Inf;
bestset = [];
if debugflag==1, fprintf('hkgrow1.m: Called hkgrow_mex on set of size=%i with t=%f ; eps=%f \n', ...
numel(vert), t_vals(ei), eps_vals(ei)); end
[curset cond cut vol] = hkgrow_mex(A, vert, p.Results.t, p.Results.eps, debugflag);
if debugflag==1, fprintf('hkgrow.m: hkgrow_mex done on set of size=%i with t=%f ; eps=%f \n', ...
numel(vert), t_vals(ei), eps_vals(ei)); end
% ripped code from hkgrow.m hence the strange extra work
% TODO elimiate this and simplify.
if cond < bestcond
bestcond = cond;
bestset = curset;
bestvol = vol;
bestcut = cut;
end