Socket
Book a DemoInstallSign in
Socket

markov-clustering

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markov-clustering

Markov clustering algorithm implementation

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

What is this?

This is a simple Markov graph cluster algorithm implementation. For more information about the algorithm, see http://micans.org/mcl/.

Installation

npm install markov-clustering

Usage

The main entry point is the cluster function. It takes two arguments, an adjacency matrix graph representation and an optional options parameter.

Here's an example options object with default values:

const options = {
  expandFactor: 2,
  inflateFactor: 2,
  maxLoops: 10,
  multFactor: 1;
}

Example

The undirected graph below is used in this example.

Before clustering

Create an adjacency matrix representation of your graph, this will be the input for the clustering algorithm.

Here's the adjacency matrix for the graph above:

[[0, 1, 1, 0, 0, 0],
 [1, 0, 1, 0, 0, 0],
 [1, 1, 0, 1, 0, 0],
 [0, 0, 1, 0, 1, 1],
 [0, 0, 0, 1, 0, 1],
 [0, 0, 0, 1, 1, 0]]

The following snippet clusters the adjacency matrix:

const mc = require('markov-clustering');
const math = require('mathjs');

const A = math.matrix([[0, 1, 1, 0, 0, 0],
                       [1, 0, 1, 0, 0, 0],
                       [1, 1, 0, 1, 0, 0],
                       [0, 0, 1, 0, 1, 1],
                       [0, 0, 0, 1, 0, 1],
                       [0, 0, 0, 1, 1, 0]]);
console.log(mc.cluster(A));
$ node snippet.js
[ [ 0, 1, 2 ], [ 3, 4, 5 ] ]

After clustering

Tests

Some basic tests are included:

npm run test

Dependencies

The implementation relies on http://mathjs.org/ for matrix implementation.

Credits

The implementation is largely based on Python MCL https://github.com/koteth/python_mcl.

License

MIT

FAQs

Package last updated on 11 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts