Why Markov clustering algorithm produced NaN ?

2 views (last 30 days)
chocho
chocho on 5 Jun 2017
Commented: chocho on 5 Jun 2017
I have a graph of 67 nodes and 60 edges and want to cluster it using MCL (Markov Cluster) method. i got the adjacency matrix of this graph which has only 1's and 0's. Then when i turn this matrix into a transition matrix I got some rows had NaN and also i get the same when i run MCL, what's wrong!
Could anyone explain to me why NaN occurred??
I get this code online and try it but seems my entries are wrong. Anyone help because i have tried my best and really get stuck!.
function Transition_matrixmod1 = mcl(Transition_matrixmod1)
% test the explanations in stijn van dongens thesis.
%
% @author gregor :: arbylon . net
if nargin < 1
% m contains T(G3 + I) as stochastic matrix
load -ascii Transition_matrixmod1.txt
end
p = 2;
minval = 0.001;
e = 1.;
emax = 0.001;
while e > emax
fprintf('iteration %i before expansion:\n', i);
Transition_matrixmod1
fprintf('iteration %i after expansion/before inflation:\n', i);
m2 = expand(Transition_matrixmod1)
fprintf('inflation:\n')
[Transition_matrixmod1, e] = inflate(m2, p, minval);
fprintf('residual energy: %f\n', e);
end % while e
end % mcl
% expand by multiplying m * m
% this preserves column (or row) normalisation
function m2 = expand(Transition_matrixmod1)
m2 = Transition_matrixmod1 *Transition_matrixmod1;
end
% inflate by Hadamard potentiation
% and column re-normalisation
% prune elements of m that are below minval
function [m2, energy] = inflate(Transition_matrixmod1, p, minval)
% inflation
m2 = Transition_matrixmod1.^ p;
% pruning
m2(find(m2 < minval)) = 0;
% normalisation
dinv = diag(1./sum(m2));
m2 = m2 * dinv;
% calculate residual energy
maxs = max(m2);
sqsums = sum(m2 .^ 2);
energy = max(maxs - sqsums);
end

Answers (1)

John D'Errico
John D'Errico on 5 Jun 2017
NaNs arise from operations that yield an indeterminate result. For example,
0/0
ans =
NaN
inf-inf
ans =
NaN
inf/inf
ans =
NaN
The doc for NaN says:
These operations produce NaN:
Any arithmetic operation on a NaN, such as sqrt(NaN)
Addition or subtraction, such as magnitude subtraction of infinities as (+Inf)+(-Inf)
Multiplication, such as 0*Inf
Division, such as 0/0 and Inf/Inf
Remainder, such as rem(x,y) where y is zero or x is infinity
You can identify the creation of a NaN element using dbstop.
help dbstop
dbstop if infnan
When the debugger finds the NaN, then look to see which of the possible NaN causes was the culprit.
Of course, the best person to help you is the author of the code.
  1 Comment
chocho
chocho on 5 Jun 2017
@John D'Erricon, i have shared my input because i think the problem not in the code but in my transition matrix, hope anyone can check it for me!.
i tried the same code with another matrix and is worked well.However with mu inputs doesn't work (the transition matrix issue)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!