def iterateEM(self, count):
for iter in range(count):<EOL><INDENT>countef = {}<EOL>totalf = {}<EOL>for word in self.en_words:<EOL><INDENT>if(word not in self.probs):<EOL><INDENT>continue<EOL><DEDENT>word_probs = self.probs[word]<EOL>count = dict([(w, <NUM_LIT:0>) for w in word_probs])<EOL>countef[word] = count<EOL>totalf[word] = <NUM_LIT:0><EOL><DEDENT>self.countef = countef<EOL>self.totalf = totalf<EOL>for (es, ds) in self.sent_pairs:<EOL><INDENT>es_split = es.split()<EOL>ds_split = ds.split()<EOL>for d in ds_split:<EOL><INDENT>self.totals[d] = <NUM_LIT:0><EOL>for e in es_split:<EOL><INDENT>if (e not in self.transmissions):<EOL><INDENT>continue<EOL><DEDENT>e_trans = self.transmissions[e]<EOL>if (d not in e_trans):<EOL><INDENT>continue<EOL><DEDENT>self.totals[d] += e_trans[d]<EOL><DEDENT>for e in es_split:<EOL><INDENT>if(e not in self.transmissions):<EOL><INDENT>continue<EOL><DEDENT>if (d not in self.transmissions[e]):<EOL><INDENT>continue<EOL><DEDENT>self.countef[e][<EOL>d] += self.transmissions[e][d] / self.totals[d]<EOL>self.totalf[<EOL>e] += self.transmissions[e][d] / self.totals[d]<EOL><DEDENT><DEDENT><DEDENT>for e in self.en_words:<EOL><INDENT>if (e not in self.probs):<EOL><INDENT>continue<EOL><DEDENT>e_prob = self.probs[e]<EOL>for d in e_prob:<EOL><INDENT>self.transmissions[e][d] = self.countef[<EOL>e][d] / self.totalf[e]<EOL><DEDENT><DEDENT><DEDENT>
Iterate through all transmissions of english to
foreign words. keep count of repeated occurences
 do until convergence
   set count(e|f) to 0 for all e,f
   set total(f) to 0 for all f
   for all sentence pairs (e_s,f_s)
     set total_s(e) = 0 for all e
     for all words e in e_s
       for all words f in f_s
         total_s(e) += t(e|f)
     for all words e in e_s
       for all words f in f_s
         count(e|f) += t(e|f) / total_s(e)
         total(f)   += t(e|f) / total_s(e)
   for all f
     for all e
       t(e|f) = count(e|f) / total(f)