Code Monkey home page Code Monkey logo

jlouvain's Introduction

jLouvain

Description

Formally, a community detection aims to partition a graph’s vertices in subsets, such that there are many edges connecting between vertices of the same sub-set compared to vertices of different sub-sets; in essence, a community has many more ties between each constituent part than with outsiders. There are numerous algorithms present in the literature for solving this problem, a complete survey can be found in [1].

One of the popular community detection algorithms is presented in [2]. This algorithm separates the network in communities by optimizing greedily a modularity score after trying various grouping operations on the network. By using this simple greedy approach the algorithm is computationally very efficient.

[1] Fortunato, Santo. "Community detection in graphs." Physics Reports 486, no. 3-5 (2010).

[2] V.D. Blondel, J.-L. Guillaume, R. Lambiotte, E. Lefebvre. "Fast unfolding of communities in large networks." J. Stat. Mech., 2008: 1008.

Usage

1. Import the script.

<script type="text/javascript" src="jLouvain.js"></script>

2. Sample Data Format

Node Data

let node_data = ['id1', 'id2', 'id3']; // any type of string can be used as id

Edge Data

let edge_data = [
	{ source: 'id1', target: 'id2', weight: 10.0 },
	{ source: 'id2', target: 'id3', weight: 20.0 },
	{ source: 'id3', target: 'id1', weight: 30.0 }
];

(Optional) Partition Data

let init_part = { id1: 0, id2: 0, id3: 1 };
// Object with ids of nodes as properties and community number assigned as value.

3. Run the algorithm

  1. Run the Algorithm on your node and edge set by chaining the nodes and edges methods, optionally you can provide an intermediary community partition assignement with the partition_init method. [ Order of chaining is important ]
let community = jLouvain()
	.nodes(node_data)
	.edges(edge_data)
	.partition_init(init_part);
let result = community();

Example

See example.html, use the console to view the raw input data and raw output.

Initial input graph for community detection.

After Community Detection

We can see the partitioned graph vertices with the help of color coding.

jlouvain's People

Contributors

2xl avatar avermeij avatar upphiminn 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jlouvain's Issues

Sensitivity of community detection

Is it possible to pass an argument (or otherwise alter the code) such that a user can control the sensitivity of community detection (i.e. more sensitive would result in a larger number of communities and less sensitive would result in a smaller number)?

I see in the original paper the following: "However, our algorithm provides a decomposition of the network into communities for different levels of organization..... This result suggests that the intermediate solutions found by our algorithm may also be meaningful and that the uncovered hierarchical structure may allow the end-user to zoom in the network and to observe its structure with the desired resolution."

I am not clear though how I can obtain that flexibility / sensitivity. Thanks.

crashes whenever a node is called 'constructor'

jLouvain crashes whenever a node is called 'constructor', apparently it overrides some object's native constructor property.

Similar crash may occur whenever other javascript resssserved words are used as node names.

Prefixing nodes names (e.g. like in d3js' .data) should solve this problem.

node.js compatibility

Hi,

Would you consider making this library compatible with node.js?

Happy to send a pull request if you are interested.

Unexpected behavior because of mutable data

Description

Since jLouvain is not using an immutable datastructure it is possible that the data provided during initialization (nodes and edges) will be different when calculating the community.

How to reproduce

This behavior can be seen in the provided example/example.html
The prepared community on line 298 var community = jLouvain().nodes(node_data).edges(edge_data); will be calculated in the on-click handler defined in line 367. This will happen AFTER d3 used the data to display the graph and AFTER d3 modified edge_data

Moving line 364 var community_assignment_result = community(); up to line 299 will result in different communities:
g1
g2

Reason

The library d3 is changing the value inside edge_data from {source : 1 ..} to {source: {key: "1", value: 1, index: 1 ...}}. Therefore using edge.source will result in unexpected behavior. Especially using partition[edge.source] will return undefined.

Community sparsity data?

Is there any data coming in that can tell about the sparsity of the resulting graph — e.g. if there are many disconnected communities or if one community has disproportionally more nodes than the others? I remember in the original algorithm there was this number 0.4 that if it was higher than the communities detected were distinct enough, and if it was less, then not so. Anything similar can be derived from this algorithm and if not, where would I start looking in the code itself?

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.