コード例 #1
0
print(label)
print(predicted_cluster)

v = v_measure_score(label, predicted_cluster)
print('oMHMM v-measure: {}'.format(v))

acc = accuracy_score(label, predicted_cluster)
print('oMHMM acc: {}'.format(acc))

###################################################################################################

mhmm = MHMM.SpaMHMM(n_nodes=1,
                       mix_dim=M,
                       n_components=S,
                       n_features=l,
                       graph=None,
                       n_iter=100,
                       verbose=True,
                       name='mhmm')
mhmm.fit(data.flatten()[:, np.newaxis], y, lengths)
pi_nk, transitions = mhmm._compute_mixture_posteriors(data.flatten()[:, np.newaxis], y, lengths)

print(transitions.reshape(M, S, S))

print(np.exp(pi_nk))

predicted_cluster = []
label_0 = [0 for i in range(len(data1[:, 0]))]
label_1 = [1 for i in range(len(data2[:, 0]))]
for n in range(num_of_cells):
    cell = np.float64(pi_nk[n])
コード例 #2
0
start_prob = np.concatenate((start_1, start_2), axis=0).reshape(2, num_of_states)

rates_1 = np.random.uniform(low=80, high=100, size=(num_of_states,))
rates_2 = np.random.uniform(low=80, high=100, size=(num_of_states,))
rates = np.concatenate((rates_1, rates_2), axis=0).reshape(2, num_of_states)

data, len_0, pi = generate_data(num_of_cells, [.5, .5], rates, seq_len, trans, start_prob, num_of_states)

y = np.zeros(num_of_cells, dtype=int)
M = 2
lengths = (np.ones(num_of_cells, dtype=int) * seq_len).tolist()

mhmm = spamhmm_init_A.SpaMHMM(n_nodes=1,
                                         mix_dim=M,
                                         n_components=num_of_states,
                                         n_features=seq_len,
                                         graph=None,
                                         n_iter=100,
                                         verbose=True,
                                         name='mhmm')
mhmm.fit(data.flatten()[:, np.newaxis], y, lengths)
pi_nk, transitions = mhmm._compute_mixture_posteriors(data.flatten()[:, np.newaxis], y, lengths)
predicted_cluster = []
label = []
for n in range(num_of_cells):
    cell = np.float64(pi_nk[n])
    truth = np.float64(pi[n])
    predicted_cluster = np.append(predicted_cluster, np.where(cell == max(cell))[0][0])
    label = np.append(label, np.where(truth == max(truth))[0][0])
print(label)
print(predicted_cluster)
v_measure = v_measure_score(label, predicted_cluster)