-
Notifications
You must be signed in to change notification settings - Fork 0
/
learner.py
63 lines (49 loc) · 2.24 KB
/
learner.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import math
class Learner:
def __init__(self, initialvalue): #initialization
self.space = initialvalue.S
self.trajectories = initialvalue.trajectories
self.patient = initialvalue.patientTrajectories
self.health = initialvalue.healthTrajectories
self.unknown = initialvalue.unknownTrajectories
self.hygiene = initialvalue.H
self.timeSetter = initialvalue.timeSetter
# beeing patient ratio
self.beta = 0.8
# social distance impact
self.socialDis = 0.1
self.learn()
def learn(self): # DETECTING THE HAZARD PLACES
for pTraj in self.patient: #Checking path of the patients
t = 0
day = 0
for place in self.trajectories[pTraj]:
if t == self.timeSetter:
day += 1
t = 0
else:
self.space[day][t][place] = self.updateProbability(pTraj, day, place, t)
t += 1
for hTraj in self.health: #Checking path of the healty individuals
t = 0
day = 0
for place in self.trajectories[hTraj]:
if t == self.timeSetter:
day += 1
t = 0
else:
self.space[day][t][place] = self.updateProbability2(hTraj, day, place, t)
t += 1
self.rounding()
def updateProbability(self, pTraj, day, place, t):
pusp = (1-self.hygiene[pTraj])*self.PBP(day) #probability of unsaifty of the patient
return 1-((1-self.space[day][t][place])*(1-pusp))
def PBP(self, day): #probability of being patient in a day
return (self.beta)**(day)
def updateProbability2(self, hTraj, day, place, t):
return (1+math.log(self.hygiene[hTraj])/8)*self.space[day][t][place]
def rounding(self):
for day in range(len(self.space)):
for t in range(len(self.space[day])):
for place in range(len(self.space[day][t])):
self.space[day][t][place] = round(self.space[day][t][place], 2)