in reply to Probability sum of random variables
Then, when you calculate the p value for the sucessful combination (2 + 2 is the only one to equal 4), you've mutiplied the probability of a 2 (= .7) times the probability for another 2 and get the answer (.49). If there had been other combs that equaled 4, their probability would have been calculated and added to the .49.0 + 0 = 0 0 + 1 = 1 0 + 2 = 2 1 + 0 = 1 1 + 1 = 2 1 + 2 = 3 2 + 0 = 2 2 + 1 = 3 2 + 2 = 4
I guess I am wondering if the sum to be gotten was 2, for example, then 3 cases would qualify with your algorithm.
But, do you really want to count (0, 2) *and* (2, 0) because they are the same elements (from the original array), only one is the reverse of the other. Also, do you want to include the same item added to itself (1 + 1)?0 + 2 = 2 1 + 1 = 2 2 + 0 = 2
The numbers you are generating now are also known as the cross product of n sets. Perhaps you just want to test all the possible combinations instead?
0 + 1 = 1 0 + 2 = 2 1 + 2 = 3
As far as your code scaling up, it depends on how large the number of trials. If you use the cross product, with 10,000 numbers there will be 10,000 * 10,000 trials. On the other hand, if you tested the combinations there would be 10,000 * 9,999 / 2 trials - half as many.
Chris
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Probability sum of random variables
by FFRANK (Beadle) on Aug 31, 2007 at 02:03 UTC |