Coder Social home page Coder Social logo

ngraph.pagerank's Introduction

ngraph.pagerank Build Status

PageRank algorithm implementation in JavaScript. This module is part of ngraph family.

usage

Let's compute PageRank for a simple graph with two nodes, one edge:

var graph = require('ngraph.graph')();
graph.addLink(1, 2);

var pagerank = require('ngraph.pagerank');
var rank = pagerank(graph);

This code will compute PageRank for two nodes:

{
  "1": 0.350877,
  "2": 0.649123
}

configuring

The PageRank algorithm allows you to specify a probability at any step that a person will continue clicking outgoing links. This probability in some literature is called a dumping factor, and is recommended to be set between 0.80 and 0.90.

To configure this probability use the second, optional argument of the pagerank() function:

// by default this value is 0.85. Bump it to 0.9:
var internalJumpProbability = 0.90;
var rank = pagerank(graph, internalJumpProbability);

Current implementation uses approximate solution for eigenvector problem. To specify precision level use the last optional argument:

var internalJumpProbability = 0.85;
// by default it's set to 0.005, let's increase it:
var precision = 0.00001;
var rank = pagerank(graph, internalJumpProbability, precision);

precision will affect algorithm performance and serves as an exit criteria:

|r(t) - r(t - 1)| < precision

Here r(t) is eigenvector (or pagerank of a graph) at time step t.

performance

The focus of this module is to be very fast. I tried multiple approaches, including

So far approach with typed array gives the fastest results in v8/node.js 0.12: 43 ops/sec. asm.js version is the fastest when executed inside spider monkey (firefox) with 50 ops/sec. Unfortunately asm.js version gives terrible results in iojs 1.5 (around 20 ops/sec), and while performs at 47 ops/sec in node.js 0.12 the deviation is too big (around 7%) to call it stable. I'm frankly a little bit lost and not sure why asm.js gives such poor results in v8. So currently sticking with approach with typed arrays.

demo

A small demo is available here. It computes PageRank for a graph from Wikipedia and then renders it with force based layout.

install

With npm do:

npm install ngraph.pagerank

license

MIT

TODO:

Implement topic-specific rank?

ngraph.pagerank's People

Contributors

anvaka avatar

Watchers

James Cloos avatar  avatar

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.