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

def Bio::HMM::DynamicProgramming::ScaledDPAlgorithms::_forward_recursion (   self,
  cur_state,
  sequence_pos,
  forward_vars 
) [private]

Calculate the value of the forward 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 forward_vars -- The current set of forward variables

Definition at line 223 of file DynamicProgramming.py.

00223                                                                        :
        """Calculate the value of the forward 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 forward_vars -- The current set of forward 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, forward_vars)

        # e_{l}(x_{i})
        seq_letter = self._seq.emissions[sequence_pos]
        cur_emission_prob = self._mm.emission_prob[(cur_state, seq_letter)]
        # divide by the scaling value
        scale_emission_prob = (float(cur_emission_prob) /
                               float(self._s_values[sequence_pos]))
        
        # 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
            
            # get the previous forward_var values
            # f_{k}(i - 1)
            prev_forward = forward_vars[(second_state, sequence_pos - 1)]

            # a_{kl}
            cur_trans_prob = self._mm.transition_prob[(second_state,
                                                       cur_state)]
            state_pos_sum += prev_forward * cur_trans_prob

        # if we have the possiblity of having a transition
        # return the recursion value
        if have_transition:
            return (scale_emission_prob * state_pos_sum)
        else:
            return None

    def _backward_recursion(self, cur_state, sequence_pos, backward_vars):


Generated by  Doxygen 1.6.0   Back to index