⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tostoch.m

📁 Mathematical Methods by Moor n Stiling.
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -