Code Monkey home page Code Monkey logo

genlouvain's Introduction

GenLouvain Version 2.2

released July 2019

Please cite this code as Lucas G. S. Jeub, Marya Bazzi, Inderjit S. Jutla, and Peter J. Mucha,
"A generalized Louvain method for community detection implemented in MATLAB," https://github.com/GenLouvain/GenLouvain (2011-2019).

Contents:

This package consists of the main genlouvain.m file which calls a number of subroutines implemented as mex functions. Source code for the mex files is included in the "MEX_SRC" directory. Pre-compiled executables for 64bit Mac, Windows, and Linux systems are included in the private directory. It also includes iterated_genlouvain.m which iteratively applies genlouvain on the output partition of the previous run with optional post-processing. Functions to compute modularity matrices and to post-process partitions are included in the "HelperFunctions" directory. The post-processing functions solve optimal assignment problems using code by Markus Buehren (included in the "Assignment" directory and available at https://uk.mathworks.com/matlabcentral/fileexchange/6543-functions-for-the-rectangular-assignment-problem/content/assignmentoptimal.m).

Installation instructions:

Make sure that the "GenLouvain" folder and all its subfolders are on the MATLAB path to ensure that all dependencies between functions are accessible.

Mex files:

The included precompiled mex executables were generated using MATLAB_R2019a and may not be compatible with other versions of MATLAB, resulting in an Invalid MEX-file error. If this is the case or the mex executables for your system are not in the private directory, you will need to compile these files on your system by running the compile_mex.m script from the "MEX_SRC" directory (check the mex documentation in your MATLAB). If you would like to share these compiled files with other users, email them to Peter Mucha ([email protected]).

If you get a Cannot write to destination error when running compile_mex.m, remove or rename the offending file and try again.

Changes from previous versions:

Support for multiple aspects

Version 2.2 of GenLouvain adds support for multilayer networks with multiple aspects (see "multiaspect.m" in "HelperFunctions").

Additional randomization:

Version 2.1 of GenLouvain also a implements a new 'moverandw' option which chooses moves at random with a probability proportional to the increase in the quality function. This is in addition to the 'moverand' option from Version 2.0 which chooses moves uniformly at random from all possible moves that improve the quality function.

Increased speed:

Version 2.1 removes quadratic bottlenecks that could become noticeable for very large networks (millions of nodes). The mex functions have also been optimized further.

Generate modularity matrices:

Version 2.1 includes a folder "HelperFunctions" with functions to generate different types of monolayer and multilayer modularity matrices.

Iterated GenLouvain with postprocessing:

Includes iterated_genlouvain which iteratively restarts genlouvain with the output partition of the previous run (with optional post-processing). Post-processing functions for ordered and unordered multilayer partitions that increase the value of the quality function without changing partitions on each layer are included in "HelperFunctions". "HelperFunctions" also includes functions that compute "persistence" for ordered and unordered multilayer networks.

Usage:

  1. generate a modularity matrix for your network (see doc('HelperFunctions'))

  2. use genlouvain or iterated_genlouvain to obtain a partition that approximately optimizes the corresponding modularity-like quality function

  3. ideally repeat step 2 multiple times to check that the output is consistent between randomizations

The genlouvain.m function uses different methods for computing the change in modularity, depending on whether the modularity matrix is provided as a sparse matrix or not. Depending on the amount of sparsity in the modularity matrix, it may be faster to convert it to a full matrix.

More extensive documentation and example use of this code is provided in the inline documentation comments for the individual functions.

See doc('genlouvain') and doc('iterated_genlouvain') for more information on the main modularity opimising functions. See doc('HelperFunctions') for a list of the pre-build modularity functions and post-processors and refer to the documentation of the individual functions for more detailed instructions.

IMPORTANT NOTE: When using the multilayer quality function in Mucha et al. 2010, we recommend using iterated_genlouvain with 'moverandw' and the appropriate post-processing function (i.e., postprocess_ordinal_multilayer for an ordered multilayer network and postprocess_categorical_multilayer for an unordered multilayer network) for better results.

Acknowledgments:

A special thank you to Stephen Reid, whose greedy.m code was the original version that has over time developed into the present code.

Thank you also to Dani Bassett, Jesse Blocher, Mason Porter and Simi Wang for inspiring improvements to the code.

References:

Mucha, P. J., Richardson, T., Macon, K., Porter, M. A. & Onnela, J.-P. Community structure in time-dependent, multiscale, and multiplex networks. Science 328, 876-878 (2010).

License:

The codes included in this directory are provided for broad use under a minor (last line) modification of the "FreeBSD License" (see License.txt)


Notes on OCTAVE compatibility:

The compile_mex.m script from the MEX_SRC directory creates OCTAVE .mex files when run from OCTAVE.

If you are trying to use this from the old 3.4.0 .app bundle version of OCTAVE for Mac, you will need to fix OCTAVE's build configuration first (or you may want to consider upgrading to a recent 3.8.x version where this seems to work out of the box):

  1. Ensure that the environment variables CXX and DL_LD point to a C++ compiler installed on your system (e.g. by running setenv(‘CXX’,’/usr/bin/g++’) setenv(‘DL_LD’,’/usr/bin/g++’) where ‘/usr/bin/g++’ may need to be replaced with the path to your compiler depending on your system configuration).

  2. Include the ‘-arch i386’ option in CXXFLAGS and LDFLAGS by running setenv('CXXFLAGS',[getenv('CXXFLAGS'),' -arch i386']) setenv('LDFLAGS',[getenv('LDFLAGS'),' -arch i386']) to create 32bit binaries.

  3. Change line 52 of /Applications/Octave.app/Contents/Resources/include/octave-3.4.0/octave/mexproto.h from #include <cstdlib> to #include <stdlib.h> to avoid a conflict from including two different versions of the standard library.

  4. Finally run compile_mex to compile the binaries.


genlouvain's People

Contributors

ljeub avatar mbazzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

genlouvain's Issues

Identified community results in no contact with particles

Hello,

I also used geographical null model as" A=@(i)W(:,i)-gamma*B(:,i); [S,Q]=genlouvain(A);", but my data is very large as the "W" and "B" are both 20463x20463. As a result, the result of project is about particles don't contact.
image
Like this, blue and cyan are two communities, but you can see the particles in the same community don't contact.I sincerely need your help!

Sincerely,
Zhang

Question on using different null models

Hello,

This isn't an issue, I have a question that I haven't figured been able to figure out. I apologize for writing in the issues tab.

I am new to Matlab and coding, and I'm having difficulty figuring out how to apply a 'Geographical' Null model to the Louvain algorithm. The geographical null model has been described in much of Dr. Danielle Bassett's works with community detection.
Pij = pBij
Pij is the null model, p is the mean edge weight, and Bij is the binary adjacency matrix of the network.

I saw a comment in the modularity function that the function could be altered for different null models; however, I am unsure how to do this. I would truly appreciate any guidance on how to incorporate the formula into the code.

Sincerely,
Richard

Taking into account interlayer edges

Dear Lucas,

is it possible with GenLouvain to take into account arbitrary interlayer edges? (i.e., not just coupling ones). I wasn't able to find informations about this on the netwiki.

Best regards,
Roberto Interdonato

Visualization

This is not directly an issue but more a question. I'm using your code to find community structures in my temporal network. Now I try to perform visualization of the communities in time. Looking at the wonderful figure in Mucha et al. (2010) (Figure 3), I wonder how to perform such visualization. Any pointer would be greatly appreciated.

Modularity in iterated_genlouvain appear random (multilayer network)

[S_g1, Q_g1] = iterated_genlouvain(B_g1,10000,0,1,'moverandw',[], PP_g1);

Output values of S_g1 were observed to have some element of randomness i.e for a give input data over successive independent execution, outputs are not the same, how can this randomness be removed?
I have tried switching from moverandw to move but no significant improvement.

Thanks in advance for your clarification/suggestion

Support for Multi-layered network with cross node couplings

Does this implementation support a network where cross connections between nodes across layers exist? (Example connections like Node1 of Layer1 connected to Node 2 of Layer2) . Although the formula for Modularity does not support this but is there a way around?
I want to do community detection on such a network (basically a fully connected network). Any suggestions on how to achieve this if not supported by this package?

octave use

I am having trouble compiling the MEX files for octave. I know this is probably an octave problem, but I am curious if anyone has had this issue before. Here is the command and output. Thanks!

octave bertolem/GenLouvain-master/MEX_SRC/compile_mex.m
warning: docstring file '/usr/share/octave/3.8.2/etc/built-in-docstrings' not found
GNU Octave, version 3.8.2
Copyright (C) 2014 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. For details, type 'warranty'.

Octave was configured for "x86_64-redhat-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.

warning: unknown mexext mex, assuming 64bit
error: mkoctfile: unable to find the mkoctfile command, Octave installation is incomplete

Bug? Comparison between double and string is not supported

Dear GenLouvain team,

I apologize if this is not a bug but rather due to my incompetence. In which case I will be happy to close it asap. I am trying to run your script on a sparse network matrix but after a few iteration the script returns the error enclosed down below.

The code I am running is as follows:

N = table of Node features (including column "Name")
D = table of Edge features (including the column "EndNodes")

network = digraph(D, N);

n = numel(network.Nodes.Name);

adj_net = sparse(n,n) + adjacency(network ); % this way, we obtain a nxn matrix filled with either zero or ones

[B,twom] = modularitydir_f(adj_net ,1);

lou = genlouvain(B,verbose=1);

The code produces the following:

Merging 364108 communities 03-Nov-2023 12:09:42
361986 change: 3135.6397 total: 3135.6397 relative: 1
361963 change: 47.3485 total: 3182.9881 relative: 0.014875
361960 change: 5.4692 total: 3188.4574 relative: 0.0017153
361960 change: 2.9646 total: 3191.422 relative: 0.00092894
361959 change: 1.9864 total: 3193.4083 relative: 0.00062202
361959 change: 0 total: 3193.4083 relative: 0
Error using >
Comparison between double and string is not supported.

Error in genlouvain (line 304)
if (t>limit)

Error in iterated_genlouvain (line 215)
[S,Q]=genlouvain(B,limit,verbose,randord,randmove,S0);

Thank you for the massive work. This suite is definitely superior to any other Louven algorithm I could find online, and very advanced for my skills. I am learning a lot about (the right way to program in) Matlab thanks to you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.