List of usage examples for org.apache.mahout.cf.taste.impl.common FastByIDMap keySetIterator
public LongPrimitiveIterator keySetIterator()
From source file:de.tuberlin.dima.recsys.ssnmm.interactioncut.InteractionCutDataModelBuilder.java
License:Apache License
@Override public DataModel buildDataModel(FastByIDMap<PreferenceArray> trainingData) { FastByIDMap<PreferenceArray> sampledTrainingData = new FastByIDMap<PreferenceArray>(); LongPrimitiveIterator userIDs = trainingData.keySetIterator(); while (userIDs.hasNext()) { long userID = userIDs.nextLong(); PreferenceArray prefs = trainingData.get(userID); if (prefs.length() > maxPrefsPerUser) { Preference[] sampledPrefs = Iterators.toArray( new FixedSizeSamplingIterator<Preference>(maxPrefsPerUser, prefs.iterator()), Preference.class); sampledTrainingData.put(userID, new GenericUserPreferenceArray(Arrays.asList(sampledPrefs))); } else {//from www. j ava2 s . c om sampledTrainingData.put(userID, prefs); } } return new GenericDataModel(sampledTrainingData); }