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

def Bio::HMM::Trainer::BaumWelchTrainer::update_transitions (   self,
  transition_counts,
  training_seq,
  forward_vars,
  backward_vars,
  training_seq_prob 
)

Add the contribution of a new training sequence to the transitions.

Arguments:

o transition_counts -- A dictionary of the current counts for the
transitions

o training_seq -- The training sequence we are working with

o forward_vars -- Probabilities calculated using the forward
algorithm.

o backward_vars -- Probabilities calculated using the backwards
algorithm.

o training_seq_prob - The probability of the current sequence.

This calculates A_{kl} (the estimated transition counts from state
k to state l) using formula 3.20 in Durbin et al.

Definition at line 246 of file Trainer.py.

                                                                          :
        """Add the contribution of a new training sequence to the transitions.

        Arguments:

        o transition_counts -- A dictionary of the current counts for the
        transitions

        o training_seq -- The training sequence we are working with

        o forward_vars -- Probabilities calculated using the forward
        algorithm.

        o backward_vars -- Probabilities calculated using the backwards
        algorithm.

        o training_seq_prob - The probability of the current sequence.

        This calculates A_{kl} (the estimated transition counts from state
        k to state l) using formula 3.20 in Durbin et al.
        """
        # set up the transition and emission probabilities we are using
        transitions = self._markov_model.transition_prob
        emissions = self._markov_model.emission_prob
        
        # loop over the possible combinations of state path letters
        for k in training_seq.states.alphabet.letters:
            for l in self._markov_model.transitions_from(k):
                estimated_counts = 0
                # now loop over the entire training sequence
                for i in range(len(training_seq.emissions) - 1):
                    # the forward value of k at the current position
                    forward_value = forward_vars[(k, i)]

                    # the backward value of l in the next position
                    backward_value = backward_vars[(l, i + 1)]

                    # the probability of a transition from k to l
                    trans_value = transitions[(k, l)]

                    # the probability of getting the emission at the next pos
                    emm_value = emissions[(l, training_seq.emissions[i + 1])]

                    estimated_counts += (forward_value * trans_value *
                                         emm_value * backward_value)

                # update the transition approximation
                transition_counts[(k, l)] += (float(estimated_counts) /
                                              training_seq_prob)
                    
        return transition_counts

    def update_emissions(self, emission_counts, training_seq,


Generated by  Doxygen 1.6.0   Back to index