【问题标题】:Generating graphs favouring unique cliques生成有利于独特集团的图
【发布时间】:2022-01-16 22:02:16
【问题描述】:

对于我正在进行的一个研究项目,我需要生成随机图,这些图有利于在没有包含相同节点的最大派系的情况下形成派系。例如,Barabási-Albert 模型可以生成包含大团的图,但由于优先附着,这些团主要具有相同的节点。

虽然我更喜欢使用 Networkx 或 IGraph 之类的现有软件包,但我可以实施已正式生成此类网络的研究论文。唯一的标准是,对于具有 10.000 个节点和平均度数为 100 的图,生成这些图的时间不应超过 15 秒。

我也不确定是否应该在这里或https://math.stackexchange.com/ 上问这个问题,所以如果我需要在那里问的话就说吧。

【问题讨论】:

  • 还有cs.stackexchange.com 用于计算机科学。但如果您正在寻找生成图表的实际代码,stackoverflow 可能更适合。
  • 我希望这个问题会在这里结束,因为它是一个研究问题,而不是一个编程问题。 Math.SE 会更好。但是在重新发布之前,我认为您应该澄清“没有包含相同节点的最大集团”的意思。我不明白你想做什么。
  • 您可能已经找到该页面,但以防万一,这里是 networkx 的随机图函数:networkx.org/documentation/stable/reference/…(实际上,该页面上有一些随机图列在某物下方除了“随机图”,因此在整个页面中搜索“随机”和“集团”)。特别是“社区”下的图表经常提到派系:networkx.org/documentation/stable/reference/…
  • 我还建议您仔细考虑“随机图”与“属性 X”的含义(对于任何 X,例如对派系的一些要求)。您想从满足您的属性的图形集中均匀地采样吗?如果没有,那么您打算如何处理这些图表?如果您的抽样有偏差(不均匀),您的结果是否有意义?这已经说明了为什么这个问题不适用于 StackOverflow。
  • 如果你的意思是“不重叠的派系”,这可能接近:doi.org/10.1103/PhysRevE.82.066118

标签: python c++ networkx graph-theory igraph


【解决方案1】:

这是一种可能的算法来生成部分重叠的团图。

我强烈建议您对其进行调整,以使其更适合您对随机分布的直觉。

from itertools import combinations
from itertools import pairwise # or def pairwise(a): return zip(a, a[1:])
import random
import networkx as nx

def random_graph(n_nodes, n_cliques, p_overlap):
    a = [0] + random.sample(range(n_nodes), n_cliques-1) + [n_nodes]  # split points
    cliques = [set(range(i,j)) for i,j in pairwise(a)]                # partition
    nodes = set(range(n_nodes))
    for c in cliques:
        c.update(random.sample(nodes - c, round(p_overlap * len(c)))) # add random nodes from other cliques
    G = nx.Graph()
    for c in cliques:
        G.add_edges_from(combinations(c, 2))
    return G

# Can add some randomness by replacing round(p_overlap * len(c)) with a random.gauss()

# TESTING
import matplotlib.pyplot as plt

G = random_graph(20, 4, 0.1)
nx.draw(G)
plt.show()

【讨论】:

    【解决方案2】:

    这取决于你所说的随机是什么意思。

    但是,这里有一种算法,用于生成具有不共享节点且具有一定数量“随机性”的大团的图

    Input number of cliques required ( or random distribution specs for same )
    Input number of nodes in each clique ( or random distribution specs for same )
    LOOP over number of cliques
       LOOP over number of nodes in clique
            Add node to graph
       Add links between every pair of nodes in clique
    LOOP c1 over cliques
        LOOP c2 over c1+1 to number of cliques
            SELECT a random node in c1 and c2
            Link nodes in c1 and c2
    

    c1 循环确保图是完全连通的。不知道你是否想要那个。它在每对派系之间创建一个链接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多