Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: random matrix from row and column sums

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53599] Re: random matrix from row and column sums
  • From: "Astanoff" <astanoff at yahoo.fr>
  • Date: Thu, 20 Jan 2005 03:47:40 -0500 (EST)
  • References: <csinpt$njk$1@smc.vnet.net><csl12t$6rv$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

A faster random solution assuming a truncated Poisson distribution :

<<Statistics`

rand[sumLin_List, sumCol_List]:=
Module[{nbLin = Length[sumLin],
nbCol = Length[sumCol],t,ok},
While[t = Outer[Min[#1,#2,
Random[PoissonDistribution[Min[#1/nbCol, #2/nbLin]]]
]&,
sumLin, sumCol];
t[[1]]=sumCol-Plus @@ Rest[t];
t[[All,1]]=sumLin-(Plus @@ #& /@ (Rest/@t));
ok=And @@ Thread[0 <= t[[1]]] &&
And @@ Thread[t[[1]] <= sumCol] &&
And @@ Thread[0 <= t[[All,1]]] &&
And @@ Thread[t[[All,1]] <= sumLin] &&
(Plus @@ #& /@ t) == sumLin &&
(Plus @@ #& /@ Transpose[t]) == sumCol;
!ok];
t];

rand[{15,17,12,10,4},{9,11,10,6,14,8}]//Timing

{0.218
Second,{{0,4,0,3,5,3},{2,2,5,0,5,3},{4,0,4,1,2,1},{3,3,0,2,2,0},{0,2,1,0,0,1}}}


  • Prev by Date: Algebraic problem solved by simulation
  • Next by Date: Re: A NewBie Question
  • Previous by thread: Re: Re: random matrix from row and column sums
  • Next by thread: Re: Re: random matrix from row and column sums