IntroCModelingLA/Code/MIParser.py
def MI(self, bigram, ltype, rtype):
		"""Calculate the mutual information for bigram.
			MI = log2 ( P(XY) / P(X) P(Y) )."""
		if ltype == TOKEN and rtype == TOKEN:
			bigrams  = self.totoBigrams
			unileft  = self.tokens
			uniright = self.tokens
		elif ltype == TOKEN and rtype == TYPE:
			bigrams = self.totyBigrams
			unileft = self.tokens
			uniright = self.types
		elif ltype == TYPE and rtype == TOKEN:
			bigrams = self.tytoBigrams
			unileft = self.types
			uniright = self.tokens
		elif ltype == TYPE and rtype == TYPE:
			bigrams = self.tytyBigrams
			unileft = self.types
			uniright = self.types
		mi = 0.0
		words = string.split(bigram)
		if bigrams.has_key(bigram):
			if unileft.has_key(words[0]):
				if uniright.has_key(words[1]):
					pxy = float(bigrams[bigram]) / float(self.myData.counts["bigramCnt"])
					px  = float(unileft[words[0]]) / float(self.myData.counts["wordCnt"])
					py  = float(uniright[words[1]]) / float(self.myData.counts["wordCnt"])
					mi = math.log(pxy / (px * py), 2)
		return mi
Calculate the mutual information for bigram.
			MI = log2 ( P(XY) / P(X) P(Y) ).
Calculate the mutual information for bigram.
Calculate the mutual information for bigram .
def MI(self, bigram, ltype, rtype):
		if ltype == TOKEN and rtype == TOKEN:
			bigrams  = self.totoBigrams
			unileft  = self.tokens
			uniright = self.tokens
		elif ltype == TOKEN and rtype == TYPE:
			bigrams = self.totyBigrams
			unileft = self.tokens
			uniright = self.types
		elif ltype == TYPE and rtype == TOKEN:
			bigrams = self.tytoBigrams
			unileft = self.types
			uniright = self.tokens
		elif ltype == TYPE and rtype == TYPE:
			bigrams = self.tytyBigrams
			unileft = self.types
			uniright = self.types
		mi = 0.0
		words = string.split(bigram)
		if bigrams.has_key(bigram):
			if unileft.has_key(words[0]):
				if uniright.has_key(words[1]):
					pxy = float(bigrams[bigram]) / float(self.myData.counts["bigramCnt"])
					px  = float(unileft[words[0]]) / float(self.myData.counts["wordCnt"])
					py  = float(uniright[words[1]]) / float(self.myData.counts["wordCnt"])
					mi = math.log(pxy / (px * py), 2)
		return mi
def MI ( self , bigram , ltype , rtype ) : if ltype == TOKEN and rtype == TOKEN : bigrams = self . totoBigrams unileft = self . tokens uniright = self . tokens elif ltype == TOKEN and rtype == TYPE : bigrams = self . totyBigrams unileft = self . tokens uniright = self . types elif ltype == TYPE and rtype == TOKEN : bigrams = self . tytoBigrams unileft = self . types uniright = self . tokens elif ltype == TYPE and rtype == TYPE : bigrams = self . tytyBigrams unileft = self . types uniright = self . types mi = 0.0 words = string . split ( bigram ) if bigrams . has_key ( bigram ) : if unileft . has_key ( words [ 0 ] ) : if uniright . has_key ( words [ 1 ] ) : pxy = float ( bigrams [ bigram ] ) / float ( self . myData . counts [ "bigramCnt" ] ) px = float ( unileft [ words [ 0 ] ] ) / float ( self . myData . counts [ "wordCnt" ] ) py = float ( uniright [ words [ 1 ] ] ) / float ( self . myData . counts [ "wordCnt" ] ) mi = math . log ( pxy / ( px * py ) , 2 ) return mi
Calculate the mutual information for bigram.
Calculate the mutual information for bigram .
"""Calculate the mutual information for bigram.
			MI = log2 ( P(XY) / P(X) P(Y) )."""
self
bigram
ltype
rtype