pagerank

package module
Version: v0.0.0-...-900657b Latest Latest

Go to latest
Published: Jan 5, 2020 License: MIT

pagerank

Weighted PageRank implementation in Go

Usage

``````package main

import (
"fmt"

"github.com/alixaxel/pagerank"
)

func main() {
graph := pagerank.NewGraph()

graph.Rank(0.85, 0.000001, func(node uint32, rank float64) {
fmt.Println("Node", node, "has a rank of", rank)
})
}
``````

Output

``````Node 1 has a rank of 0.34983779905464363
Node 2 has a rank of 0.1688733284604475
Node 3 has a rank of 0.3295121849483849
Node 4 has a rank of 0.15177668753652385
``````

Install

``````go get github.com/alixaxel/pagerank
``````

MIT

Documentation ¶

Overview ¶

Package pagerank implements the *weighted* PageRank algorithm.

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Graph ¶

```type Graph struct {
// contains filtered or unexported fields
}```

Graph holds node and edge data.

func NewGraph ¶

`func NewGraph() *Graph`

NewGraph initializes and returns a new graph.

`func (self *Graph) Link(source, target uint32, weight float64)`

Link creates a weighted edge between a source-target node pair. If the edge already exists, the weight is incremented.

func (*Graph) Rank ¶

`func (self *Graph) Rank(α, ε float64, callback func(id uint32, rank float64))`

Rank computes the PageRank of every node in the directed graph. α (alpha) is the damping factor, usually set to 0.85. ε (epsilon) is the convergence criteria, usually set to a tiny value.

This method will run as many iterations as needed, until the graph converges.

func (*Graph) Reset ¶

`func (self *Graph) Reset()`

Reset clears all the current graph data.