为什么我的Markov聚类算法(MCL)在Matlab中产生NaN?

时间:2017-05-24 11:31:21

标签: matlab markov

我在Matalb中尝试过马尔可夫聚类算法(MCL),但遗憾的是我得到了一个67 * 67的矩阵,所有元素都有NaN。

enter image description here

有谁能告诉我出了什么问题?

 function adjacency_matrixmod2= mcl(adjacency_matrixmod2)
% 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 adjacency_matrixmod2.txt
end


p = 2;
minval = 0.001;

e = 1.;
emax = 0.001;
while e > emax

    fprintf('iteration %i before expansion:\n', i);
    adjacency_matrixmod2

    fprintf('iteration %i after expansion/before inflation:\n', i);
    m2 = expand(adjacency_matrixmod2)

    fprintf('inflation:\n')
    [adjacency_matrixmod2, 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(adjacency_matrixmod2)
m2 = adjacency_matrixmod2 *adjacency_matrixmod2;
end

% inflate by Hadamard potentiation
% and column re-normalisation
% prune elements of m that are below minval
function [m2, energy] = inflate(adjacency_matrixmod2, p, minval)
% inflation
m2 = adjacency_matrixmod2 .^ 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

这是我使用过的代码,它的输入是一个邻接矩阵。

0 个答案:

没有答案