ranker

package
v0.0.0-...-e97be17 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Implemets Google famous and first PageRank algorithm https://en.wikipedia.org/wiki/PageRank

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DampingFactor is the probability that a random surfer will click on
	// one of the outgoing links on the page they are currently visiting
	// instead of visiting (teleporting to) a random page in the graph.
	//
	// If not specified, a default value of 0.85 will be used instead.
	DampingFactor float64

	// At each step of the iterative PageRank algorithm, an accumulator
	// tracks the sum of absolute differences (SAD) of the PageRank
	// scores for each vertex in the graph.
	//
	// The algorithm will keep executing until the aggregated SAD for all
	// vertices becomes less than MinSADForConvergence.
	//
	// If not specified, a default value of 0.001 will be used instead.
	MinSADForConvergence float64

	// The number of workers to spin up for computing PageRank scores. If
	// not specified, a default value of 1 will be used instead.
	ComputeWorkers int
}

Config encapsulates the required parameters for creating a new PageRank ranker instance.

type IncomingScoreMessage

type IncomingScoreMessage struct {
	Score float64
}

IncomingScoreMessage is used for distributing PageRank scores to neighbors.

func (IncomingScoreMessage) Type

func (pr IncomingScoreMessage) Type() string

type Ranker

type Ranker struct {
	// contains filtered or unexported fields
}

Ranker executes the iterative version of the PageRank algorithm on a graph until the desired level of convergence is reached.

func NewRanker

func NewRanker(cfg Config) (*Ranker, error)

NewRanker returns a new Ranker instance using the provided config options.

func (*Ranker) AddEdge

func (c *Ranker) AddEdge(src, dst string) error

AddEdge inserts a directed edge from src to dst. If both src and dst refer to the same vertex then this is a no-op.

func (*Ranker) AddVertex

func (c *Ranker) AddVertex(id string)

AddVertex inserts a new vertex to the graph with the given id.

func (*Ranker) Close

func (c *Ranker) Close() error

Close releases any resources allocated by this PageRank ranker instance.

func (*Ranker) Executor

func (c *Ranker) Executor() *bsp.Executor[float64, any]

Executor creates and return a bspgraph.Executor for running the PageRank algorithm once the graph layout has been properly set up.

func (*Ranker) Graph

func (c *Ranker) Graph() *bsp.Graph[float64, any]

Graph returns the underlying bspgraph.Graph instance.

func (*Ranker) Scores

func (c *Ranker) Scores(visitFn func(id string, score float64) error) error

Scores invokes the provided visitor function for each vertex in the graph.

func (*Ranker) SetExecutorFactory

func (c *Ranker) SetExecutorFactory(factory bsp.ExecutorFactory[float64, any])

SetExecutorFactory configures the ranker to use the a custom executor factory when the Executor method is invoked.

Jump to

Keyboard shortcuts

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