@Override protected void map(VarIntWritable key, VectorAndPrefsWritable vectorAndPrefsWritable, Context context) throws IOException, InterruptedException { Vector similarityMatrixColumn = vectorAndPrefsWritable.getVector(); List<Long> userIDs = vectorAndPrefsWritable.getUserIDs(); List<Float> prefValues = vectorAndPrefsWritable.getValues(); for (int i = 0; i < userIDs.size(); i++) { long userID = userIDs.get(i); float prefValue = prefValues.get(i); if (!Float.isNaN(prefValue)) { prefAndSimilarityColumn.set(prefValue, similarityMatrixColumn); userIDWritable.set(userID); context.write(userIDWritable, prefAndSimilarityColumn); } } }
@Override protected void map(VarIntWritable key, VectorAndPrefsWritable vectorAndPrefsWritable, Context context) throws IOException, InterruptedException { Vector similarityMatrixColumn = vectorAndPrefsWritable.getVector(); List<Long> userIDs = vectorAndPrefsWritable.getUserIDs(); List<Float> prefValues = vectorAndPrefsWritable.getValues(); for (int i = 0; i < userIDs.size(); i++) { long userID = userIDs.get(i); float prefValue = prefValues.get(i); if (!Float.isNaN(prefValue)) { prefAndSimilarityColumn.set(prefValue, similarityMatrixColumn); userIDWritable.set(userID); context.write(userIDWritable, prefAndSimilarityColumn); } } }
@Override protected void map(VarIntWritable key, VectorAndPrefsWritable vectorAndPrefsWritable, Context context) throws IOException, InterruptedException { Vector similarityMatrixColumn = vectorAndPrefsWritable.getVector(); List<Long> userIDs = vectorAndPrefsWritable.getUserIDs(); List<Float> prefValues = vectorAndPrefsWritable.getValues(); for (int i = 0; i < userIDs.size(); i++) { long userID = userIDs.get(i); float prefValue = prefValues.get(i); if (!Float.isNaN(prefValue)) { prefAndSimilarityColumn.set(prefValue, similarityMatrixColumn); userIDWritable.set(userID); context.write(userIDWritable, prefAndSimilarityColumn); } } }
public void map(IntWritable key, VectorAndPrefsWritable vectorAndPrefsWritable, Context context) throws IOException, InterruptedException { Vector cooccurrenceColumn = vectorAndPrefsWritable.getVector(); List<Long> userIDs = vectorAndPrefsWritable.getUserIDs(); List<Float> prefValues = vectorAndPrefsWritable.getValues(); for (int i = 0; i < userIDs.size(); i++) { long userID = userIDs.get(i); float prefValue = prefValues.get(i); Vector partialProduct = cooccurrenceColumn.times(prefValue); context.write(new VarLongWritable(userID), new VectorWritable(partialProduct)); } } }
@Override public boolean matches(Object argument) { if (argument instanceof VectorAndPrefsWritable) { VectorAndPrefsWritable vectorAndPrefs = (VectorAndPrefsWritable) argument; if (!vectorAndPrefs.getUserIDs().equals(userIDs)) { return false; } if (!vectorAndPrefs.getValues().equals(prefValues)) { return false; } return MathHelper.consistsOf(vectorAndPrefs.getVector(), elements); } return false; }
@Override public boolean matches(Object argument) { if (argument instanceof VectorAndPrefsWritable) { VectorAndPrefsWritable vectorAndPrefs = (VectorAndPrefsWritable) argument; Vector vector = vectorAndPrefs.getVector(); if (vector.getNumNondefaultElements() != 1) { return false; } if (!Double.isNaN(vector.get(TasteHadoopUtils.idToIndex(itemID)))) { return false; } if (userIDs.length != vectorAndPrefs.getUserIDs().size()) { return false; } for (long userID : userIDs) { if (!vectorAndPrefs.getUserIDs().contains(userID)) { return false; } } return true; } return false; }