-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.py
75 lines (61 loc) · 2.39 KB
/
progress.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
69
70
71
72
73
74
# -*- coding: utf-8 -*-
"""
© Copyright 2014. Joon Yang & Jaemin Cheun. All rights reserved.
Defines the class ProgressState
"""
import copy
from math import log
from cmath import e
class ProgressState:
def __init__(self, progress, word=None):
self.progress = progress
self.word = word
def getLegalActions(self, agentIndex):
"""
Returns the legal actions for the agent specified.
"""
if agentIndex == "computer": # Computer is asking
# representing which question can be asked
return list(self.progress.keys())
else: # Human is answering
return [0,1]
def generateSuccessor(self, agentIndex, action, time = 0):
if agentIndex == "computer": # Computer is asking
return ProgressState(self.progress, action) #remember which action is taken
else: # Human is answering
# work with the word that only matters
penalty = 0
if 2 < time < 5:
penalty = time * - 0.03
elif time >= 5:
penalty = - 0.3
progress_copy = copy.deepcopy(self.progress)
def limit_value():
if progress_copy[self.word][1] < 0.05:
progress_copy[self.word][1] = 0.05
elif progress_copy[self.word][1] > 0.95:
progress_copy[self.word][1] = 0.95
var = progress_copy[self.word][1]
inner = - pow((var - 0.55), 2)
middle = pow(e, inner)
outer = pow(middle, 8)
if action == 0: # if the user got the question wrong
progress_copy[self.word][1] -= (outer * -log(var))/2
limit_value()
if action == 1: # if the user got the question right
progress_copy[self.word][1] += (outer * -log(var))/2 + penalty
limit_value()
return ProgressState(progress_copy)
def getnumberWords(self):
return len(list(self.progress.keys()))
def getProgress(self):
return self.progress
def getWord(self):
return self.word
def getProbability(self):
return self.progress[self.word][1]
def getAverage(self):
sumProgress = 0
for key in self.progress.keys():
sumProgress = self.progress[key][1] + sumProgress
return sumProgress/len(list(self.progress.keys()))