5

I want to have two groups of $n$ random numbers $u_i$ and $v_i$ in $U(0,1)$, such that $\sum u_i = \sum v_i$

What I tried is:

I can firstly get $u_i$ by $U\sim U(0,1)$, make $s=\sum u_i$.

Then I found it is very difficult to generate another $n$ uniformly distributed random numbers $v_i$ from $U(0,1)$ that sum to $s$, where $s$ can be any real value in $[0,n]$

Try to make the question clearer, my original problem is:

The random variables, of course, is not independent! But my question requires the sampled values for each parameter roughly distributed in range [0,1] such that the Monte Carlo sampling will effectively go over the whole parameter space for the system.

I have $8$ parameters $\kappa_i, i=1,\ldots,8$ from a system, each parameter $\kappa_i$ can be any value (better be uniformly distributed) in $[0,1]$. But I have a constraint on my parameters which is $\kappa_1+\kappa_2+\kappa_3+\kappa_4=\kappa_5+\kappa_6+\kappa_7+\kappa_8$. Now I want to sample the whole parameter space (is this counted as Monte Carlo?) with such constraint. What should I do?

LifeWorks
  • 151
  • 4
  • Aren't you missing $=s$ at the end of the sum in the penultimate line? – Richard Hardy Feb 06 '16 at 15:24
  • @RichardHardy the $s$ is just a sum calculated by sampled $4$ random numbers, it can be any value in $[0,1]$ – LifeWorks Feb 06 '16 at 15:28
  • Do you require anything to be independent from anything else? If not, you could draw a single $Z \sim U[0, 1]$ and make all the $X_i$ and $V_i$ equal to that $Z$. But that's probably not what you want... – Adrian Feb 06 '16 at 15:37
  • 1
    You want samples of numbers $\kappa_i$ such that $\sum_{i=1}^4 \kappa_i = \sum_{i=5}^8 \kappa_i$. It sounds like you want the marginal distribution of each $\kappa_i$ to be uniform on $[0, 1]$. But what conditions do you want to impose on their joint distribution? – Adrian Feb 06 '16 at 15:50
  • What I mean is that $\kappa_1+\kappa_2+\kappa_3+\kappa_4=\kappa_5+\kappa_6+\kappa_7+\kappa_8$ is not a constraint on parameters although you refer to it as such. – Richard Hardy Feb 06 '16 at 15:54
  • 4
    There appears to be an interesting and important question here, but it is asked in a very confusing way. Please edit it to address the comments. – whuber Feb 06 '16 at 16:14
  • 3
    I think it is crucial what kind of dependence you allow for. Your constraint *implies* a dependence structure, so the four samples $\kappa_i: 1 \leq i \leq 8$ *cannot* be independent from each other. (To see this, note that if all $\kappa_i$ are random and independent, the probability of your constraint holding is equal to $0$.) 'How independent' do they have to be? Which dependence structure do you allow for? – Jeremias K Feb 06 '16 at 18:10
  • @whuber I wanted to at least follow through with what I started. I don't know if the answer I'm giving could possibly help the OP. It certainly doesn't have originality as I make it very clear. Please let me know if it'd be OK to leave the answer un-deleted. – Antoni Parellada Feb 06 '16 at 19:33
  • @Antoni I'm afraid I haven't a clue what your answer is supposed to be telling us. The output of your code, as shown, certainly isn't two sets of four numbers, so I have been unable to relate it to any interpretation of the question. – whuber Feb 06 '16 at 19:37
  • 2
    It's on hold so I can't post this as a solution but why not first sample $\kappa_1,\kappa_2,\kappa_3,\kappa_5,\kappa_6,\kappa_7\sim U(0,1)$. Then simulate one more $\kappa_i\sim U(0,1)$ and add it to whichever set $A=\{\kappa_1,\kappa_2,\kappa_3\}$ or $B=\{\kappa_5,\kappa_6,\kappa_7\}$ makes it such that $A>B$ or $B>A$. So either $i=4$ and $\kappa_4$ gets added to $A$ or $i=8$ and $\kappa_8$ gets added to $B$. Then, for whichever $\kappa$ is left, set the last $\kappa_8=\kappa_1+\kappa_2+\kappa_3+\kappa_4-(\kappa_5+\kappa_6+\kappa_7)$ or (ctd)... – RustyStatistician Feb 06 '16 at 19:54
  • (ctd)... $\kappa_4=\kappa_5+\kappa_6+\kappa_7+\kappa_8-(\kappa_1+\kappa_2+\kappa_3)$ and I believe that should get you what you want. I.e., $\sum_{i=1}^4\kappa_i=\sum_{i=5}^8\kappa_i$. Of course here the last $\kappa$ will depend on all of the other $\kappa$'s and so possibly not independent. – RustyStatistician Feb 06 '16 at 19:56
  • @RustyStatistician The approach is the same as I came up with yesterday!!! In addition, $A$ and $B$ need to be carefully calculated so that $|\sum A-\sum B|\le1$. Then choosing these two sets will also cost computational time. – LifeWorks Feb 07 '16 at 09:54
  • 2
    The problem of partitioning a set into two equal-in-sum (/as equal as possible) subsets is the [partition problem](https://en.wikipedia.org/wiki/Partition_problem), but it's not quite clear to me how your conditions on the distribution are supposed to work. – Glen_b Feb 07 '16 at 10:30
  • I think it is best to ask a new question concerning your underlying problem of MC sampling with certain constraints on parameters. That is, if that is what you are ultimately interested in. – Marco Breitig Feb 09 '16 at 09:15

2 Answers2

5

Here is a procedure to generate two $n$tuples of random variables $(u_k)$ and $(v_k)$, both i.i.d. uniform on $(0,1)$, with $u_1+\cdots u_n=v_1+\cdots+v_n$.

For every $k$, let $f_k$ denote the PDF of the sum of $k$ i.i.d. random variables uniformly distributed on $(0,1)$. Generate $n$ i.i.d. random variables $u_i$ uniform on $(0,1)$, and consider $s_n=u_1+\cdots+u_n$. Then generate $v_n$ distributed as $u_n$ conditionally on $u_1+\cdots+u_n=s_n$, that is, with density $$f_n(s_n)^{-1}\cdot f_{n-1}(s_n-x)\cdot\mathbf 1_{(0,1)}(x).$$ Next, define $s_{n-1}=s_n-v_n$ and generate $v_{n-1}$ distributed as $u_{n-1}$ conditionally on $u_1+\cdots+u_{n-1}=s_{n-1}$, that is, with density $$f_{n-1}(s_{n-1})^{-1}\cdot f_{n-2}(s_{n-1}-x)\cdot\mathbf 1_{(0,1)}(x),$$ and so on, until $v_2$ distributed as $u_2$ conditionally on $u_1+u_2=s_2$, that is, with density $$f_2(s_2)^{-1}\cdot f_{1}(s_2-x)\cdot\mathbf 1_{(0,1)}(x)=f_2(s_2)^{-1}\cdot \mathbf 1_{(s_2-1,s_2)}(x)\cdot\mathbf 1_{(0,1)}(x).$$ Finally define $v_1=s_2-v_2$. Then $(v_k)$ is i.i.d. uniform on $(0,1)$ and $u_1+\cdots u_n=v_1+\cdots+v_n$ almost surely.

To sum up, the procedure is exact but it requires to compute $n-1$ PDFs, each PDF $f_k$ being a polynomial of degree $k-1$ on each interval $(i-1,i)$ with $1\leqslant i\leqslant k$.

Did
  • 1,577
  • 14
  • 23
-4

I have 8 parameters $κ_i,i=1,…,8$ from a system, each parameter $κ_i$ can be any value (better be uniformly distributed) 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?

If understand your problem:

a) simulate freely 4 random numbers [0, 1]
b) let be its sum n1 c) simulate THREE ALSO FREELY and add, say n2
d) if 0<= ni-n2 <= 1 then keep x=n1-n2, otherwise reject the attempt
e) repeat from a) to d) any times in order to get a large stock

gung - Reinstate Monica
  • 132,789
  • 81
  • 357
  • 650
licas
  • 18
  • 4
  • many TIMES (NOT ANY) – licas Feb 14 '16 at 16:13
  • 3
    There appear to be several problems with this proposal, not least of which are (1) the numbers won't usually sum to unity and (2) the asymmetric treatment of the last one leads to an unexpected marginal distribution. – whuber Feb 14 '16 at 16:27
  • CORRECTION d) if 0<= |n1-n2|<=1 . . .so sorry . . . – licas Feb 14 '16 at 16:28
  • 1
    I'm afraid that doesn't fix the problems I mentioned. – whuber Feb 14 '16 at 16:29
  • of curse NOT whuber it was not demanded that th sums were – licas Feb 14 '16 at 16:33
  • it was not demanded that the sums were equal to 1. Not at all! – licas Feb 14 '16 at 16:35
  • 3
    Please stop the words in capitals and rather concentrate on the mathematical point @whuber made. – Did Feb 14 '16 at 18:56
  • A occurs or not to see if B occurs too: B|A. My solution above solves completely the posted problem. Do not complicate what is so elementary. – licas Feb 14 '16 at 19:52
  • The probability that the third RND (2nd set) be accepted to complete a sum equal to – licas Feb 14 '16 at 22:37
  • the first 4 RND set is precisely 0.716 – licas Feb 14 '16 at 22:39
  • the fourth RND (2nd set) of course. – licas Feb 14 '16 at 22:43
  • For some kind of people only understands numbers: Example 1: k1=0.3, k2=0.7, k3=0.5, k4=0.5, sum1 =2.0. if k5=0.7, k6=0.7, k7=0.7, sum2=2.1.Then (because RND are <=1) reject. Example 2: k5=0.2, k6=0.1, k7=0.1, sum2=0.4, then k8 would be 1.6, impossible, reject. – licas Mar 03 '16 at 19:50
  • 2
    There is actually a neat little exam question for introductory courses on theoretical probability here. The text of the question could read as follows. Consider seven independent random variables $T$, $U$, $V$, $W$, $X$, $Y$, $Z$, and compute the distribution of $S=(U+V+W+T)-(X+Y+Z)$ conditionally on the event $[0 – Did Mar 07 '16 at 18:10