def count_matrices_ber(data, start_state=None, threshold=None, display=None):
num_clusters = 2
if threshold is None:
clust = clusterer(data)
state = clust.fit_predict(data.reshape(-1, 1)).reshape((-1,2))
else:
logger.debug("Cluster data based on threshold = {}".format(threshold))
state = data > threshold
state = state.reshape((-1,2))
init_state = state[:,0]
final_state = state[:,1]
switched = np.logical_xor(init_state, final_state)
init_state_frac = [np.mean(init_state == ct) for ct in range(num_clusters)]
for ct, fraction in enumerate(init_state_frac):
logger.debug("Initial fraction of state %d: %f" %(ct, fraction))
if start_state is not None and start_state in range(num_clusters):
start_stt = start_state
else:
start_stt = np.argmax(init_state_frac)
logger.debug("Start state set to state: {}".format(start_stt))
logger.debug("Switched state is state: {}".format(1-start_stt))
# This array contains a 2x2 count_matrix for each coordinate tuple
count_mat = np.zeros((2, 2))
# count_mat = np.zeros((2,2), dtype=np.int)
count_mat[0,0] = np.logical_and(init_state == 0, np.logical_not(switched)).sum()
count_mat[0,1] = np.logical_and(init_state == 0, switched).sum()
count_mat[1,0] = np.logical_and(init_state == 1, switched).sum()
count_mat[1,1] = np.logical_and(init_state == 1, np.logical_not(switched)).sum()
return count_mat, start_stt
评论列表
文章目录