def extract_out_cos(transmat, cos, state): """ Helper function for building HMMs from matrices: Used for transition matrices with 'cos' transition classes. Extract outgoing transitions for 'state' from the complete list of transition matrices Allocates: .out_id vector and .out_a array (of size cos x N) """ lis = [] # parsing indixes belonging to postive probabilites for j in range(cos): for i in range(len(transmat[j][state])): if transmat[j][state][i] != 0.0 and i not in lis: lis.append(i) #lis.sort() #print "lis: ", lis trans_id = ghmmwrapper.int_array_alloc(len(lis)) probsarray = ghmmwrapper.double_matrix_alloc(cos, len(lis)) # C-function # creating list with positive probabilities for k in range(cos): for j in range(len(lis)): ghmmwrapper.double_matrix_setitem(probsarray, k, j, transmat[k][state][lis[j]]) # initializing C state index array for i in range(len(lis)): ghmmwrapper.int_array_setitem(trans_id, i, lis[i]) return [len(lis),trans_id,probsarray]
def extract_in_cos(transmat, cos, state): """ Helper function for building HMMs from matrices: Used for transition matrices with 'cos' transition classes. Extract ingoing transitions for 'state' from the complete list of transition matrices Allocates: .in_id vector and .in_a array (of size cos x N) """ lis = [] # parsing indixes belonging to postive probabilites for j in range(cos): transmat_col_state = map(lambda x: x[state], transmat[j]) for i in range(len(transmat_col_state)): if transmat_col_state[i] != 0.0 and i not in lis: lis.append(i) #lis.sort() #print "lis: ", lis trans_id = ghmmwrapper.int_array_alloc(len(lis)) probsarray = ghmmwrapper.double_matrix_alloc(cos, len(lis)) # C-function # creating list with positive probabilities for k in range(cos): for j in range(len(lis)): ghmmwrapper.double_matrix_setitem(probsarray, k, j, transmat[k][lis[j]][state]) # initializing C state index array for i in range(len(lis)): ghmmwrapper.int_array_setitem(trans_id, i, lis[i]) return [len(lis), trans_id, probsarray]
def extract_out(lisprobs): """ Helper function for building HMMs from matrices: Used for transition matrices without transition classes. Extract out-/ingoing transitions from the row-vector resp. the column vector (corresponding to incoming transitions) of the transition matrix Allocates: .[out|in]_id and .[out|in]_a vectors """ lis = [] for i in range(len(lisprobs)): if lisprobs[i]!=0: lis.append(i) trans_id = ghmmwrapper.int_array_alloc(len(lis)) trans_prob = ghmmwrapper.double_array_alloc(len(lis)) for i in range(len(lis)): ghmmwrapper.int_array_setitem(trans_id, i, lis[i]) ghmmwrapper.double_array_setitem(trans_prob, i, lisprobs[lis[i]]) return [len(lis),trans_id,trans_prob]
def extract_out(lisprobs): """ Helper function for building HMMs from matrices: Used for transition matrices without transition classes. Extract out-/ingoing transitions from the row-vector resp. the column vector (corresponding to incoming transitions) of the transition matrix Allocates: .[out|in]_id and .[out|in]_a vectors """ lis = [] for i in range(len(lisprobs)): if lisprobs[i] != 0: lis.append(i) trans_id = ghmmwrapper.int_array_alloc(len(lis)) trans_prob = ghmmwrapper.double_array_alloc(len(lis)) for i in range(len(lis)): ghmmwrapper.int_array_setitem(trans_id, i, lis[i]) ghmmwrapper.double_array_setitem(trans_prob, i, lisprobs[lis[i]]) return [len(lis), trans_id, trans_prob]