Exemplo n.º 1
0
	def learn(self):
		#print self.cs, self.ts
		learning = learn.learnCurve(self.cs, self.ts)
		#print learning
		if not math.isnan(learning['r']):
			#if it's too huge, just set it to 1000
			if learning['r'] > 5000.0:
				self.er = 5000.0
			else:
				if learning['r'] <= 0:
					self.er = 5000.0
				else:
					self.er = learning['r']
			self.epv = learning['pv']
			self.erv = learning['rv']
		else:
			self.er = 5000.0
			self.epv = 1.0
			self.erv = 1.0
		if not math.isnan(learning['p']):
			if learning['p'] < 0:
				self.ep = 0.0
			else:
				self.ep = learning['p']
		else:
			self.ep = 0.0
Exemplo n.º 2
0
		total = 0
		maximum = 0
		count = 0
		worker = Worker(str(uuid.uuid1()), 0, p, r, 1, 1)
		worker.addNoise(0, 0.1)
		for i in range(0, runs):
			ts = []
			cs = []
			for j in range(0, horizon):
				task = tasks[j]
				answer = worker.doTask(task, outcomes)
				if answer == task:
					count += 1
				ts.append(j + 1)
				cs.append(count)
				learning = learn.learnCurve(cs, ts)
				err = learning['e']
				#print err
				#print learning['r']
				if math.isnan(err):
					continue
				if err < threshold:
					total += j + 1
					tally.append(j+1)
					if j + 1 > maximum:
						maximum = j + 1
					break
		ys1.append(float(total) / float(runs))
		ys2.append(maximum)

	xs = np.arange(r_start, r_end + 1, 1)
Exemplo n.º 3
0
def getCurves(worker, tasks, runs, prob):
	#the following two are always fixed
	cqs = [] #cumulative quality
	qs = [] #quality
	aqs = [] #average quality
	ecqs = [] #estimated by linear regression
	eqs = [] #estimated by linear regression
	fqs = []
	###for learning
	cs = []
	ts = []
	errs = []
	count = 0
	for i in range(0, len(tasks)):
		task = tasks[i]
		answer = worker.doTask(task)
		if answer == getAnswer(task, prob):
			count += 1
		cqs.append(worker.getCumulativeQuality(i + 1))
		qs.append(worker.getQuality())
		aqs.append(float(count) / float(i + 1))
		#learn
		ts.append(i + 1)
		cs.append(count)
		learning = learn.learnCurve(cs, ts)
		fake = Worker(str(uuid.uuid1()), i+1, learning['p'], learning['r'], 1, 1)
		ecqs.append(fake.getCumulativeQuality(i+1))
		eqs.append(fake.getQuality())
		errs.append(learning['e'])
		if i == 0:
			fqs.append(float(count) / float(i+1))
		else:
			fqs.append(float(i+1)*aqs[i] - float(i)*aqs[i-1])

	for j in range(0, runs - 1):
		worker.reset()
		count = 0
		cs = []
		ts = []
		for i in range(0, len(tasks)):
			task = tasks[i]
			answer = worker.doTask(task)
			if answer == getAnswer(task, prob):
				count += 1
			aqs[i] += float(count) / float(i + 1)
			ts.append(i + 1)
			cs.append(count)
			learning = learn.learnCurve(cs, ts)
			fake = Worker(str(uuid.uuid1()), i+1, learning['p'], learning['r'], 1, 1)
			ecqs[i] += fake.getCumulativeQuality(i+1)
			eqs[i] += fake.getQuality()
			errs[i] += learning['e']
			if i == 0:
				fqs[i] += (float(count) / float(i+1))
			else:
				fqs[i] += (float(i+1)*aqs[i] - float(i)*aqs[i-1])

	for i in range(0, len(tasks)):
		aqs[i] = aqs[i] / float(runs)
		ecqs[i] = ecqs[i] / float(runs)
		eqs[i] = eqs[i] / float(runs)
		errs[i] = errs[i] / float(runs)
		fqs[i] = fqs[i] / float(runs)


	result = {'cqs': cqs, 'qs': qs, 'aqs': aqs, 'ecqs': ecqs, 'eqs': eqs}
	return result