Question

I have a couple vectors where each entity denotes a probability value. For example, consider the following to vectors:

a=[0.7 0.3]
b=[0.1 0.9]

Consider a and b as vectors showing probability. For example, a denotes that a random variable will be 0 with probability 0.7, and it will be 1 with probability 0.3. Similarly, b represents another random variable that will be 0 with probability 0.1, and it will be 1 with probability 0.9

I want to compute a vector c where c captures the probability mass function of the sum of a and b by considering a and b are independent. In this example, c should be

c=[0.07 0.66 0.27]

In other words, c=0 when both a=0 and b=0 this happens with probability 0.7*0.1=0.07. c=1 when either a=0 and b=1 or a=1 and b=0. The first occurs with probability 0.7*0.9=0.63 and the second occurs with probability 0.3*0.1=0.03, so the sum is 0.63+0.03=0.66. Finally, the third entry of c corresponds to the case in which both a and b is equal to 1 with probability 0.3*0.9=0.27.

I want to write a code to compute c. In my application, there will be 30 of these a vectors with a length of 100 each. So, scalability definitely matters.

Many thanks!

Was it helpful?

Solution

For your simple example, you can use conv

c=conv(a,b)

however for your actual case it will be more complicated. You could repeatedly conv vectors like so (if your a vectors are rows of A)

A=a(1,:);
for i=2:30
    A=conv(A,a(i,:));
end

(Note: This code works but I am not sure whether it will give you the correct results---this is not a topic I know much about, so be careful!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top