Logo Search packages:      
Sourcecode: python-biopython version File versions

def Bio::HMM::Trainer::AbstractTrainer::ml_estimator (   self,
  counts 
) [inherited]

Calculate the maximum likelihood estimator.

This can calculate maximum likelihoods for both transitions
and emissions.

Arguments:

o counts -- A dictionary of the counts for each item.

See estimate_params for a description of the formula used for
calculation.

Definition at line 91 of file Trainer.py.

00091                                   :
        """Calculate the maximum likelihood estimator.

        This can calculate maximum likelihoods for both transitions
        and emissions.

        Arguments:

        o counts -- A dictionary of the counts for each item.

        See estimate_params for a description of the formula used for
        calculation.
        """
        # get an ordered list of all items
        all_ordered = counts.keys()
        all_ordered.sort()
        
        ml_estimation = {}

        # the total counts for the current letter we are on
        cur_letter = None
        cur_letter_counts = 0
        
        for cur_item in all_ordered:
            # if we are on a new letter (ie. the first letter of the tuple)
            if cur_item[0] != cur_letter:
                # set the new letter we are working with
                cur_letter = cur_item[0]

                # count up the total counts for this letter
                cur_letter_counts = counts[cur_item]
                
                # add counts for all other items with the same first letter
                cur_position = all_ordered.index(cur_item) + 1

                # keep adding while we have the same first letter or until
                # we get to the end of the ordered list
                while (cur_position < len(all_ordered) and
                       all_ordered[cur_position][0] == cur_item[0]):
                    cur_letter_counts += counts[all_ordered[cur_position]]
                    cur_position += 1
            # otherwise we've already got the total counts for this letter
            else:
                pass

            # now calculate the ml and add it to the estimation
            cur_ml = float(counts[cur_item]) / float(cur_letter_counts)
            ml_estimation[cur_item] = cur_ml

        return ml_estimation
            
class BaumWelchTrainer(AbstractTrainer):


Generated by  Doxygen 1.6.0   Back to index