original_docstring: compute the forward matrix (alpha matrix)
             
             Args:
                 w: weight vector (numpy vector)
                 seq_id: integer representing unique id assigned to the sequence
              
             .. note:: 
              
                activefeatures need to be loaded first in :attr:`seqs.info`
          
docstring: compute the forward matrix (alpha matrix)
docstring_tokens: compute the forward matrix ( alpha matrix )
code: def compute_forward_vec(self, w, seq_id):
          """compute the forward matrix (alpha matrix)
             
             Args:
                 w: weight vector (numpy vector)
                 seq_id: integer representing unique id assigned to the sequence
              
             .. note:: 
              
                activefeatures need to be loaded first in :attr:`seqs.info`
          """
          model = self.model
          pi_pky_map = model.pi_pky_map
          P_codebook = model.P_codebook
          P_len = model.P_len
          T = self.seqs_info[seq_id]["T"]
          active_features = self.seqs_info[seq_id]["activefeatures"]
  
          alpha = numpy.ones((T + 1, len(P_codebook)), dtype="longdouble") * (-numpy.inf)
          alpha[0, P_codebook[""]] = 0
  
          fpotential_perboundary = {}
          for j in range(1, T + 1):
              boundary = (j, j)
              # compute f_potential
              f_potential = self.compute_fpotential(w, active_features[boundary])
              fpotential_perboundary[boundary] = f_potential
              for pi in pi_pky_map:
                  pi_c = P_codebook[pi]
                  if j >= P_len[pi]:
                      pky_c_list, pk_c_list = pi_pky_map[pi]
                      vec = f_potential[pky_c_list] + alpha[j - 1, pk_c_list]
                      alpha[j, pi_c] = vectorized_logsumexp(vec)
  
          self.seqs_info[seq_id]["fpotential"] = fpotential_perboundary
  
          return alpha
code_tokens: def compute_forward_vec ( self , w , seq_id ) : model = self . model pi_pky_map = model . pi_pky_map P_codebook = model . P_codebook P_len = model . P_len T = self . seqs_info [ seq_id ] [ "T" ] active_features = self . seqs_info [ seq_id ] [ "activefeatures" ] alpha = numpy . ones ( ( T + 1 , len ( P_codebook ) ) , dtype = "longdouble" ) * ( - numpy . inf ) alpha [ 0 , P_codebook [ "" ] ] = 0 fpotential_perboundary = { } for j in range ( 1 , T + 1 ) : boundary = ( j , j ) f_potential = self . compute_fpotential ( w , active_features [ boundary ] ) fpotential_perboundary [ boundary ] = f_potential for pi in pi_pky_map : pi_c = P_codebook [ pi ] if j >= P_len [ pi ] : pky_c_list , pk_c_list = pi_pky_map [ pi ] vec = f_potential [ pky_c_list ] + alpha [ j - 1 , pk_c_list ] alpha [ j , pi_c ] = vectorized_logsumexp ( vec ) self . seqs_info [ seq_id ] [ "fpotential" ] = fpotential_perboundary return alpha
short_docstring: compute the forward matrix (alpha matrix)
short_docstring_tokens: compute the forward matrix ( alpha matrix )
comment: """compute the forward matrix (alpha matrix)
             
             Args:
                 w: weight vector (numpy vector)
                 seq_id: integer representing unique id assigned to the sequence
              
             .. note:: 
              
                activefeatures need to be loaded first in :attr:`seqs.info`
          """$SEP$# compute f_potential