-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBayesianAgent.py
More file actions
40 lines (33 loc) · 1.22 KB
/
Copy pathBayesianAgent.py
File metadata and controls
40 lines (33 loc) · 1.22 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
39
40
import random as rand
from numpy import random
class BayesianAgent:
def __init__(self, id, variance, lam):
self.agent_id = id
self.holdingLimit = 10000
self.variance = variance
self.timer = 0
self.lam = lam
def take_action(self, midpoint):
belief = rand.normalvariate(midpoint, self.variance)
if self.timer == 0:
if belief > midpoint:
k = (abs(belief - midpoint)) / self.variance
if k < 1:
amount = int(k * self.holdingLimit) + 1000
else:
amount = self.holdingLimit
self.timer = random.poisson(self.lam, 1)[0]
return 1, belief, amount
elif belief == midpoint:
return None, None, None
else:
k = (abs(belief - midpoint)) / self.variance
if k < 1:
amount = int(k * self.holdingLimit)
else:
amount = self.holdingLimit
self.timer = random.poisson(self.lam, 1)[0]
return 0, belief, amount
else:
self.timer -= 1
return None, None, None