public VectorAndPrefsWritable(Vector vector, List<Long> userIDs, List<Float> values) { set(vector, userIDs, values); }
public VectorAndPrefsWritable(Vector vector, List<Long> userIDs, List<Float> values) { set(vector, userIDs, values); }
public VectorAndPrefsWritable(Vector vector, List<Long> userIDs, List<Float> values) { set(vector, userIDs, values); }
@Override protected void reduce(VarLongWritable itemID, Iterable<VarLongWritable> values, Context ctx) throws IOException, InterruptedException { int itemIDIndex = TasteHadoopUtils.idToIndex(itemID.get()); Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 1); /* artificial NaN summand to exclude this item from the recommendations for all users specified in userIDs */ vector.set(itemIDIndex, Double.NaN); List<Long> userIDs = Lists.newArrayList(); List<Float> prefValues = Lists.newArrayList(); for (VarLongWritable userID : values) { userIDs.add(userID.get()); prefValues.add(1.0f); } itemIDIndexWritable.set(itemIDIndex); vectorAndPrefs.set(vector, userIDs, prefValues); ctx.write(itemIDIndexWritable, vectorAndPrefs); } }
@Override protected void reduce(VarIntWritable key, Iterable<VectorOrPrefWritable> values, Context context) throws IOException, InterruptedException { List<Long> userIDs = Lists.newArrayList(); List<Float> prefValues = Lists.newArrayList(); Vector similarityMatrixColumn = null; for (VectorOrPrefWritable value : values) { if (value.getVector() == null) { // Then this is a user-pref value userIDs.add(value.getUserID()); prefValues.add(value.getValue()); } else { // Then this is the column vector if (similarityMatrixColumn != null) { throw new IllegalStateException("Found two similarity-matrix columns for item index " + key.get()); } similarityMatrixColumn = value.getVector(); } } if (similarityMatrixColumn == null) { return; } vectorAndPrefs.set(similarityMatrixColumn, userIDs, prefValues); context.write(key, vectorAndPrefs); }
@Override protected void reduce(VarIntWritable key, Iterable<VectorOrPrefWritable> values, Context context) throws IOException, InterruptedException { List<Long> userIDs = new ArrayList<>(); List<Float> prefValues = new ArrayList<>(); Vector similarityMatrixColumn = null; for (VectorOrPrefWritable value : values) { if (value.getVector() == null) { // Then this is a user-pref value userIDs.add(value.getUserID()); prefValues.add(value.getValue()); } else { // Then this is the column vector if (similarityMatrixColumn != null) { throw new IllegalStateException("Found two similarity-matrix columns for item index " + key.get()); } similarityMatrixColumn = value.getVector(); } } if (similarityMatrixColumn == null) { return; } vectorAndPrefs.set(similarityMatrixColumn, userIDs, prefValues); context.write(key, vectorAndPrefs); }
@Override protected void reduce(VarLongWritable itemID, Iterable<VarLongWritable> values, Context ctx) throws IOException, InterruptedException { int itemIDIndex = TasteHadoopUtils.idToIndex(itemID.get()); Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 1); /* artificial NaN summand to exclude this item from the recommendations for all users specified in userIDs */ vector.set(itemIDIndex, Double.NaN); List<Long> userIDs = Lists.newArrayList(); List<Float> prefValues = Lists.newArrayList(); for (VarLongWritable userID : values) { userIDs.add(userID.get()); prefValues.add(1.0f); } itemIDIndexWritable.set(itemIDIndex); vectorAndPrefs.set(vector, userIDs, prefValues); ctx.write(itemIDIndexWritable, vectorAndPrefs); } }
@Override protected void reduce(VarLongWritable itemID, Iterable<VarLongWritable> values, Context ctx) throws IOException, InterruptedException { int itemIDIndex = TasteHadoopUtils.idToIndex(itemID.get()); Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 1); /* artificial NaN summand to exclude this item from the recommendations for all users specified in userIDs */ vector.set(itemIDIndex, Double.NaN); List<Long> userIDs = new ArrayList<>(); List<Float> prefValues = new ArrayList<>(); for (VarLongWritable userID : values) { userIDs.add(userID.get()); prefValues.add(1.0f); } itemIDIndexWritable.set(itemIDIndex); vectorAndPrefs.set(vector, userIDs, prefValues); ctx.write(itemIDIndexWritable, vectorAndPrefs); } }
@Override protected void reduce(VarIntWritable key, Iterable<VectorOrPrefWritable> values, Context context) throws IOException, InterruptedException { List<Long> userIDs = Lists.newArrayList(); List<Float> prefValues = Lists.newArrayList(); Vector similarityMatrixColumn = null; for (VectorOrPrefWritable value : values) { if (value.getVector() == null) { // Then this is a user-pref value userIDs.add(value.getUserID()); prefValues.add(value.getValue()); } else { // Then this is the column vector if (similarityMatrixColumn != null) { throw new IllegalStateException("Found two similarity-matrix columns for item index " + key.get()); } similarityMatrixColumn = value.getVector(); } } if (similarityMatrixColumn == null) { return; } vectorAndPrefs.set(similarityMatrixColumn, userIDs, prefValues); context.write(key, vectorAndPrefs); }