0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

networkxのランダム有向グラフの生成

Last updated at Posted at 2019-06-25

あるエッジリストをもとにランダムな有向グラフを生成したいです。

import networkx as nx

G = nx.read_edgelist(path, create_using=nx.DiGraph())#自己ループも多重辺も存在しない。

ここで生成するランダム有向グラフの条件として
・Gのノード数と一致する
・GのノードのIn、Outの次数を保存している
・自己ループは存在して良いが多重辺は存在してはならない。よってGのエッジの数を保存している。

A = nx.directed_configuration_model(in_degree_sequence, 
                out_degree_sequence=, create_using=nx.DiGraph())

上のコードを用い、ランダムグラフを生成しました。
この関数は普通、MultiDiGraphを返します。そのためDiGraphと指定しました。
しかし、この関数は、指定したグラフを生成するわけではなく、MultiDiGraphを生成した後にそれをDiGraphに直しているようです。
そのためノード数は一致しますが次数とエッジ数がGとは異なるランダム有向グラフを生成してしまいました。
ノード数が100万個レベルの大きいデータを扱っている時重複してしまうエッジの数は全体のエッジ数に対して0.5%にも満たないほど小さかったため、グラフの解析において大きな影響を与えないと考えました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?