dotmotif介绍


一、简介

DotMotif是一个Python的第三方库,用于检测大型图(graph)中的子图(subgraph)或模体(motif),可以应用在复杂网络相关项目中。
官网链接:https://github.com/aplbrain/dotmotif


二、官方文档

ArgumentType, DefaultBehavior
ignore_directionbool: FalseWhether to disregard direction when generating the database query
limitint: NoneA limit (if any) to impose on the query results
enforce_inequalitybool: FalseWhether to enforce inequality; in other words, whether two nodes should be permitted to be aliases for the same node. For example, in A->B->C; if A!=C, then set to True
exclude_automorphismsbool: FalseWhether to return only a single example for each detected automorphism. See more in the documentation
参数类型,默认值行为
ignore_directionbool:False生成数据库查询时是否忽略方向(取决于被检测的图是否为无向图)
limitint:None对查询结果施加的限制(如果有的话)
enforce_inequalitybool:False是否强制执行不平等;换句话说,是否允许两个节点作为同一节点的别名。例如,在A->B->C中;如果A不等于C,那么设置为True
exclude_automorphismsbool:False是否将自同构体算作一项。详见文档

三、示例

0.安装dotmotif

使用pip安装:

pip install dotmotif

1.引入库

import networkx as nx
from dotmotif import Motif, NetworkXExecutor

2.创建图

G = nx.DiGraph()
G.add_nodes_from(['a', 'b', 'c'])
G.add_edges_from([('a', 'b'), ('b', 'c'), ('c', 'a')])

3.创建检测器

E = NetworkXExecutor(graph=G)
triangle = Motif(input_motif="""
A -> B
B -> C
C -> A
""", ignore_direction=False, exclude_automorphisms=True)

4.检测模体、输出结果

result = E.find(triangle)
print(result)
print(len(result))

5.模体保存及读取

triangle.save('motif_triangle.pkl')
triangle.load('motif_triangle.pkl')

四、代码汇总

import networkx as nx
from dotmotif import Motif, NetworkXExecutor
G = nx.DiGraph()
G.add_nodes_from(['a', 'b', 'c'])
G.add_edges_from([('a', 'b'), ('b', 'c'), ('c', 'a')])
E = NetworkXExecutor(graph=G)
triangle = Motif(input_motif="""
A -> B
B -> C
C -> A
""", ignore_direction=False, exclude_automorphisms=True)
#triangle.save('motif_triangle.pkl')
#triangle=triangle.load('motif_triangle.pkl')
result = E.find(triangle)
print(result)
print(len(result))
  • 28
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值