-
Notifications
You must be signed in to change notification settings - Fork 0
/
reaper.py
36 lines (33 loc) · 1.55 KB
/
reaper.py
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
from numpy import random
class Reaper:
# The payoff matrix:
def __init__(self, true_positive_survival_odds = 1.0,
false_positive_survival_odds = 0.9,
true_negative_survival_odds = 1.0,
false_negative_survival_odds = 0.0):
self.true_positive_survival_odds = true_positive_survival_odds
self.false_positive_survival_odds = false_positive_survival_odds
self.true_negative_survival_odds = true_negative_survival_odds
self.false_negative_survival_odds = false_negative_survival_odds
# Determine whether something with given odds of being safe is a threat:
def is_threat(self, s):
return random.random() > s
# Determine whether it's a true or false positive or negative, then roll
# the dice as appropriate to determine survival
def does_survive(self, is_a_threat, does_attack):
if is_a_threat and does_attack:
# True positive
survival_odds = self.true_positive_survival_odds
elif (not is_a_threat) and does_attack:
# False positive
survival_odds = self.false_positive_survival_odds
elif (not is_a_threat) and (not does_attack):
# True negative
survival_odds = self.true_negative_survival_odds
elif is_a_threat and (not does_attack):
# False negative
survival_odds = self.false_negative_survival_odds
else:
# Should never happen
raise
return random.random() < survival_odds