MathGroup Archive 2008

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

Search the Archive

Re: Sample uniformly from a simplex

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94466] Re: Sample uniformly from a simplex
  • From: Mark Fisher <particlefilter at gmail.com>
  • Date: Sun, 14 Dec 2008 07:37:26 -0500 (EST)
  • References: <ghtjg8$rb3$1@smc.vnet.net>

On Dec 12, 6:55 am, Andreas <aa... at ix.netcom.com> wrote:
> I need to develop Mathematica code to sample uniformly from a unit n-dime=
nsional simplex.
>
> I came across a description of the problem at:http://geomblog.blogspot.co=
m/2005/10/sampling-from-simplex.html
>
> Specifically, I would like a uniform sample from the set
>
> X = { (x1, x2, ..., xD) | 0 <= xi <= 1, x1 + x2 + ... + xD = 1}.
>
> D is the dimension of the simplex.
>
> So, the coordinates of any point on the simplex would sum to 1 and I need=
 to sample points on the simplex.
>
> geomblog's solution suggested:
>
> Generating IID random samples from an exponential distribution by samplin=
g X from [0,1] uniformly, and returning -log(X)).
>
> Take n samples, then normalize.  
>
> This should result in a list of numbers which is a uniform sample from th=
e simplex.
>
> I've searched extensively for a Mathematica implementation of something l=
ike this, to no avail.
>
> I keep trying different things but haven't made much headway.
>
> Any suggestions for how to develop this (or an equivelant) in Mathematica=
 much appreciated
>
> A

Hi. Try this (using Version 6 or 7):

ranSimp[d_] := (#/Plus @@ #) &[-Log[RandomReal[1, d]]]
ranSimp[d_, n_] := (#/Plus @@ #) & /@ (-Log[RandomReal[1, {n, d}]])

d is the "dimension" of the simplex and n is the number of draws.

--Mark


  • Prev by Date: Re: Aligning two PLots
  • Next by Date: Beginner: List Indexing and Assignment
  • Previous by thread: Re: Sample uniformly from a simplex
  • Next by thread: Re: Sample uniformly from a simplex