在分块约束下(分块邻接矩阵)绘制一致图。常用于网络测试。

ugd的Python项目详细描述


统一图形绘制

该软件包实现了网络的随机抽取算法。特别是它创建了具有 给定度序列和分区约束(分区中节点组之间交叉边/箭头的固定数目)。 文献中也将这组约束定义为分区邻接矩阵(pam)约束。

它是根据论文实现的:

运行它

通过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

提供了两个功能。

  1. 图论测验
    • 在所需的约束集下生成均匀采样graphs序列。
  2. 有向图检验
    • 在所需的约束集下生成均匀采样有向图序列。

对于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

在终点站。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
jframe为什么JAVA paint()方法不起作用?   java Guice:将ContainerRequestContext注入拦截器   java如何优雅地关闭Spring JMS MessageListenerAdapter   java如何在Spring中设置快照隔离级别   Java中的安卓平台独立信任存储路径   java无法在eclipse中运行hello world程序   java Sinch空指针问题   使用Java将JSON流式传输到BigQuery   java从“大数据”中选择什么Swing控件?   java通过对象字段过滤/排序集合?   java将数据从活动传递到另一个活动中的片段   java访问打包在jar文件中的文档   Java获取事件的大小。getDragboard()。getFiles()。流()。映射(文件::长度)。toString());   java Android libgdx:启动程序图标按下后,启动屏幕不会立即显示   java如何在Google App Engine灵活环境中配置oracle jdk   java有没有办法减少这些行?   Java:客户端socket不读取第二行,在终止符行之后保持打开状态   java以编程方式获取api 29上的所有APK文件   java ActionBar按钮不显示