probability or statistics - How to generate two group of n random numbers in U(0,1) such that sum of these two groups equal?
I want to have two groups of n random numbers ui and vi in U(0,1), such that ∑ui=∑vi
What I tried is:
I can firstly get ui by RandomReal[{0,1},n]
, make s=∑ui.
Then I found it is very difficult to generate another n uniformly distributed random numbers vi from U(0,1) that sum to s, where s is a real value in [0,n]. I can scale it but need to reject many cases that vi is larger than 1, I guess.
Try to make the question clearer, my original problem is:
I have 8 parameters κi,i=1,…,8 from a system, each parameter κi can be any value in [0,1]. But I have a constraint on my parameters which is κ1+κ2+κ3+κ4=κ5+κ6+κ7+κ8. Now I want to sample the whole parameter space (is this counted as Monte Carlo?) with such constraint. What should I do?
Update:
I have used @Coolwater 's method, but the problem is that rejecting any values larger than 1 costs a lot. When I want to sample 10,000 sets, it costs me hours. By the time I update this post, it is still running.
Any ideas about how to do this efficiently?
More update: @JasonB 's approach perfectly solved my problem. Actually, it makes sense that just scale the larger group based on the two sums ratio!!! I was too stupid to come out with this idea, which is very intuitive and straightforward!
Comments
Post a Comment