def manage_data(domain_name):
domain_pkts = get_data(domain_name)
node_cname, node_ip, visit_total, edges, node_main = get_ip_cname(domain_pkts[0]['details'])
for i in domain_pkts[0]['details']:
for v in i['answers']:
edges.append((v['domain_name'],v['dm_data']))
DG = nx.DiGraph()
DG.add_edges_from(edges)
ass = nx.degree_assortativity_coefficient(DG)
nodes_count = len(node_cname)+len(node_ip)+len(node_main)
print nodes_count
edges_count = len(edges)
average_degree = sum(nx.degree(DG).values())
print domain_name,ass
print nx.density(DG)
return nodes_count,edges_count, ass,average_degree,nx.degree_histogram(DG)
python类density()的实例源码
assortativity_node_edge.py 文件源码
项目:analyse_website_dns
作者: mrcheng0910
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def get_data_prop(self):
prop = super(frontendNetwork, self).get_data_prop()
if self.is_symmetric():
nnz = np.triu(self.data).sum()
else:
nnz = self.data.sum()
_nnz = self.data.sum(axis=1)
d = {'instances': self.data.shape[1],
'nnz': nnz,
'nnz_mean': _nnz.mean(),
'nnz_var': _nnz.var(),
'density': self.density(),
'diameter': self.diameter(),
'clustering_coef': self.clustering_coefficient(),
'modularity': self.modularity(),
'communities': self.clusters_len(),
'features': self.get_nfeat(),
'directed': not self.is_symmetric()
}
prop.update(d)
return prop
def template(self, d):
d['time'] = d.get('time', None)
netw_templ = '''###### $corpus
Building: $time minutes
Nodes: $instances
Links: $nnz
Degree mean: $nnz_mean
Degree var: $nnz_var
Diameter: $diameter
Modularity: $modularity
Clustering Coefficient: $clustering_coef
Density: $density
Communities: $communities
Relations: $features
Directed: $directed
\n'''
return super(frontendNetwork, self).template(d, netw_templ)
def info_list(graph):
"""Returns useful information about the graph as a list of tuples
:param pybel.BELGraph graph: A BEL graph
:rtype: list
"""
number_nodes = graph.number_of_nodes()
result = [
('Nodes', number_nodes),
('Edges', graph.number_of_edges()),
('Citations', count_unique_citations(graph)),
('Authors', count_unique_authors(graph)),
('Network density', nx.density(graph)),
('Components', nx.number_weakly_connected_components(graph)),
]
try:
result.append(('Average degree', sum(graph.in_degree().values()) / float(number_nodes)))
except ZeroDivisionError:
log.info('Graph has no nodes')
if graph.warnings:
result.append(('Compilation warnings', len(graph.warnings)))
return result
def calculate_density(graph):
print "\n\tCalculating density..."
g = graph
dens = nx.density(g)
print "\t > Graph density:", dens
return g, dens
def density(Network):
density = []
density.append(round(nx.density(G)))
# adjacent matrix
def run(self, ips, imgs, para = None):
titles = ['PartID', 'Noeds', 'Edges', 'TotalLength', 'Density', 'AveConnect']
k, unit = ips.unit
gs = nx.connected_component_subgraphs(ips.data, False) if para['parts'] else [ips.data]
comid, datas = 0, []
for g in gs:
sl = 0
for (s, e) in g.edges():
sl += sum([i['weight'] for i in g[s][e].values()])
datas.append([comid, g.number_of_nodes(), g.number_of_edges(), round(sl*k, 2),
round(nx.density(g), 2), round(nx.average_node_connectivity(g),2)][1-para['parts']:])
comid += 1
print(titles, datas)
IPy.table(ips.title+'-graph', datas, titles[1-para['parts']:])
def run(self, ips, imgs, para = None):
titles = ['PartID', 'Noeds', 'Edges', 'TotalLength', 'Density', 'AveConnect']
k, unit = ips.unit
gs = nx.connected_component_subgraphs(ips.data, False) if para['parts'] else [ips.data]
comid, datas = 0, []
for g in gs:
sl = 0
for (s, e) in g.edges():
sl += sum([i['weight'] for i in g[s][e].values()])
datas.append([comid, g.number_of_nodes(), g.number_of_edges(), round(sl*k, 2),
round(nx.density(g), 2), round(nx.average_node_connectivity(g),2)][1-para['parts']:])
comid += 1
print(titles, datas)
IPy.table(ips.title+'-graph', datas, titles[1-para['parts']:])
def density(self):
g = self.getG()
return nx.density(g)
def graphDensity(self):
self.G.clear()
with open(self.filename, 'r') as f:
for line in f.readlines():
transaction = line.strip().split(self.delimeter)
if len(transaction) == 1:
self.G.add_node(transaction[0])
elif len(transaction) > 1:
for i in range(len(transaction) - 1):
for j in range(i + 1, len(transaction)):
self.G.add_edges_from([(transaction[i], transaction[j])])
else:
return -1 # empty transaction found
return nx.density(self.G)
def graphDensity(self):
self.G.clear()
with open(self.filename, 'r') as f:
for line in f.readlines():
transaction = line.strip().split(self.delimeter)
if len(transaction) == 1:
self.G.add_node(transaction[0])
elif len(transaction) > 1:
for i in range(len(transaction) - 1):
for j in range(i + 1, len(transaction)):
self.G.add_edges_from([(transaction[i], transaction[j])])
else:
return -1 # empty transaction found
return nx.density(self.G)
def graphDensity(self):
self.G.clear()
with open(self.filename, 'r') as f:
for line in f.readlines():
transaction = line.strip().split(self.delimeter)
if len(transaction) == 1:
self.G.add_node(transaction[0])
elif len(transaction) > 1:
for i in range(len(transaction) - 1):
for j in range(i + 1, len(transaction)):
self.G.add_edges_from([(transaction[i], transaction[j])])
else:
return -1 # empty transaction found
return nx.density(self.G)
def graphDensity(self):
self.G.clear()
with open(self.filename, 'r') as f:
for line in f.readlines():
transaction = line.strip().split(self.delimeter)
if len(transaction) == 1:
self.G.add_node(transaction[0])
elif len(transaction) > 1:
for i in range(len(transaction) - 1):
for j in range(i + 1, len(transaction)):
self.G.add_edges_from([(transaction[i], transaction[j])])
else:
return -1 # empty transaction found
return nx.density(self.G)