helpers

package
Version: v0.0.0-...-0102553 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Calculator

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

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

func NewCalculator

func NewCalculator(cfg Config) (*Calculator, error)

NewCalculator returns a new Calculator instance using the provided config options.

func (*Calculator) AddEdge

func (c *Calculator) 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 (*Calculator) AddVertex

func (c *Calculator) AddVertex(id string)

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

func (*Calculator) Close

func (c *Calculator) Close() error

Close releases any resources allocated by this PageRank calculator instance.

func (*Calculator) Executor

func (c *Calculator) Executor() *bspgraph.Executor

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

func (*Calculator) Graph

func (c *Calculator) Graph() *bspgraph.Graph

Graph returns the underlying bspgraph.Graph instance.

func (*Calculator) Scores

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

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

func (*Calculator) SetExecutorFactory

func (c *Calculator) SetExecutorFactory(factory bspgraph.ExecutorFactory)

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

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 calculator 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 returns the type of this message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL