@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 public boolean matches(Object argument) { if (argument instanceof VectorOrPrefWritable) { VectorOrPrefWritable pref = (VectorOrPrefWritable) argument; return pref.getUserID() == userID && Float.isNaN(pref.getValue()); } return false; }
@Override public boolean matches(Object argument) { if (argument instanceof VectorOrPrefWritable) { VectorOrPrefWritable pref = (VectorOrPrefWritable) argument; return pref.getUserID() == userID && pref.getValue() == prefValue; } return false; }
@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); }