-
Notifications
You must be signed in to change notification settings - Fork 0
/
probabilities.py
68 lines (63 loc) · 2.76 KB
/
probabilities.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
64
65
66
67
68
"""
ANOLOGIES
0 - Rock
1 - Paper
2 - Scissors
"""
class Model:
def __init__(self,baisFactor = 0.1):
self.P = [[1/3,1/3,1/3] for i in range(3)]
self.S = [[1,0,0]]
self.predictedMove = 0
self.previousMove = 0
self.biasFactor = baisFactor
def changeTrasitionMatrix(self, actualMove,predictedMove,previousMove):
if actualMove == predictedMove:
print("Correctly Predicted")
for currentPossibility in range(3):
if currentPossibility == predictedMove:
self.P[previousMove][predictedMove] += self.biasFactor
if self.P[previousMove][predictedMove] < 0:
self.P[previousMove][predictedMove] = 0
if self.P[previousMove][predictedMove] >= 1:
self.P[previousMove][predictedMove] = 1
else:
self.P[previousMove][currentPossibility] -= self.biasFactor / 2
if self.P[previousMove][currentPossibility] < 0:
self.P[previousMove][currentPossibility] = 0
if self.P[previousMove][currentPossibility] >= 1:
self.P[previousMove][currentPossibility] = 1
else:
for currentPossibility in range(3):
if currentPossibility == predictedMove:
self.P[previousMove][predictedMove] -= self.biasFactor
if self.P[previousMove][predictedMove] < 0:
self.P[previousMove][predictedMove] = 0
if self.P[previousMove][predictedMove] >= 1:
self.P[previousMove][predictedMove] = 1
else:
self.P[previousMove][currentPossibility] += self.biasFactor / 2
if self.P[previousMove][currentPossibility] < 0:
self.P[previousMove][currentPossibility] = 0
if self.P[previousMove][currentPossibility] >= 1:
self.P[previousMove][currentPossibility] = 1
def nextState(self):
result = [[0, 0, 0]]
for i in range(len(self.S)):
for j in range(len(self.P)):
for k in range(len(self.P)):
result[i][j] += self.S[i][k] * self.P[k][j]
self.S = result
def predict(self):
return self.S[0].index(max(self.S[0]))
koushik = Model()
# previousMove = 0
# while True:
# print("Transition Matrix ",koushik.P)
# print("State Matrix ",koushik.S)
# predictedMove = koushik.predict()
# print("Predicted Move-",predictedMove)
# actualMove = int(input("Acutual Move-"))
# koushik.changeTrasitionMatrix(actualMove,predictedMove,previousMove)
# koushik.nextState()
# previousMove = actualMove