tostoch.m
来自「Mathematical Methods by Moor n Stiling.」· M 代码 · 共 25 行
M
25 行
function A = tostoch(A)
%
% Determine the matrix nearest to A which is stochastic using
% the composite mapping algorithm
%
% function A = tostoch(A)
% A = input matrix
%
% Output: A = nearest stochastic A
% Copyright 1999 by Todd K. Moon
[m,n] = size(A); numiter = 0;
while(numiter < 200)
numiter = numiter+1;
oldA = A;
for i=1:m % apply the row-sum mapping to each row
A(i,:) = A(i,:) + (1 - sum(A(i,:)))/n;
end
idx = A < 0; % apply the positive mapping to each row
A(idx) = zeros(size(A(idx)));
if(norm(A - oldA) < 1.e-8)
break;
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?