forked from dair-iitd/octopus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_parameters.py
160 lines (138 loc) · 8.02 KB
/
system_parameters.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import numpy as np
import os
'''
Set up the experiment using this class. This class contains (mostly) all meta-data
about the experiment. Objects of this class are passed to other classes to set up their
parameters appropriately.
'''
class SystemParameters(object):
numQuestions = 0
path = '/Users/krandiash/Downloads/octopus/'
#UPDATE path to point to where the octopus folder is located (which contains this file)
def __init__(self,
difficultyDistribution,
workerDistribution,
value=200,
timeGranularityInMinutes=10,
numQuestions=100,
ballotsToCompletionGranularity=10,
completenessGranularity=10,
numberOfPricePoints=4,
deadline=60,
timeReward=100000,
costRewardScalingFactor=1.0,
costMDPDiscountFactor=1.0,
bvFunctionGranularity=40,
synchronizationGranularity=1,
controllerType=1,
numberOfSimulations=100,
workerArrivalRates=(),
numWorkers=1000,
threshold=0.9):
self.numQuestions = numQuestions
self.difficultyDistribution = difficultyDistribution
self.workerDistribution = workerDistribution
self.currentPrice = 1 #Price increases in increments of 1 unit (1 -> 2 ...).
self.value = value #Change self.value to get changes in effective price.
self.averageGamma = workerDistribution.getMean()
self.timeGranularityInMinutes = timeGranularityInMinutes
self.ballotsToCompletionGranularity = ballotsToCompletionGranularity
self.completenessGranularity = completenessGranularity #Define in number of divisions
self.numberOfPricePoints = numberOfPricePoints
self.deadline = deadline
self.timeReward = timeReward
self.costRewardScalingFactor = costRewardScalingFactor
self.costMDPDiscountFactor = costMDPDiscountFactor
self.bvFunctionGranularity = bvFunctionGranularity
self.synchronizationGranularity = synchronizationGranularity
self.controllerType = controllerType
self.numberOfSimulations = numberOfSimulations
for x in workerArrivalRates:
for y in x:
x[y] = x[y] * timeGranularityInMinutes
self.workerArrivalRates = workerArrivalRates#np.array(workerArrivalRates) * timeGranularityInMinutes
self.numWorkers = numWorkers
self.threshold = threshold
def setWorkerArrivalRates(self,workerArrivalRates):
for x in workerArrivalRates:
for y in x:
x[y] = x[y] * self.timeGranularityInMinutes
self.workerArrivalRates = workerArrivalRates
'''
Use this to generate question IDs when adding a question (and nowhere else).
'''
@staticmethod
def addQuestion():
SystemParameters.numQuestions += 1
return SystemParameters.numQuestions - 1
def prettyPrint(self):
print "----------------------------"
print "System Parameters"
print "----------------------------"
print "Difficulty Distribution: Beta(%2.2f,%2.2f)" % (self.difficultyDistribution.alpha,self.difficultyDistribution.beta)
print "Worker Distribution: Gamma(%2.2f,%2.2f)" % (self.workerDistribution.k,self.workerDistribution.theta)
print "Penalty for Wrong Answer: %d" % (self.value)
print "Time Granularity in Minutes: %d" % (self.timeGranularityInMinutes)
print "Number of Questions: %d" % (self.numQuestions)
print "Ballots to Completion Granularity: %d" % (self.ballotsToCompletionGranularity)
print "Completeness Granularity: %d" % (self.completenessGranularity)
print "Number of Price Points: %d" % (self.numberOfPricePoints)
print "Deadline: %d" % (self.deadline)
print "Time Reward: %d" % (self.timeReward)
print "Cost Reward Scaling Factor: %1.3f" % (self.costRewardScalingFactor)
print "Cost MDP Discount Factor: %.4f" % (self.costMDPDiscountFactor)
print "BV Function Granularity: %d" % (self.bvFunctionGranularity)
print "Synchronization Granularity: %d" % (self.synchronizationGranularity)
print "Controller Type: %d" % (self.controllerType)
print "Number of Simulations: %d" % (self.numberOfSimulations)
print "Worker Arrival Rates: " + str([x[0] for x in self.workerArrivalRates])
def prettyReturn(self):
return "----------------------------\n"\
+ "System Parameters\n"\
+ "----------------------------\n"\
+ "Difficulty Distribution: Beta(%2.2f,%2.2f)\n" % (self.difficultyDistribution.alpha,self.difficultyDistribution.beta)\
+ "Worker Distribution: Gamma(%2.2f,%2.2f)\n" % (self.workerDistribution.k,self.workerDistribution.theta)\
+ "Penalty for Wrong Answer: %d\n" % (self.value)\
+ "Time Granularity in Minutes: %d\n" % (self.timeGranularityInMinutes)\
+ "Number of Questions: %d\n" % (self.numQuestions)\
+ "Ballots to Completion Granularity: %d\n" % (self.ballotsToCompletionGranularity)\
+ "Completeness Granularity: %d\n" % (self.completenessGranularity)\
+ "Number of Price Points: %d\n" % (self.numberOfPricePoints)\
+ "Deadline: %d\n" % (self.deadline)\
+ "Time Reward: %d\n" % (self.timeReward)\
+ "Cost Reward Scaling Factor: %1.3f\n" % (self.costRewardScalingFactor)\
+ "Cost MDP Discount Factor: %.4f\n" % (self.costMDPDiscountFactor)\
+ "BV Function Granularity: %d\n" % (self.bvFunctionGranularity)\
+ "Synchronization Granularity: %d\n" % (self.synchronizationGranularity)\
+ "Controller Type: %d\n" % (self.controllerType)\
+ "Number of Simulations: %d\n" % (self.numberOfSimulations)\
+ "Worker Arrival Rates: " + str([x[0] for x in self.workerArrivalRates]) + "\n"
def stringify(self):
l = [self.difficultyDistribution.alpha,self.difficultyDistribution.beta,self.workerDistribution.k,self.workerDistribution.theta,
self.value,self.timeGranularityInMinutes,self.numQuestions,self.ballotsToCompletionGranularity,self.completenessGranularity,
self.numberOfPricePoints, self.deadline, self.timeReward, self.costRewardScalingFactor, self.costMDPDiscountFactor, self.bvFunctionGranularity,
self.controllerType,self.synchronizationGranularity]
l.extend([x[0] for x in self.workerArrivalRates])
l = [str(x) for x in l]
return ",".join(l) + "_" + str(self.numberOfSimulations)
def stringifyForBVFunction(self,referenceDifficultyDistribution):
l = [self.difficultyDistribution.alpha,self.difficultyDistribution.beta,self.workerDistribution.k,self.workerDistribution.theta,
self.value,self.numberOfPricePoints,self.bvFunctionGranularity,referenceDifficultyDistribution.alpha,referenceDifficultyDistribution.beta]
l = [str(x) for x in l]
return ",".join(l)
def stringifyForTransitionTable(self):
l = [self.difficultyDistribution.alpha,self.difficultyDistribution.beta,self.workerDistribution.k,self.workerDistribution.theta,
self.value,self.numQuestions,self.ballotsToCompletionGranularity,self.completenessGranularity,
self.numberOfPricePoints, self.bvFunctionGranularity,self.controllerType]
l = [str(x) for x in l]
return ",".join(l)
def stringifyQuestionData(self):
l = [self.difficultyDistribution.alpha,self.difficultyDistribution.beta,self.numQuestions]
l = [str(x) for x in l]
return ",".join(l)
def stringifyWorkerData(self):
l = [self.workerDistribution.k,self.workerDistribution.theta,self.numWorkers]
l = [str(x) for x in l]
return ",".join(l)
def stringifyArrivalData(self,cost):
return ",".join([str(x) for x in [cost,self.workerArrivalRates[cost - 1][0]]])