pagerank

package module
v0.0.0-...-830548a Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2021 License: MIT Imports: 3 Imported by: 16

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.NewGraph64()

	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 uint64, 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.

Package pagerank implements the *weighted* PageRank algorithm.

Index

Constants

This section is empty.

Variables

View Source
var (
	// NumCPU is the number of cpus
	NumCPU = runtime.NumCPU()
)

Functions

This section is empty.

Types

type Graph32

type Graph32 struct {
	Verbose bool
	// contains filtered or unexported fields
}

Graph32 holds node and edge data.

func NewGraph32

func NewGraph32(size ...int) *Graph32

NewGraph32 initializes and returns a new graph.

func (g *Graph32) Link(source, target uint64, weight float32)

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

func (*Graph32) Rank

func (g *Graph32) Rank(α, ε float32, callback func(id uint64, rank float32))

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 (*Graph32) Reset

func (g *Graph32) Reset(size ...int)

Reset clears all the current graph data.

type Graph64

type Graph64 struct {
	Verbose bool
	// contains filtered or unexported fields
}

Graph64 holds node and edge data.

func NewGraph64

func NewGraph64(size ...int) *Graph64

NewGraph64 initializes and returns a new graph.

func (g *Graph64) Link(source, target uint64, weight float64)

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

func (*Graph64) Rank

func (g *Graph64) Rank(α, ε float64, callback func(id uint64, 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 (*Graph64) Reset

func (g *Graph64) Reset(size ...int)

Reset clears all the current graph data.

type Node32

type Node32 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Node32 is a node in a graph

type Node64

type Node64 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Node64 is a node in a graph

Jump to

Keyboard shortcuts

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