Exemplo n.º 1
0
/* n is size of list, person is data.UserId,
users is map of data.User and
simFunc is algo.SimFunc */
func TopMatches(prefpointer *data.PrefList, person int, simFunc algo.SimFunc) map[int]data.Similar {
	scores := data.NewSimList()

	prefs := *prefpointer
	for key, _ := range prefs {
		if key != person {
			if len(scores[person]) == 0 {
				scores[person] = make(map[int]data.Similar)
			}
			scores[person][key] = data.Similar{key, simFunc(&prefs, person, key)}
		}
	}

	return sortMapByValue(scores[person])
}
Exemplo n.º 2
0
func GetSimilar(prefpointer *data.PrefList, simFunc algo.SimFunc) data.SimList {
	transformPrefs(prefpointer)

	prefs := *prefpointer
	simlist := data.NewSimList()
	c := 0
	for item, _ := range prefs {
		c += 1
		if c%100 == 0 {
			fmt.Println("%d / %d", c, len(prefs))
		}
		if len(simlist[item]) == 0 {
			simlist[item] = make(map[int]data.Similar)
		}
		simlist[item] = sort.TopMatches(&prefs, item, simFunc)
	}
	return simlist
}