1 view (last 30 days)

Bruno Luong
on 29 Sep 2019

Edited: Bruno Luong
on 29 Sep 2019

This will generate uniform distribution (within to polytope)

N = 10;

Etotal = 0;

E = -log(rand(N+1,1));

E = E(1:N,:)./sum(E,1);

Bruno Luong
on 29 Sep 2019

Here is a comparison of distribution with the two other methods proposed below to show the issue of non-uniformity if one doesn't pay attention

N = 2;

Etotal = 1;

p = 3e3;

Ebias = rand(1,p) .* randfixedsum(N,p,Etotal,0,Etotal);

E = rand(1,p).^(1/N)*Etotal .* randfixedsum(N,p,1,0,1);

E2 = -log(rand(N+1,p)); E2 = E2(1:N,:)./sum(E2,1);

subplot(2,2,1)

plot(Ebias(1,:),Ebias(2,:),'.');

title('rand * randfixedsum')

axis equal

subplot(2,2,2)

plot(E(1,:),E(2,:),'.');

axis equal

title('sqrt(rand) * randfixedsum')

subplot(2,2,3)

plot(E2(1,:),E2(2,:),'.');

axis equal

title('exponential method')

Sign in to comment.

Walter Roberson
on 29 Sep 2019

Bruno Luong
on 29 Sep 2019

IIUC you propose

E = rand()*Etotal * randfixedsum(N,1,1,0,1)

this will generate bad distribution (too many point close to 0 compare to uniform distribution), espetially for N >> 1.

Walter Roberson
on 29 Sep 2019

I was thinking of

rand() * randfixedsum(N,1,Etotal,0,Etotal)

but your comment might still apply.

Bruno Luong
on 29 Sep 2019

Both give the same non-uniform pdf

The "correct" one is

E = rand()^(1/N)*Etotal * randfixedsum(N,1,1,0,1);

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.