def gacPathCondEntropy(IminuszW, cluster_i, cluster_j):
# Compute conditional complexity from the subpart of the weighted adjacency matrix
# Inputs:
# - IminuszW: the matrix (I - z*P)
# - cluster_i: index vector of cluster i
# - cluster_j: index vector of cluster j
# Output:
# - L_ij - the sum of conditional complexities of cluster i and j after merging.
# by Wei Zhang (wzhang009 at gmail.com), June, 8, 2011
num_i = np.size(cluster_i)
num_j = np.size(cluster_j)
# detecting cross elements (this check costs much and is unnecessary)
ijGroupIndex = np.append(cluster_i, cluster_j)
y_ij = np.zeros((num_i + num_j, 2)) # [y_i, y_j]
y_ij[:num_i, 0] = 1
y_ij[num_i:, 1] = 1
idx = np.ix_(ijGroupIndex, ijGroupIndex)
L_ij = scipy.linalg.inv(IminuszW[idx]).dot(y_ij)
L_ij = sum(L_ij[:num_i, 0]) / (num_i * num_i) + sum(L_ij[num_i:, 1]) / (num_j * num_j)
return L_ij
评论列表
文章目录