Skip to main content
gamedev.net
🔒 Locked

Probabilty Calculation

Started by Cygnus_X 4 replies 750+ views
Original Post
Cygnus_X
Cygnus_X
So, I had prob-stat in college, but I didn't fair to well in the class. Now that I'm working in game development, I kinda wish I had paid more attention to what I was doing. Anyways, here is my question: Given two ranges A(with range z-y) and B(with range x-w), what is the probability that A > B Example: If A is a random number between 0-10, and B is a random number between 5-20, what is the probability that A > B I could set this up to do a brute for calculation (ie, do 1000 loops, generate random numbers for each, etc), but if there exists a formula, I'd rather just have that.
ToohrVyk
ToohrVyk
You wish to know P(A > B). Decomposing through conditional probabilities, we get:

P(A > B) = ∫x∈R P(A > x) dB(x)

And thus:

P(A > B) = ∫x∈R (∫y∈[x,+∞) dA(y)) dB(x)

The value of this depends on the distributions dA and dB. For instance, if the distribution is uniform for A on [0, 10] and for B on [5,20], you get 0 outside these intervals, and inside:

dA(y) = 1/10 dy and dB(x) = 1/15 dx

Therefore:

P(A > B) = ∫x∈[5,20] (∫y∈[x,10] 1/10 dy) 1/15 dx

And so:

P(A > B) = ∫x∈[5,10] (1 - x/10)/15 dx

Which evaluates to:

P(A > B) ∼ 0.083
Cygnus_X
Cygnus_X
First, wow. That was fast.

Second, I think I caught everything except for how you went from here:

P(A > B) = ∫x∈[5,20] ...

to here:

P(A > B) = ∫x∈[5,10] ...


Why does the range of integration change?


ToohrVyk
ToohrVyk
∫y∈[x,10] 1/10 dy = 1 - x/10 if x < 10 and 0 otherwise. Therefore:

∫x∈[5,20] (∫y∈[x,10] 1/10 dy) 1/15 dx = ∫x∈[5,10] (1 - x/10)/15 dx + ∫x∈[10,20] 0/15 dx
Cygnus_X
Cygnus_X
You're the man.


[Edited by - Cygnus_X on March 9, 2008 4:11:02 PM]
Raghar
Raghar
Quote:
Original post by Cygnus_X
So, I had prob-stat in college, but I didn't fair to well in the class. Now that I'm working in game development, I kinda wish I had paid more attention to what I was doing. Anyways, here is my question:

Given two ranges A(with range z-y) and B(with range x-w), what is the probability that A > B

Example:

If A is a random number between 0-10, and B is a random number between 5-20, what is the probability that A > B

I could set this up to do a brute for calculation (ie, do 1000 loops, generate random numbers for each, etc), but if there exists a formula, I'd rather just have that.


Why don't you try to derive it yourself?

You have range 0 to 10, and 5 to 20. Basically you have two dices, one 11 sided, and the other 16 sided.

If these two dices are independend on each other, this is often not granted, you pretty much see you need at least 6 on the first to guarantee that A > B.
Let call first estimation N. We know amount of situations when A > B could happen is N'= 5*N/11 (A > 5). N' is useful for early out and to simplify more complex calculations.

So next we sum probabilities. We know when we have A = 6, B must equal 5. B < 6 is 1/16 probability. Probability of A = 6 is 1/11 when we use N, 1/5 when we use N'. Probability of A = 6 B = 5 = 1/(16*11)
A = 7 permits A > B on B < 7 Probability of B < 7 is 1/8 (2/16) Combination is (1/(8*11))
To sum it up we would have
n = 16*11
P = 1/n + 2/n + 3/n + 4/n + 5/n

BTW sum 1+2+3 ... is called triangle number.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.