Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non deterministic result for same input #4

Open
zeslava opened this issue Jul 24, 2019 · 0 comments
Open

Non deterministic result for same input #4

zeslava opened this issue Jul 24, 2019 · 0 comments

Comments

@zeslava
Copy link

zeslava commented Jul 24, 2019

In example below order of ranks is depends on order of internal map(map of edges).
But for same input i expect deterministic output.
How do i reach this?

package main

import (
	"fmt"

	"github.com/alixaxel/pagerank"
)

const (
	damping   = 0.85
	tolerance = 0.0001
)

type Rank struct {
	idx   int
	score float64
}

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

	g.Link(0, 1, 0.33333)
	g.Link(1, 2, 0.33333)
	g.Link(2, 0, 0.33333)

	var ranks []int
	g.Rank(damping, tolerance, func(sentenceIndex uint32, rank float64) {
		ranks = append(ranks, int(sentenceIndex))
	})

	var ranks2 []int
	g.Rank(damping, tolerance, func(sentenceIndex uint32, rank float64) {
		ranks2 = append(ranks2, int(sentenceIndex))
	})

	fmt.Printf("%v\n", eq(ranks, ranks2)) // ! sometimes false !
}

func eq(l, r []int) bool {
	if len(l) != len(r) {
		return false
	}

	for i := range l {
		if l[i] != r[i] {
			return false
		}
	}

	return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant