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

def Bio::HMM::DynamicProgramming::ScaledDPAlgorithms::_backward_recursion (   self,
  cur_state,
  sequence_pos,
  backward_vars 
) [private]

Calculate the value of the backward recursion

Arguments:

o cur_state -- The letter of the state we are calculating the
forward variable for.

o sequence_pos -- The position we are at in the training seq.

o backward_vars -- The current set of backward variables

Reimplemented from Bio::HMM::DynamicProgramming::AbstractDPAlgorithms.

Definition at line 270 of file DynamicProgramming.py.

00270                                                                          :
        """Calculate the value of the backward recursion

        Arguments:

        o cur_state -- The letter of the state we are calculating the
        forward variable for.

        o sequence_pos -- The position we are at in the training seq.

        o backward_vars -- The current set of backward variables
        """
        # calculate the s value, if we haven't done so already (ie. during
        # a previous forward or backward recursion)
        if not(self._s_values.has_key(sequence_pos)):
            self._s_values[sequence_pos] = \
              self._calculate_s_value(sequence_pos, backward_vars)

        # loop over all of the possible states at the position
        state_pos_sum = 0
        have_transition = 0
        for second_state in self._mm.transitions_from(cur_state):
            have_transition = 1
            # e_{l}(x_{i + 1})
            seq_letter = self._seq.emissions[sequence_pos + 1]
            cur_emission_prob = self._mm.emission_prob[(cur_state, seq_letter)]

            # get the previous backward_var value
            # b_{l}(i + 1)
            prev_backward = backward_vars[(second_state, sequence_pos + 1)]

            # the transition probability -- a_{kl}
            cur_transition_prob = self._mm.transition_prob[(cur_state,
                                                            second_state)]

            state_pos_sum += (cur_emission_prob * prev_backward *
                              cur_transition_prob)

        # if we have a probability for a transition, return it
        if have_transition:
            return (state_pos_sum / float(self._s_values[sequence_pos]))
        # otherwise we have no probability (ie. we can't do this transition)
        # and return None
        else:
            return None
            
class LogDPAlgorithms(AbstractDPAlgorithms):


Generated by  Doxygen 1.6.0   Back to index