Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用公式计算python中无向图的圈数_Python_Graph_Networkx_Cycle_Discrete Mathematics - Fatal编程技术网

用公式计算python中无向图的圈数

用公式计算python中无向图的圈数,python,graph,networkx,cycle,discrete-mathematics,Python,Graph,Networkx,Cycle,Discrete Mathematics,我找到了这个公式来计算无向图中的4圈数: [![formula to calculate the number of 4-cycle][1]][1] Ck = 1/2k Tr(Pk-1 A) k stands for k-cycle, and A is the adjacency matrix, Pk-1 is the path count matrix 网页链接: [数学世界] 我现在尝试用python编写这个简单的公式,我可以使用NetworkX的邻接矩阵函数来得到邻接矩阵,我也

我找到了这个公式来计算无向图中的4圈数:

 [![formula to calculate the number of 4-cycle][1]][1]

 Ck = 1/2k Tr(Pk-1 A)

 k stands for k-cycle, and A is the adjacency matrix, Pk-1 is the path count matrix
网页链接:

[数学世界]

我现在尝试用python编写这个简单的公式,我可以使用NetworkX的邻接矩阵函数来得到邻接矩阵,我也可以得到矩阵跟踪。我只是不确定所谓的路径计数Pk矩阵,我在谷歌上搜索了一会儿,但没有找到关于这一点的直接解释。专家能否建议这个Pk矩阵是什么,我想知道是否可以用Python编写它


提前谢谢

我猜是
p_k=A^k
。但是,由于您对4个循环的数量感兴趣,您可以简单地使用以下公式(3):

其中
a{ij}^{(2)}
a^2
的元素


这个公式应该可以通过
numpy
轻松实现

多谢各位。但我不确定A^2是什么…它是邻接矩阵的一半吗?那是矩阵幂,例如,
A^2=A*A
,后者是矩阵乘法(
A^4=A*A*A
),而
A
是邻接矩阵。谢谢,这非常有帮助!
8c_4 = Tr(A^4) - 2m - 2 \sum_i{i\ne j} a_{ij}^{(2)}