def try_train_HMM_on_Data(): N = 8 M = OBSERVE_STATE_LIST.__len__() a_matrix = init_A(N) b_matrix = init_B(N, M) pi = init_PI(N) # print(a_matrix); # print(b_matrix); # print(pi); _data = getHMMData() o_sequence_List = [] for index in range(_data.__len__()): o_sequence_List.append(_data[index][1]) a_matrix, b_matrix, pi = baum_welch_multipleObservation( a_matrix, b_matrix, pi, o_sequence_List, None, 10) # print(normalize_matrix_line(shelterSmallValue(a_matrix,1e-5,0))); # print(normalize_matrix_line(shelterSmallValue(b_matrix,1e-5,0))); # print(normalize_matrix_line(shelterSmallValue(np.array([pi]),1e-5,0))[0]); print(compute_bic_of_HMM(a_matrix, b_matrix, pi, o_sequence_List))
def convert_index_to_Uid(): _data = getHMMData() index_to_uid_dic = {} for index in range(_data.__len__()): index_to_uid_dic[index] = _data[index][0] _out_data = copy.deepcopy(cluster_result) for cluster_index in range(cluster_result.__len__()): for item_index, value in enumerate(cluster_result[cluster_index]): _out_data[cluster_index][item_index] = index_to_uid_dic[value] print(_out_data)
for i in range(K - 1): for j in range(1, K): is_pre_same_cluster = pre_cluster_result_dic[ i] == pre_cluster_result_dic[j] is_new_same_cluster = new_cluster_result_dic[ i] == new_cluster_result_dic[j] disMatchCount += is_new_same_cluster ^ is_pre_same_cluster return disMatchCount > 0 if __name__ == "__main__": # 数据准备 M = OBSERVE_STATE_LIST.__len__() _data = getHMMData() o_sequence_List = [] for index in range(_data.__len__()): o_sequence_List.append(_data[index][1]) a_matrix_list, b_matrix_list, pi_list, data_of_clusters = do_HMM_Cluster_On_data_with_dN( o_sequence_List, 3, M, show_progress=True) #a_matrix_list, b_matrix_list, pi_list, data_of_clusters = do_HMM_Cluster_On_data(o_sequence_List,3,4,M,show_progress=True) print(a_matrix_list) print(b_matrix_list) print(pi_list) print(data_of_clusters) PMI = compute_PMI_of_HMM_Clusters(a_matrix_list, b_matrix_list, pi_list, data_of_clusters, o_sequence_List)