Is there a better way to randomly generate a Doubly Stochastic Matrix?

后端 未结 1 1453
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 15:10

Here is a profile of the call n = 2*10^3; M = DStochMat02(n,ones(n)./n);

 time   calls  line
                  1 function M = DStochMat02(n,c)
          


        
相关标签:
1条回答
  • 2021-01-14 15:56

    How about changing lines 14 and 15 to the following lines:

    l = ( [ pidx ; 1:n ] - 1 ) * [1;n] + 1; % convert pairs (pidx,1:n) to linear indices
    M(l) = M(l) + c(k);
    

    since P is very sparse, maybe it would be more efficient to increment only the non-zeros of P.

    0 讨论(0)
提交回复
热议问题