Esempio n. 1
0
File: tops.go Progetto: Comdex/tasty
func capper(v float64, m model.DataModel) float64 {
	if v > m.MaxPreferenceValue() {
		v = m.MaxPreferenceValue()
	} else if v < m.MinPreferenceValue() {
		v = m.MinPreferenceValue()
	}
	return v
}
Esempio n. 2
0
func (this *GenericItemBasedRecommender) getAllOtherItemIds(preferredItemIds []uint64, dataModel model.DataModel) ([]uint64, error) {
	possibleIdSet := utils.IdSet{}
	for _, itemId := range preferredItemIds {
		itemPrefs, err := dataModel.GetItemPreferences(itemId)
		if err != nil {
			continue
		}
		for _, uid := range itemPrefs.Ids() {
			up, err := dataModel.GetUserPreferences(uid)
			if err != nil {
				continue
			}
			possibleIdSet.AddArray(up.Ids())
		}
	}
	possibleIdSet.RemoveArray(preferredItemIds)
	return possibleIdSet.ToArray(), nil
}
Esempio n. 3
0
func SplitTrainingAndTest(m model.DataModel, trainingPercentage, evaluationPercentage float32) (model.PreferenceArrayMap, model.PreferenceArrayMap) {
	trainings := model.NewUserPreferenceArrayMap()
	tests := model.NewUserPreferenceArrayMap()
	for _, uid := range m.UserIds() {
		if rand.Float32() < evaluationPercentage {
			prefs, err := m.GetUserPreferences(uid)
			if err != nil {
				continue
			}
			for _, p := range prefs.Raw() {
				if rand.Float32() < trainingPercentage {
					trainings.Set(p)
				} else {
					tests.Set(p)
				}
			}
		}
	}
	return trainings, tests
}