Community Discovery SLPA Algorithm

Source: Internet
Author: User

Community (community) definition: Nodes within the same community are closely related to nodes, and the relationships between communities and communities are sparse.

Figure G=g (V,e), the so-called Community Discovery is defined in Figure G to determine the NC (>=1) Community c={c1,c2,..., CNV}, so that each community's vertex set constitutes a cover of V.

If the communication of the vertex set of any two communities is empty, then C is a non-overlapping community (disjoint communities); otherwise called overlapping community (overlapping communities).

SLPA (Speaker-listener label propagation algorithm) algorithm is a Community discovery algorithm, which is an extension of the LPA algorithm (label propagation algorithm).

The algorithm idea is as follows:

Input parameters: Number of iterations T, Threshold R to meet community number requirements

Output parameters: Community distribution of each node

(1) First, a unique tag is initialized in the memory of each node.

(2) Then repeat the following steps until the maximum iteration T is reached:

  A. Select a node as the listener;

B. The random selection probability of each neighbor of the selected node is proportional to the label of the label's occurrence frequency in its memory, and the selected label (Speakervote) is sent to the listener (listener);

  C. The listener adds the most popular tags to memory that are received.

(3) Finally, based on the label and Threshold R in memory, post-processing is used for the output community.

1  Public intSpeakervote () {2         //Run through each element in the map to create a cumulative distribution3Set<integer> Communityids =Communitydistribution.keyset ();4Arraylist<integer> Communities =NewArraylist<integer>();5Arraylist<integer> cumulativecounts =NewArraylist<integer>();6         7         intSum=-1;8          for(Integer comm:communityids) {9Sum + =Communitydistribution.get (comm);Ten Communities.add (comm); One cumulativecounts.add (sum); A         } -      -         //Generate a random integer in the range [0,sum] the         intRand = Randomnumgenerator.getrandomint (sum+1); -          -         //Find The index of first value greater than Rand in Cumulativecounts -         intI=0; +          for(i=0; i<cumulativecounts.size (); i++) { -             if(Cumulativecounts.get (i) >=Rand) +                  Break; A         } at              -         //Return the corresponding community -         returnCommunities.get (i); -}
Speakervote
1  Public voidupdatelabels (Integer userId) {2set<defaultweightededge> incomingedges = Usernodegraph.getgraph (). Incomingedgesof (UserId);//get all of the vertex's in-degree vertices3Map<integer, integer> incomingvotes =NewHashmap<integer, integer> ();//All speaker vertex voting conditions4         5         //For each vertex V with a incoming edge to the current node6          for(Defaultweightededge edge:incomingedges) {7             intSpeakerid =usernodegraph.getgraph (). Getedgesource (edge);8Usernode Speakernode =Usernodegraph.getnodemap (). get (Speakerid);9             Ten             intVotedcommunity =speakernode.speakervote (); One             intVotedcommunitycount = 1; A             if(Incomingvotes.containskey (votedcommunity)) { -Votedcommunitycount + =Incomingvotes.get (votedcommunity); -             }  the incomingvotes.put (votedcommunity, votedcommunitycount); -         } -          -         //Find The most popular vote +Iterator<entry<integer, integer>> it =Incomingvotes.entryset (). iterator (); -         intPopularcommunity=-1; +         intPopularcommunitycount=0; A          while(It.hasnext ()) { atEntry<integer, integer> Entry =It.next (); -             if(Entry.getvalue () >Popularcommunitycount) { -Popularcommunity =Entry.getkey (); -Popularcommunitycount =Entry.getvalue (); -             } -         } in         //Update Community Distribution of the current node by 1 -Usernode CurrentNode =Usernodegraph.getnodemap (). get (userId); toCurrentnode.updatecommunitydistribution (popularcommunity, 1); +}
listenerupdatecommunity

Note: please contact [email protected]for source code.

Community Discovery SLPA Algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.