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 }
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 }
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 }