@Test public void testAdjustOrPutValue() { OpenIntLongHashMap map = new OpenIntLongHashMap(); map.put((int) 11, (long) 22); map.put((int) 12, (long) 23); map.put((int) 13, (long) 24); map.put((int) 14, (long) 25); map.adjustOrPutValue((int)11, (long)1, (long)3); assertEquals(25, map.get((int)11) ); map.adjustOrPutValue((int)15, (long)1, (long)3); assertEquals(1, map.get((int)15) ); }
@Test public void testClear() { OpenIntLongHashMap map = new OpenIntLongHashMap(); map.put((int) 11, (long) 22); assertEquals(1, map.size()); map.clear(); assertEquals(0, map.size()); assertEquals(0, map.get((int) 11), 0.0000001); }
@Override protected void reduce(WritableComparable<?> key, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException { Iterator<VectorWritable> it = values.iterator(); if (!it.hasNext()) { return; } Vector value = it.next().get(); Vector vector = value.clone(); if (maxDf != Long.MAX_VALUE || minDf > -1) { for (Vector.Element e : value.nonZeroes()) { if (!dictionary.containsKey(e.index())) { vector.setQuick(e.index(), 0.0); continue; } long df = dictionary.get(e.index()); if (df > maxDf || df < minDf) { vector.setQuick(e.index(), 0.0); } } } VectorWritable vectorWritable = new VectorWritable(vector); context.write(key, vectorWritable); }
@Override protected void reduce(WritableComparable<?> key, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException { Iterator<VectorWritable> it = values.iterator(); if (!it.hasNext()) { return; } Vector value = it.next().get(); Vector vector = value.clone(); if (maxDf != Long.MAX_VALUE || minDf > -1) { for (Vector.Element e : value.nonZeroes()) { if (!dictionary.containsKey(e.index())) { vector.setQuick(e.index(), 0.0); continue; } long df = dictionary.get(e.index()); if (df > maxDf || df < minDf) { vector.setQuick(e.index(), 0.0); } } } VectorWritable vectorWritable = new VectorWritable(vector); context.write(key, vectorWritable); }
@Override protected void reduce(WritableComparable<?> key, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException { Iterator<VectorWritable> it = values.iterator(); if (!it.hasNext()) { return; } Vector value = it.next().get(); Vector vector = value.clone(); if (maxDf != Long.MAX_VALUE || minDf > -1) { for (Vector.Element e : value.nonZeroes()) { if (!dictionary.containsKey(e.index())) { vector.setQuick(e.index(), 0.0); continue; } long df = dictionary.get(e.index()); if (df > maxDf || df < minDf) { vector.setQuick(e.index(), 0.0); } } } VectorWritable vectorWritable = new VectorWritable(vector); context.write(key, vectorWritable); }
continue; long df = dictionary.get(e.index()); if (maxDf > -1 && (100.0 * df) / vectorCount > maxDf) { continue;
continue; long df = dictionary.get(e.index()); if (maxDf > -1 && (100.0 * df) / vectorCount > maxDf) { continue;
@Override protected void map(IntWritable itemIDIndexWritable, VectorWritable similarityVector, Context ctx) throws IOException, InterruptedException { int itemIDIndex = itemIDIndexWritable.get(); TopSimilarItemsQueue topKMostSimilarItems = new TopSimilarItemsQueue(maxSimilarItemsPerItem); for (Vector.Element element : similarityVector.get().nonZeroes()) { SimilarItem top = topKMostSimilarItems.top(); double candidateSimilarity = element.get(); if (candidateSimilarity > top.getSimilarity()) { top.set(indexItemIDMap.get(element.index()), candidateSimilarity); topKMostSimilarItems.updateTop(); } } long itemID = indexItemIDMap.get(itemIDIndex); for (SimilarItem similarItem : topKMostSimilarItems.getTopItems()) { long otherItemID = similarItem.getItemID(); if (itemID < otherItemID) { ctx.write(new EntityEntityWritable(itemID, otherItemID), new DoubleWritable(similarItem.getSimilarity())); } else { ctx.write(new EntityEntityWritable(otherItemID, itemID), new DoubleWritable(similarItem.getSimilarity())); } } } }
@Override protected void map(IntWritable itemIDIndexWritable, VectorWritable similarityVector, Context ctx) throws IOException, InterruptedException { int itemIDIndex = itemIDIndexWritable.get(); TopSimilarItemsQueue topKMostSimilarItems = new TopSimilarItemsQueue(maxSimilarItemsPerItem); for (Vector.Element element : similarityVector.get().nonZeroes()) { SimilarItem top = topKMostSimilarItems.top(); double candidateSimilarity = element.get(); if (candidateSimilarity > top.getSimilarity()) { top.set(indexItemIDMap.get(element.index()), candidateSimilarity); topKMostSimilarItems.updateTop(); } } long itemID = indexItemIDMap.get(itemIDIndex); for (SimilarItem similarItem : topKMostSimilarItems.getTopItems()) { long otherItemID = similarItem.getItemID(); if (itemID < otherItemID) { ctx.write(new EntityEntityWritable(itemID, otherItemID), new DoubleWritable(similarItem.getSimilarity())); } else { ctx.write(new EntityEntityWritable(otherItemID, itemID), new DoubleWritable(similarItem.getSimilarity())); } } } }
continue; long df = dictionary.get(e.index()); if (maxDf > -1 && (100.0 * df) / vectorCount > maxDf) { continue;
@Override protected void map(IntWritable itemIDIndexWritable, VectorWritable similarityVector, Context ctx) throws IOException, InterruptedException { int itemIDIndex = itemIDIndexWritable.get(); TopSimilarItemsQueue topKMostSimilarItems = new TopSimilarItemsQueue(maxSimilarItemsPerItem); for (Vector.Element element : similarityVector.get().nonZeroes()) { SimilarItem top = topKMostSimilarItems.top(); double candidateSimilarity = element.get(); if (candidateSimilarity > top.getSimilarity()) { top.set(indexItemIDMap.get(element.index()), candidateSimilarity); topKMostSimilarItems.updateTop(); } } long itemID = indexItemIDMap.get(itemIDIndex); for (SimilarItem similarItem : topKMostSimilarItems.getTopItems()) { long otherItemID = similarItem.getItemID(); if (itemID < otherItemID) { ctx.write(new EntityEntityWritable(itemID, otherItemID), new DoubleWritable(similarItem.getSimilarity())); } else { ctx.write(new EntityEntityWritable(otherItemID, itemID), new DoubleWritable(similarItem.getSimilarity())); } } } }
long itemID; if (indexItemIDMap != null && !indexItemIDMap.isEmpty()) { itemID = indexItemIDMap.get(index); } else { //we don't have any mappings, so just use the original itemID = index;
long itemID; if (indexItemIDMap != null && !indexItemIDMap.isEmpty()) { itemID = indexItemIDMap.get(index); } else { // we don't have any mappings, so just use the original itemID = index;
long itemID; if (indexItemIDMap != null && !indexItemIDMap.isEmpty()) { itemID = indexItemIDMap.get(index); } else { // we don't have any mappings, so just use the original itemID = index;