IntroCModelingLA/Code/MI.py
def MI(bigram, bigramprob, tokens, tokencount):
	"""Returns the mutual information for bigrams.
		MI = P(XY|X) log2 ( P(XY) / P(X) P(Y) )
		P(XY|X) = num of bigrams XY over num bigrams with X left
	"""
	tokenlist = string.split(bigram)

	if tokens.has_key(tokenlist[0]):
		px = float(tokens[tokenlist[0]])/float(tokencount)
	else:
		px = 0.0
	if tokens.has_key(tokenlist[1]):
		py = float(tokens[tokenlist[1]])/float(tokencount)
	else:
		py = 0.0
	if py == 0.0 or px == 0.0:
		return 0.0
	return bigramprob * math.log(bigramprob/(px * py) , 2)
Returns the mutual information for bigrams.
		MI = P(XY|X) log2 ( P(XY) / P(X) P(Y) )
		P(XY|X) = num of bigrams XY over num bigrams with X left
	
Returns the mutual information for bigrams.
Returns the mutual information for bigrams .
def MI(bigram, bigramprob, tokens, tokencount):
	tokenlist = string.split(bigram)
	if tokens.has_key(tokenlist[0]):
		px = float(tokens[tokenlist[0]])/float(tokencount)
	else:
		px = 0.0
	if tokens.has_key(tokenlist[1]):
		py = float(tokens[tokenlist[1]])/float(tokencount)
	else:
		py = 0.0
	if py == 0.0 or px == 0.0:
		return 0.0
	return bigramprob * math.log(bigramprob/(px * py) , 2)
def MI ( bigram , bigramprob , tokens , tokencount ) : tokenlist = string . split ( bigram ) if tokens . has_key ( tokenlist [ 0 ] ) : px = float ( tokens [ tokenlist [ 0 ] ] ) / float ( tokencount ) else : px = 0.0 if tokens . has_key ( tokenlist [ 1 ] ) : py = float ( tokens [ tokenlist [ 1 ] ] ) / float ( tokencount ) else : py = 0.0 if py == 0.0 or px == 0.0 : return 0.0 return bigramprob * math . log ( bigramprob / ( px * py ) , 2 )
Returns the mutual information for bigrams.
Returns the mutual information for bigrams .
"""Returns the mutual information for bigrams.
		MI = P(XY|X) log2 ( P(XY) / P(X) P(Y) )
		P(XY|X) = num of bigrams XY over num bigrams with X left
	"""
bigram
bigramprob
tokens
tokencount