Exemplo n.º 1
0
	def get_all_ids(self, no_nots=True):
		"""
		@deprecated: Use iter instead.
		@return: Set of string tuple keys (acc1,acc2)
		"""
		if no_nots:
			ret_keys = []
			for key in self._dict.keys():
				key = self._unkey(key)
				#print "key: ", key, "key[0], key[1]: ", key[0], key[1]
				if not is_not_id(key[0]) and not is_not_id(key[1]):
					yield key
		else:
			for key in  self:
				yield key
Exemplo n.º 2
0
	def get_metric(self, acc1, acc2=None):
		if None == acc2:
			try:
				if is_not_id(acc1):
					all_freq = self.get_metric(ALL_TERM) 
					return  all_freq - self.get_metric(get_not_id(acc1.get_id()))
				else:
					return Metric.get_metric(self,acc1, None)
			except KeyError:
				return 0

		else:
			#kdrew: F(notacc2 , notacc1)
			if is_not_id(acc1) and is_not_id(acc2):
				acc_acc2_freq = self.get_metric(get_not_id(acc1), get_not_id(acc2))
				acc_freq = self.get_metric(get_not_id(acc1))
				acc2_freq = self.get_metric(get_not_id(acc2))
				all_freq = self.get_metric(ALL_TERM) 
				return all_freq - acc_freq - acc2_freq + acc_acc2_freq

			#kdrew: F(notacc2 , acc1)
			elif is_not_id(acc2):
				acc_acc2_freq = self.get_metric(acc1, get_not_id(acc2))
				acc_freq = self.get_metric(acc1)
				return acc_freq - acc_acc2_freq

			#kdrew: F(acc2 , notacc1)
			elif is_not_id(acc1):
				acc_acc2_freq = self.get_metric(acc2, get_not_id(acc1))
				acc2_freq = self.get_metric(acc2)
				return acc2_freq - acc_acc2_freq

			#kdrew: F(acc1, acc2)
			else:
				try:
					return Metric.get_metric(self,acc1, acc2)

				except KeyError:
					#kdrew: if the one combination of predictors doesn't work reverse them and try again
					try:
						return Metric.get_metric(self,acc2, acc1)
					except KeyError:
						return 0
Exemplo n.º 3
0
	def get_metric(self, acc1, acc2):
		try:
			if acc1 == None:
				return TINY_NUM
			if acc2 == None:
				if is_not_id(acc1):
					return (1.0 - self.get_metric(get_not_id(acc1),None))
				else:
					return self._dict[self._key(acc1, None)]
			else:
				#kdrew: P(notacc2 | notacc1)
				if is_not_id(acc1) and is_not_id(acc2):
					rawacc2 = get_not_id(acc2)
					#kdrew: P(notacc2|notacc1)
					return 1.0 - self.get_metric(acc1, rawacc2)

				#kdrew: P(notacc2 | acc1)
				elif is_not_id(acc2):
					rawacc2 = get_not_id(acc2)
					#kdrew: P(notacc2|acc1)
					return 1.0 - self.get_metric(acc1, rawacc2)

				#kdrew: P(acc2 | notacc1)
				elif is_not_id(acc1):
					rawacc1 = get_not_id(acc1)
					p1 = self.get_metric(rawacc1,None)
					p2 = self.get_metric(acc2,None)
					p2G1 = self.get_metric(rawacc1, acc2)

					#kdrew: tests for small numerator and returns TINY_NUM if smaller
					#kdrew: fixes problem with P(all|notall) returning 1.0
					if (p2 - p2G1 * p1) <= TINY_NUM:
						return TINY_NUM
					else:
						#kdrew: P(acc2|notacc1)
						return (p2 - p2G1 * p1) / (1.0 - p1)

				else:
					return self._dict[self._key(acc1, acc2)]

		except KeyError:
			return TINY_NUM