CPM(Cluster Percolation method)派系过滤算法

2024-05-30 03:38

本文主要是介绍CPM(Cluster Percolation method)派系过滤算法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文地址

一、概念

(1)完全子图/全耦合网络/k-派系:所有节点全部两两相连

                                          图1

这些全耦合网络也成为派系,k-派系表示该全耦合网络的节点数目为k

1)k-派系相邻:两个不同的k-派系共享k-1个节点,认为他们相邻

2)k-派系连通:一个k-派系可以通过若干个相邻的k-派系到达另一个k-派系,则称这两个k-派系彼此联通

二、思路

                       图2

1- first find all cliques of size k in the graph

  第一步首先找到网络中大小为K的完全子图,例如图2中k=3的完全子图有{123} {134} {456} {567} {568} {578} {678}
2- then create graph where nodes are cliques of size k

  第二步将每个完全子图定义为一个节点,建立一个重叠矩阵

             a=[3 2 0 0 0 0 0;

                 2 3 1 0 0 0 0;

                 0 1 3 2 2 1 1;

                 0 0 2 3 2 2 2;

                 0 0 2 2 3 2 2;

                 0 0 1 2 2 3 2;

                 0 0 1 2 2 2 3 ]
3- add edges if two nodes (cliques) share k-1 common nodes

  第三步将重叠矩阵变成社团邻接矩阵,其中重叠矩阵中对角线小于k,非对角线小于k-1的元素全置为0

           a=[1 1 0 0 0 0 0;

                 1 1 0 0 0 0 0;

                 0 0 1 1 1 0 0;

                 0 0 1 1 1 1 1;

                 0 0 1 1 1 1 1;

                 0 0 0 1 1 1 1;

                 0 0 0 1 1 1 1 ]


4- each connected component is a community

画出派系图,如上所示

从图中可以看出包含了两个社区{1,2,3,4}和{4,5,6,7,8},节点4属于两个社区的重叠节点

三、代码实现

R实现代码和Java实现代码可在GitHub网站上下载,R下载地址

https://github.com/angelosalatino/CliquePercolationMethod-R

四、References

Palla, G., Derényi, I., Farkas, I., & Vicsek, T. (2005). Uncovering the overlapping community structure of complex networks in nature and societyNature435(7043), 814-818.

注意事项:

CPM算法不适用于稀疏矩阵,K的取值对结果影响不大,一般实验证明4-6为最佳

2017年4.16更新

用matlab算法实现,其中做了一点小变动,k是最小派系范围,寻找的是大于等于k的完全子图数,得到结果与上述描述结果一致,节点4是重叠节点

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function  [components,cliques,CC] = k_clique(k,M)
% k-clique algorithm for detecting overlapping communities in a network
% as defined in the paper "Uncovering the overlapping
% community structure of complex networks in nature and society" -
% G. Palla, I. Derényi, I. Farkas, and T. Vicsek - Nature 435, 814–818 (2005)
%
% [X,Y,Z] = k_clique(k,A)
%
% Inputs:
% k - clique size
% A - adjacency matrix
%
% Outputs:
% X - detected communities
% Y - all cliques (i.e. complete subgraphs that are not parts of larger
% complete subgraphs)
% Z - k-clique matrix
%
% Author : Anh-Dung Nguyen
% Email : anh-dung.nguyen@isae.fr
% The adjacency matrix of the example network presented in the paper
% M = [1 1 0 0 0 0 0 0 0 1;
%     1 1 1 1 1 1 1 0 0 1;
%     0 1 1 1 0 0 1 0 0 0;
%     0 1 1 1 1 1 1 0 0 0;
%     0 1 0 1 1 1 1 1 0 0;
%     0 1 0 1 1 1 1 1 0 0;
%     0 1 1 1 1 1 1 1 1 1;
%     0 0 0 0 1 1 1 1 1 1;
%     0 0 0 0 0 0 1 1 1 1;
%     1 1 0 0 0 0 1 1 1 1];
nb_nodes =  size (M,1);  % number of nodes
% Find the largest possible clique size via the degree sequence:
% Let {d1,d2,...,dk} be the degree sequence of a graph. The largest
% possible clique size of the graph is the maximum value k such that
% dk >= k-1
degree_sequence =  sort ( sum (M,2) - 1, 'descend' );
max_s = 0;
for  i  = 1: length (degree_sequence)
     if  degree_sequence( i ) >=  i  - 1
         max_s =  i ;
     else
         break ;
     end
end
cliques =  cell (0);
% Find all s-size kliques in the graph
for  s = max_s:-1:3
     M_aux = M;
     % Looping over nodes
     for  n = 1:nb_nodes
         A = n;  % Set of nodes all linked to each other
         B =  setdiff ( find (M_aux(n,:)==1),n);  % Set of nodes that are linked to each node in A, but not necessarily to the nodes in B
         C = transfer_nodes(A,B,s,M_aux);  % Enlarging A by transferring nodes from B
         if  ~ isempty (C)
             for  i  size (C,1)
                 cliques = [cliques;{C( i ,:)}];
             end
         end
         M_aux(n,:) = 0;  % Remove the processed node
         M_aux(:,n) = 0;
     end
end
% Generating the clique-clique overlap matrix
CC =  zeros ( length (cliques));
for  c1 = 1: length (cliques)
     for  c2 = c1: length (cliques)
         if  c1==c2
             CC(c1,c2) =  numel (cliques{c1});
         else
             CC(c1,c2) =  numel ( intersect (cliques{c1},cliques{c2}));
             CC(c2,c1) = CC(c1,c2);
         end
     end
end
% Extracting the k-clique matrix from the clique-clique overlap matrix
% Off-diagonal elements <= k-1 --> 0
% Diagonal elements <= k --> 0
CC( eye ( size (CC))==1) = CC( eye ( size (CC))==1) - k;
CC( eye ( size (CC))~=1) = CC( eye ( size (CC))~=1) - k + 1;
CC(CC >= 0) = 1;
CC(CC < 0) = 0;
% Extracting components (or k-clique communities) from the k-clique matrix
components = [];
for  i  = 1: length (cliques)
     linked_cliques =  find (CC( i ,:)==1);
     new_component = [];
     for  j  = 1: length (linked_cliques)
         new_component =  union (new_component,cliques{linked_cliques( j )});
     end
     found = false;
     if  ~ isempty (new_component)
         for  j  = 1: length (components)
             if  all ( ismember (new_component,components{ j }))
                 found = true;
             end
         end
         if  ~found
             components = [components; {new_component}];
         end
     end
end
     function  R = transfer_nodes(S1,S2,clique_size,C)
         % Recursive function to transfer nodes from set B to set A (as
         % defined above)
         
         % Check if the union of S1 and S2 or S1 is inside an already found larger
         % clique
         found_s12 = false;
         found_s1 = false;
         for  c = 1: length (cliques)
             for  cc = 1: size (cliques{c},1)
                 if  all ( ismember (S1,cliques{c}(cc,:)))
                     found_s1 = true;
                 end
                 if  all ( ismember ( union (S1,S2),cliques{c}(cc,:)))
                     found_s12 = true;
                     break ;
                 end
             end
         end
         
         if  found_s12 || ( length (S1) ~= clique_size &&  isempty (S2))
             % If the union of the sets A and B can be included in an
             % already found (larger) clique, the recursion is stepped back
             % to check other possibilities
             R = [];
         elseif  length (S1) == clique_size;
             % The size of A reaches s, a new clique is found
             if  found_s1
                 R = [];
             else
                 R = S1;
             end
         else
             % Check the remaining possible combinations of the neighbors
             % indices
             if  isempty ( find (S2>= max (S1),1))
                 R = [];
             else
                 R = [];
                 for  w =  find (S2>= max (S1),1): length (S2)
                     S2_aux = S2;
                     S1_aux = S1;
                     S1_aux = [S1_aux S2_aux(w)];
                     S2_aux =  setdiff (S2_aux(C(S2(w),S2_aux)==1),S2_aux(w));
                     R = [R;transfer_nodes(S1_aux,S2_aux,clique_size,C)];
                 end
             end
         end
     end
end

这篇关于CPM(Cluster Percolation method)派系过滤算法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1015476

相关文章

如何通过Golang的container/list实现LRU缓存算法

《如何通过Golang的container/list实现LRU缓存算法》文章介绍了Go语言中container/list包实现的双向链表,并探讨了如何使用链表实现LRU缓存,LRU缓存通过维护一个双向... 目录力扣:146. LRU 缓存主要结构 List 和 Element常用方法1. 初始化链表2.

golang字符串匹配算法解读

《golang字符串匹配算法解读》文章介绍了字符串匹配算法的原理,特别是Knuth-Morris-Pratt(KMP)算法,该算法通过构建模式串的前缀表来减少匹配时的不必要的字符比较,从而提高效率,在... 目录简介KMP实现代码总结简介字符串匹配算法主要用于在一个较长的文本串中查找一个较短的字符串(称为

通俗易懂的Java常见限流算法具体实现

《通俗易懂的Java常见限流算法具体实现》:本文主要介绍Java常见限流算法具体实现的相关资料,包括漏桶算法、令牌桶算法、Nginx限流和Redis+Lua限流的实现原理和具体步骤,并比较了它们的... 目录一、漏桶算法1.漏桶算法的思想和原理2.具体实现二、令牌桶算法1.令牌桶算法流程:2.具体实现2.1

Python中的随机森林算法与实战

《Python中的随机森林算法与实战》本文详细介绍了随机森林算法,包括其原理、实现步骤、分类和回归案例,并讨论了其优点和缺点,通过面向对象编程实现了一个简单的随机森林模型,并应用于鸢尾花分类和波士顿房... 目录1、随机森林算法概述2、随机森林的原理3、实现步骤4、分类案例:使用随机森林预测鸢尾花品种4.1

Mybatis拦截器如何实现数据权限过滤

《Mybatis拦截器如何实现数据权限过滤》本文介绍了MyBatis拦截器的使用,通过实现Interceptor接口对SQL进行处理,实现数据权限过滤功能,通过在本地线程变量中存储数据权限相关信息,并... 目录背景基础知识MyBATis 拦截器介绍代码实战总结背景现在的项目负责人去年年底离职,导致前期规

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

康拓展开(hash算法中会用到)

康拓展开是一个全排列到一个自然数的双射(也就是某个全排列与某个自然数一一对应) 公式: X=a[n]*(n-1)!+a[n-1]*(n-2)!+...+a[i]*(i-1)!+...+a[1]*0! 其中,a[i]为整数,并且0<=a[i]<i,1<=i<=n。(a[i]在不同应用中的含义不同); 典型应用: 计算当前排列在所有由小到大全排列中的顺序,也就是说求当前排列是第

深入探索协同过滤:从原理到推荐模块案例

文章目录 前言一、协同过滤1. 基于用户的协同过滤(UserCF)2. 基于物品的协同过滤(ItemCF)3. 相似度计算方法 二、相似度计算方法1. 欧氏距离2. 皮尔逊相关系数3. 杰卡德相似系数4. 余弦相似度 三、推荐模块案例1.基于文章的协同过滤推荐功能2.基于用户的协同过滤推荐功能 前言     在信息过载的时代,推荐系统成为连接用户与内容的桥梁。本文聚焦于

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖