Repository navigation
Expand file tree
/
Copy pathPeacekeeperUnderFire.java
More file actions
38 lines (33 loc) · 1.79 KB
/
Copy pathPeacekeeperUnderFire.java
File metadata and controls
38 lines (33 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* -- Scenario taken from Bayes Theorem by Dan Morris
* A peacekeeper is pinned down trying to help an injured family,
* A truck is approaching, but you can't see if it has a gun or not
* A wave of bullets hit the front of the vehicle your are taking cover behind
*
* Rebels have 54 dilapidated trucks, 22 are rigged with guns
*
* We don't know if the bullets came from the truck or elsewhere so the
* probability is 50% or .5 That the heavy fire came from the truck
*
* Hypothesis:
* The truck is rigged with a Gun because a wave of bullets hit your cover vehicle
*
* What do we know?
* - The probability of a truck firing at you if rigged with a gun is 80%
* - (Event A) The probability of a truck rigged with a gun is .4074 or 40% or 22/54
* - (Event B) The probability that heavy fire came from the truck .5 or 50%
*
*/
public class PeacekeeperUnderFire {
public static void main(String [] args) {
// People with the flu will have a headache and sore throat ~ 90% of the time
float probabilityOfATruckFiringAtYouIfRiggedWithAGun = 0.8f;
//(Event A)The probability of a truck rigged with a gun is .4074 or 40% or 22/54
float probabilityOfTheTruckRiggedWithAGun = 0.4074f;
// (Event B)The probability of a rebel having heavey firepower is .5 or 50%
float probabilityThatHeavyFireCameFromTheTruck = 0.5f;
Bayes bayes = new Bayes(probabilityOfATruckFiringAtYouIfRiggedWithAGun, probabilityOfTheTruckRiggedWithAGun, probabilityThatHeavyFireCameFromTheTruck);
float probabilityOfThatTheTruckIsRiggedWithAGunGivenTheHeavyFire = bayes.computePosterior();
System.out.println("Posterior probability of the truck rigged with a gun: "+probabilityOfThatTheTruckIsRiggedWithAGunGivenTheHeavyFire);
}
}