in reply to Probability sum of random variables

Although I can't install the module Algorithm::Loops, I believe if I'm following correctly (after reading up on this module on CPAN) that the sums you have set up are:
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
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.

I guess I am wondering if the sum to be gotten was 2, for example, then 3 cases would qualify with your algorithm.

0 + 2 = 2 1 + 1 = 2 2 + 0 = 2
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)?

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
    Hi Cristoforo, you getting the point right. If, for example, only three "object sums" are possible (0, 1 and 2).

    $nElements = 1: Sum = 0 -> 0 Sum = 1 -> 1 Sum = 2 -> 2 $nElements = 2: Sum = 0 -> 0+0 Sum = 1 -> 0+1 1+0 Sum = 2 -> 0+2 1+1 2+0 Sum = 3 -> 1+2 2+1 Sum = 4 -> 2+2 $nElements = 3: Sum = 0 -> 0+0+0 Sum = 1 -> 0+0+1 0+1+0 1+0+0 Sum = 2 -> 0+0+2 0+1+1 0+2+0 1+0+1 1+1+0 2+0+0 Sum = 3 -> 0+1+2 0+2+1 1+0+2 1+1+1 1+2+0 2+0+1 2+1+0 Sum = 4 -> 0+2+2 1+1+2 1+2+1 2+0+2 2+1+1 2+2+0 Sum = 5 -> 1+2+2 2+1+2 2+2+1 Sum = 6 -> 2+2+2 And so on...
    Of course, there is some redundancy in there, for ex. Element = 3, sum = 1 could be treated as (3*((p0)**2)*p1). But, how to generate this automatically and fast ?

    Thanks, FFRANK