本文整理汇总了Python中networkx.to_networkx_graph函数的典型用法代码示例。如果您正苦于以下问题:Python to_networkx_graph函数的具体用法?Python to_networkx_graph怎么用?Python to_networkx_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_networkx_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_graph_india
def test_graph_india():
A1 = np.loadtxt("adj_allVillageRelationships_vilno_1.csv", delimiter=",")
A2 = np.loadtxt("adj_allVillageRelationships_vilno_2.csv", delimiter=",")
G1 = nx.to_networkx_graph(A1)
G2 = nx.to_networkx_graph(A2)
basic_net_stats(G1)
basic_net_stats(G2)
plot_degree_distribution(G1)
plot_degree_distribution(G2)
plt.show()
示例2: _randomize
def _randomize(net, density=None):
n_nodes = len(net.nodes())
density = density or 1.0/n_nodes
max_attempts = 50
for attempt in xrange(max_attempts):
# create an random adjacency matrix with given density
adjmat = N.random.rand(n_nodes, n_nodes)
adjmat[adjmat >= (1.0-density)] = 1
adjmat[adjmat < 1] = 0
# add required edges
for src,dest in required_edges:
adjmat[src][dest] = 1
# remove prohibited edges
for src,dest in prohibited_edges:
adjmat[src][dest] = 0
# remove self-loop edges (those along the diagonal)
adjmat = N.invert(N.identity(n_nodes).astype(bool))*adjmat
# set the adjaceny matrix and check for acyclicity
net = nx.to_networkx_graph(adjmat, create_using=Network())
if net.is_acyclic():
return net
# got here without finding a single acyclic network.
# so try with a less dense network
return _randomize(density/2)
示例3: degree_dist
def degree_dist(g):
if isinstance(g,np.ndarray):
g=nx.to_networkx_graph(g) # if matrix is passed, convert to networkx
d=dict(g.degree()).values()
vals=list(set(d))
counts=[d.count(i) for i in vals]
return list(zip(vals, counts))
示例4: t_delta_partition
def t_delta_partition(t_delta_matrix,sm,verbose=False):
import community;
g=nx.to_networkx_graph(t_delta_matrix+t_delta_matrix.T - np.diag(t_delta_matrix.diagonal()) ,create_using=nx.Graph());
if verbose==True:
plt.figure, plt.pcolor(np.array(nx.to_numpy_matrix(g))), plt.colorbar();
plt.show()
return community.best_partition(g);
示例5: test_exceptions
def test_exceptions(self):
# _prep_create_using
G = {"a": "a"}
H = nx.to_networkx_graph(G)
assert_graphs_equal(H, nx.Graph([('a', 'a')]))
assert_raises(TypeError, to_networkx_graph, G, create_using=0.0)
# NX graph
class G(object):
adj = None
assert_raises(nx.NetworkXError, to_networkx_graph, G)
# pygraphviz agraph
class G(object):
is_strict = None
assert_raises(nx.NetworkXError, to_networkx_graph, G)
# Dict of [dicts, lists]
G = {"a": 0}
assert_raises(TypeError, to_networkx_graph, G)
# list or generator of edges
class G(object):
next = None
assert_raises(nx.NetworkXError, to_networkx_graph, G)
# no match
assert_raises(nx.NetworkXError, to_networkx_graph, "a")
示例6: identity_conversion
def identity_conversion(self, G, A, create_using):
GG = nx.from_numpy_matrix(A, create_using=create_using)
self.assert_equal(G, GG)
GW = nx.to_networkx_graph(A, create_using=create_using)
self.assert_equal(G, GW)
GI = create_using.__class__(A)
self.assert_equal(G, GI)
示例7: identity_conversion
def identity_conversion(self, G, A, create_using):
GG = nx.from_scipy_sparse_matrix(A, create_using=create_using)
self.assert_equal(G, GG)
GW = nx.to_networkx_graph(A, create_using=create_using)
self.assert_equal(G, GW)
GI = create_using.__class__(A)
self.assert_equal(G, GI)
ACSR = A.tocsr()
GI = create_using.__class__(ACSR)
self.assert_equal(G, GI)
ACOO = A.tocoo()
GI = create_using.__class__(ACOO)
self.assert_equal(G, GI)
ACSC = A.tocsc()
GI = create_using.__class__(ACSC)
self.assert_equal(G, GI)
AD = A.todense()
GI = create_using.__class__(AD)
self.assert_equal(G, GI)
AA = A.toarray()
GI = create_using.__class__(AA)
self.assert_equal(G, GI)
示例8: geoGraph
def geoGraph(n, d, epsilon):
""" Create a geometric graph: n points in d-dimensional space,
nodes are connected if closer than epsilon"""
points = np.random.random((n,d))
pl2 = np.array([np.linalg.norm(points, axis=1)])**2
eucDist = (pl2.T @ np.ones((1,n))) + (np.ones((n,1)) @ pl2) - (2 * points @ points.T)
A = ((eucDist + np.eye(n)) < epsilon).astype(int)
return nx.to_networkx_graph(A)
示例9: identity_conversion
def identity_conversion(self, G, A, create_using):
assert(A.sum() > 0)
GG = nx.from_numpy_array(A, create_using=create_using)
self.assert_equal(G, GG)
GW = nx.to_networkx_graph(A, create_using=create_using)
self.assert_equal(G, GW)
GI = nx.empty_graph(0, create_using).__class__(A)
self.assert_equal(G, GI)
示例10: StickyGraph
def StickyGraph(n, deg):
"""input: n, degree sequence."""
assert(n == len(deg))
deg = np.array(deg) / np.sqrt(np.sum(deg))
A = np.zeros((n,n),dtype=int)
for i,j in itertools.combinations(range(n),2):
if (i != j) and (np.random.random() < deg[i]*deg[j]):
A[i,j] = 1
A[j,i] = 1
return nx.to_networkx_graph(A)
示例11: geoGraphP
def geoGraphP(n, d, p):
""" Create a geometric graph: n points in d-dimensional space,
fraction p node pairs are connected"""
points = np.random.random((n,d))
pl2 = np.array([np.linalg.norm(points, axis=1)])**2
eucDist = (pl2.T @ np.ones((1,n))) + (np.ones((n,1)) @ pl2) - (2 * points @ points.T)
dists = np.sort(np.ravel(eucDist))
epsilon = dists[n + np.floor((n**2-n) * p).astype(int)]
A = ((eucDist + dists[-1] * np.eye(n)) < epsilon).astype(int)
return nx.to_networkx_graph(A)
示例12: hits_algo
def hits_algo(adj_matrix,hub_score):
# INPUT: Initial hub_score, authorities score and adjacency matrix.
# OUTPUT: Converged
print "Running HITS algorithm..."
graph = nx.to_networkx_graph(adj_matrix)
# print graph
nstart = dict([(i, hub_score[i]) for i in xrange(len(hub_score))])
# print nstart
# return nx.hits(graph)
return nx.hits(graph,nstart=nstart)
示例13: convertIDToGraph
def convertIDToGraph(id,motifSize):
binary = bin(id);
adj = np.zeros(motifSize*motifSize)
for x in xrange(motifSize*motifSize):
if binary[-x] == 'b':
break
adj[-x] = int(binary[-x])
adj.shape = (motifSize,motifSize)
graph = nx.to_networkx_graph(adj,create_using=nx.DiGraph())
nx.draw_circular(graph)
#plt.savefig("result/id-"+str(id)+"size-"+str(motifSize))
plt.show()
示例14: __init__
def __init__(self, term_term_matrix, threshold=10):
self.graph = {}
for term_a in term_term_matrix:
for term_b in term_term_matrix:
if term_term_matrix[term_a][term_b] >= threshold:
tmp = self.graph.get(term_a, [])
tmp.append(term_b)
self.graph[term_a] = tmp
if term_a not in self.graph:
self.graph[term_a] = []
self.nx_graph = nx.to_networkx_graph(self.graph)
示例15: test_graph_generator
def test_graph_generator():
A1 = np.loadtxt("adj_allVillageRelationships_vilno_1.csv", delimiter=",")
A2 = np.loadtxt("adj_allVillageRelationships_vilno_2.csv", delimiter=",")
G1 = nx.to_networkx_graph(A1)
G2 = nx.to_networkx_graph(A2)
gen1 = nx.connected_component_subgraphs(G1)
G1_LCC = max(gen1, key=len)
print(len(G1_LCC))
print(G1.number_of_nodes())
print(G1_LCC.number_of_nodes())
print(G1_LCC.number_of_nodes()/G1.number_of_nodes())
# g1 = gen1.__next__()
# print(g1)
# basic_net_stats(G1)
# basic_net_stats(g1)
gen2 = nx.connected_component_subgraphs(G2)
G2_LCC = max(gen2, key=len)
print(len(G2_LCC))
print(G2.number_of_nodes())
print(G2_LCC.number_of_nodes())
print(G2_LCC.number_of_nodes()/G2.number_of_nodes())
plt.figure()
nx.draw(G2_LCC, with_labels=False)
plt.show()