在分块约束下(分块邻接矩阵)绘制一致图。常用于网络测试。
ugd的Python项目详细描述
统一图形绘制
该软件包实现了网络的随机抽取算法。特别是它创建了具有 给定度序列和分区约束(分区中节点组之间交叉边/箭头的固定数目)。 文献中也将这组约束定义为分区邻接矩阵(pam)约束。
它是根据论文实现的:
- 算法正确性证明
- pam实现问题的讨论
鹈鹕,A.和格雷厄姆,B.S.(2019年)。社会经济战略互动的检验 网络形成。加州大学伯克利分校技术报告。
- 一个正常形式的n人网络形成博弈的局部最强大检验统计量的推导
运行它
通过PIP安装纸张:
- PIP安装UGD
然后运行
#import modules
import ugd
import numpy
# create ajdancy matrix
adj_m = numpy.zeros((4,4))
adj_m[0,1] = 1
adj_m[1,0] = 1
adj_m[3,2] = 1
adj_m[2,3] = 1
# create dictionary of nodeatributes
var_dict ={
0: {'gender': 'm'},
1: {'gender': 'm'},
2: {'gender': 'f'},
3: {'gender': 'f'},
}
out_dict = ugd.graph_hyp_test(adj_m=adj_m, var_dict = var_dict, test_variable= ('gender','m','f'),mixing_time=1000, anz_sim=100, show_polt=True)
使用ugd
使用ugd的最简单方法是简单地传入邻接矩阵并设置show_plot=true。这运行模拟 算法并绘制默认统计信息。
统计数据可以定制。首先输入一个具有节点特征的字典并测试一个特征。 其次,通过编写一个服装测试统计数据,并将其作为“stat-f”输入函数。如何写出“本地最强大” 特定网络阵型游戏的测试统计数据来自Pelican,A.&Graham,B.S.(2019)。最优值的权重 测试统计不是由这个包计算的,它必须与其他统计包和 通过“stat_f”输入或直接应用于ugd包返回的图形列表。
节点特性可以作为控件添加。该算法生成的一致图也具有相同的个数 控件诱导的节点组之间的边。请注意,如果添加了许多控件,则算法速度会慢一些。 硬约束(其中没有边或某些组),如二分图中的组约束 不要减慢算法的速度。
通过直接使用模拟图,可以方便地定制单个图的处理。
测试社会和经济网络的切入点可以在这里找到。
API
提供了两个功能。
- 图论测验
- 在所需的约束集下生成均匀采样graphs序列。
- 有向图检验
- 在所需的约束集下生成均匀采样有向图序列。
对于api,这两个函数的区别只是邻接矩阵的解释只有一次。 作为有向图表示和一次作为图表示。
INPUT:
:param adj_m: A numpy array containing 0 and 1s as elements, representing
adjacency matrix of the graph
:param var_dict: A dictionary with the integers 1..n as primary key (representing
the n nodes). The values are dictionaries containing the
Variable name as keys and the values can either be numbers or be
numbers or strings
:param stat_f: A function which maps the adj_m and var_dict to a number "the
statistic of interest".
:param test_variable: Alternative to stat_f, creating a statistic which counts the
arrows form a node-subset into another. It is a triple with
first element variable name, second the value of the variable
for the set where the arrows leave and third the value of the
subset where the arrow go to.
:param controlls: List of variable names, the number of arrows crossing the groups
induced by the controls is constant in all the simulation.
:param mixing_time: Number of runs (steps in the markov graph) before a the graph
is considered random
:param anz_sim: Number of simulations
:param show_polt: Boolean whether a plot is desired
OUTPUT:
:return: out_dict Dictionary with keys 'graph_list', 'stat_list', 'plot',
and 'info_dict'
graph_list: List of random adjacency matrices with the given degree-sequence
and arrows between the controls
stat_list: List of the statistics stat_f evaluated for the random graphs
plot: Plot with the illustration of the estimation output
info_dict: Dictionary with the information about the simulation
架构:
所有的逻辑都在有向图的文件夹中实现。它分为
马尔可夫步行
本文算法1的实现markov-draw算法
施劳芬建筑
本文算法2的实现schlaufen检测算法
型号
包含数据模型(适用于 schlaufen中改变路径的有效构造)
用户界面
包含用于输入验证、分析输入、估计运行时的所有逻辑, 图形格式转换,输出处理。
帮助功能
评论
当前的实现,仅包括控制节点组之间固定数量的交叉边/箭头,如 约束条件。更复杂的可以通过编写no_violation函数的consum实现来实现 在约束冲突检查中。注意,根据约束条件,schlaufensequence的构造应该 不是因为找到一个可行的而停止,而是因为随机停止。这是为了保持正确性。
测试
所有测试都在测试文件夹中。它们是使用pytest编写的。 要将它们CD执行到测试文件夹并运行
- pytest
在终点站。