pagerank

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

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2020 License: MIT Imports: 1 Imported by: 3

README

pagerank GoDoc GoCover Go Report Card

Weighted PageRank implementation in Go

Usage

package main

import (
	"fmt"

	"github.com/alixaxel/pagerank"
)

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

	graph.Link(1, 2, 1.0)
	graph.Link(1, 3, 2.0)
	graph.Link(2, 3, 3.0)
	graph.Link(2, 4, 4.0)
	graph.Link(3, 1, 5.0)

	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

License

MIT

Documentation

Overview

Package pagerank implements the *weighted* PageRank algorithm.

Index

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.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL