def undirected(graph, scaled=False): A = get_matrix(graph).toarray() n = len(A) I = identity(n) ones = array([1 for _ in range(n)]) beta = 1. / (n - 1.) h_star = dot(inv(I + beta * A), ones) if not scaled: return h_star return scale_centrality(h_star)
def outgoing(graph, scaled=False): A = get_matrix(graph).toarray() n = len(A) I = identity(n) ones = array([1 for _ in range(n)]) beta1 = 1. / (n - 1.) beta2 = 1. / ((n - 1.)**2) h_star = dot( dot(inv(I - beta2 * dot(A, transpose(A))), (I - beta1 * A)), ones) if not scaled: return h_star return scale_centrality(h_star)
def undirected_on_matrices(positive_matrix, negative_matrix, scaled=False): P = positive_matrix # Positive weights N = negative_matrix # Negative weights A = P - 2. * N # All weights n = len(A) I = identity(n) ones = array([1 for _ in range(n)]) beta = 1. / (2. * n - 2.) PN = dot(inv(I - beta * A), ones) if not scaled: return PN return scale_centrality(PN)
def outgoing_on_matrices(positive_matrix, negative_matrix, scaled=False): P = positive_matrix # Positive weights N = negative_matrix # Negative weights A = P - 2. * N # All weights n = len(A) I = identity(n) ones = array([1 for _ in range(n)]) beta1 = 1. / (4 * ((n - 1.)**2)) beta2 = 1. / (2 * (n - 1.)) PN = dot(dot(inv(I - beta1 * dot(A, transpose(A))), (I + beta2 * A)), ones) if not scaled: return PN return scale_centrality(PN)