%NHGRAPH Find a neighborhood graph and its shortest paths % % [NG,L,DL,D] = NHGRAPH(A,OPT,PAR) % % INPUT % A NxN Weight (dissimilarity) matrix/dataset representing a weighted graph % OPT Option method (optional; default: 'MST') % 'NN' - based on nearest neighbor neighborhoods % 'MST' - based on minimum spanning trees (MSTs) % 'EPS' - based on eps-neighborhoods % 'MST-NN' - based on a single MST followed by nearest neighbor neighborhoods % 'MST-EPS'- based on a single MST followed by eps-neighborhoods % PAR Parameter (optional; default: 3 for 'NN' and 'MST-NN'; 1 for 'MST'; % 0.1*avr(W) for 'EPS' and 'MST-EPS') % Integer K, 1<=K= n, error ('K should be the number of nearest neighbors.'); end if strcmp(opt,'MST-NN'), [L,DL,V] = kmst(V,1); end [VV,I] = sort(V); for i=1:n V(i,I((2+K):end,i)) = inf; end if nargout > 1, for i=1:n L = [L; i*ones(K,1) I(2:1+K,i)]; DL = [DL; VV(i,I(2:1+K,i))']; end end case {'EPS','MST-EPS'} if strcmp(opt,'MST-EPS') [L,DL,V] = kmst(V,1); end deps = par; if deps <= 0, error ('EPS should be positive.'); end warning off; V = V./(V <= deps); V = min(V,inf); if nargout > 1, [I J] = find(V < inf); L = [L; I J]; DL = [DL; V(J*(n-1)+I)]; end warning on; otherwise error('Unknown method.') end LL = [L; L(:,[2 1])]; V = inf*ones(n,m); V((LL(:,2)-1)*n+LL(:,1)) = +A((LL(:,2)-1)*n+LL(:,1)); if isdataset(A), V = setdata(A,V); end if nargout > 3, D = dspaths(V); end return;