@Override public void put(long item, double score) { if (entries == null) { entries = new Long2DoubleOpenHashMap(); } entries.put(item, score); }
@Test @Ignore("removed smoothing") public void testSmoothingDetailedOldVector() { MeanVarianceNormalizer urvn = null; // new MeanVarianceNormalizer.Builder(dao, 3.0).get(); InvertibleFunction<Long2DoubleMap,Long2DoubleMap> trans = urvn.makeTransformation(userRatings); Long2DoubleOpenHashMap nUR = new Long2DoubleOpenHashMap(userRatings); final double mean = 2.0; final double stdev = Math.sqrt(7.0 / 3.0); trans.apply(nUR); //Test apply Assert.assertEquals((0.0 - mean) / stdev, nUR.get(0L), MIN_DOUBLE_PRECISION); Assert.assertEquals((2.0 - mean) / stdev, nUR.get(1L), MIN_DOUBLE_PRECISION); Assert.assertEquals((4.0 - mean) / stdev, nUR.get(2L), MIN_DOUBLE_PRECISION); trans.unapply(nUR); //Test unapply Assert.assertEquals(0.0, nUR.get(0L), MIN_DOUBLE_PRECISION); Assert.assertEquals(2.0, nUR.get(1L), MIN_DOUBLE_PRECISION); Assert.assertEquals(4.0, nUR.get(2L), MIN_DOUBLE_PRECISION); } }
/** * Constructor. * * @param inner Inner query * @param size Initial size of map */ public CachedDistanceQuery(DistanceQuery<V> inner, int size) { this.inner = inner; this.cache = new Long2DoubleOpenHashMap(size); this.cache.defaultReturnValue(Double.NaN); }
@Override protected Long2DoubleMap makeVector(List<Entity> entities) { Long2DoubleOpenHashMap counts = new Long2DoubleOpenHashMap(); counts.defaultReturnValue(0); for (Entity e: entities) { long item = e.getLong(CommonAttributes.ITEM_ID); int count = e.getInteger(CommonAttributes.COUNT); counts.addTo(item, count); } return counts; } }
@Override public void readFieldsForPartition(DataInput in, int partitionId) throws IOException { int size = in.readInt(); Long2DoubleOpenHashMap partitionMap = new Long2DoubleOpenHashMap(size); while (size-- > 0) { long vertexId = in.readLong(); double message = in.readDouble(); partitionMap.put(vertexId, message); } synchronized (map) { map.put(partitionId, partitionMap); } } }
public Favoring(IPath previous) { // create one just from previous path, no mob avoidances favorings = new Long2DoubleOpenHashMap(); favorings.defaultReturnValue(1.0D); double coeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); if (coeff != 1D && previous != null) { previous.positions().forEach(pos -> favorings.put(BetterBlockPos.longHash(pos), coeff)); } }
@Override public void compute(String label, String type, int iterations) { RelationshipType relationshipType = RelationshipType.withName(type); labelMap = new Long2DoubleOpenHashMap(); boolean done = false; int iteration = 0; while (nodes.hasNext()) { Node node = nodes.next(); labelMap.put(node.getId(), node.getId()); long y = relationship.getEndNode().getId(); if (x == y) { continue; } if (labelMap.get(x) > labelMap.get(y)){ labelMap.put(x, labelMap.get(y)); done = false; } else if (labelMap.get(x) < labelMap.get(y)) { labelMap.put(y, labelMap.get(x)); done = false;
try { System.err.print("Trying size " + i); tempMap = new Long2DoubleOpenHashMap((int)(i)); System.err.println(" and it was successfull"); break; validMap = new Long2DoubleOpenHashMap(); else validMap = tempMap; validMap.put(hash[0], percent); validMap.trim();
public void applySpherical(Long2DoubleOpenHashMap map) { for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { if (x * x + y * y + z * z <= radius * radius) { long hash = BetterBlockPos.longHash(centerX + x, centerY + y, centerZ + z); map.put(hash, map.get(hash) * coefficient); } } } } } }
/** * Get the whole model * * @return the whole model */ public Long2DoubleOpenHashMap[] getModel() { synchronized (this) { if (model == null) { model = new Long2DoubleOpenHashMap[row]; for (Map.Entry<Integer, Map<Integer, Long2DoubleOpenHashMap>> rowEntry : tempModel .entrySet()) { int size = 0; for (Map.Entry<Integer, Long2DoubleOpenHashMap> partEntry : rowEntry.getValue() .entrySet()) { size += partEntry.getValue().size(); } model[rowEntry.getKey()] = new Long2DoubleOpenHashMap(size); for (Map.Entry<Integer, Long2DoubleOpenHashMap> partEntry : rowEntry.getValue() .entrySet()) { model[rowEntry.getKey()].putAll(partEntry.getValue()); } } } return model; } } }
/** * Creates a new hash map using the elements of two parallel arrays. * * @param k * the array of keys of the new hash map. * @param v * the array of corresponding values in the new hash map. * @param f * the load factor. * @throws IllegalArgumentException * if {@code k} and {@code v} have different lengths. */ public Long2DoubleOpenHashMap(final long[] k, final double[] v, final float f) { this(k.length, f); if (k.length != v.length) throw new IllegalArgumentException( "The key array and the value array have different lengths (" + k.length + " and " + v.length + ")"); for (int i = 0; i < k.length; i++) this.put(k[i], v[i]); } /**
@Override public void addPartitionMessages(int partitionId, VertexIdMessages<LongWritable, DoubleWritable> messages) { LongWritable reusableVertexId = new LongWritable(); DoubleWritable reusableMessage = new DoubleWritable(); DoubleWritable reusableCurrentMessage = new DoubleWritable(); Long2DoubleOpenHashMap partitionMap = map.get(partitionId); synchronized (partitionMap) { VertexIdMessageIterator<LongWritable, DoubleWritable> iterator = messages.getVertexIdMessageIterator(); while (iterator.hasNext()) { iterator.next(); long vertexId = iterator.getCurrentVertexId().get(); double message = iterator.getCurrentMessage().get(); if (partitionMap.containsKey(vertexId)) { reusableVertexId.set(vertexId); reusableMessage.set(message); reusableCurrentMessage.set(partitionMap.get(vertexId)); messageCombiner.combine(reusableVertexId, reusableCurrentMessage, reusableMessage); message = reusableCurrentMessage.get(); } partitionMap.put(vertexId, message); } } }
@Override public void setEdgeValue(LongWritable targetVertexId, DoubleWritable edgeValue) { if (edgeMap.containsKey(targetVertexId.get())) { edgeMap.put(targetVertexId.get(), edgeValue.get()); } }
@Override public DoubleWritable getEdgeValue(LongWritable targetVertexId) { if (!edgeMap.containsKey(targetVertexId.get())) { return null; } if (representativeEdgeValue == null) { representativeEdgeValue = new DoubleWritable(); } representativeEdgeValue.set(edgeMap.get(targetVertexId.get())); return representativeEdgeValue; }
public double calculate(long hash) { return favorings.get(hash); } }
@Override public void clear() { Long2DoubleOpenHashMap.this.clear(); } /** {@inheritDoc} */
@Override public void putAll(Map<? extends Long, ? extends Double> m) { if (f <= .5) ensureCapacity(m.size()); // The resulting map will be sized for m.size() elements else tryCapacity(size() + m.size()); // The resulting map will be tentatively sized for size() + m.size() // elements super.putAll(m); }
@Override public void write(DataOutput out) throws IOException { out.writeInt(edgeMap.size()); for (Long2DoubleMap.Entry entry : edgeMap.long2DoubleEntrySet()) { out.writeLong(entry.getLongKey()); out.writeDouble(entry.getDoubleValue()); } }
@Override public Iterable<LongWritable> getPartitionDestinationVertices( int partitionId) { Long2DoubleOpenHashMap partitionMap = map.get(partitionId); List<LongWritable> vertices = Lists.newArrayListWithCapacity(partitionMap.size()); LongIterator iterator = partitionMap.keySet().iterator(); while (iterator.hasNext()) { vertices.add(new LongWritable(iterator.nextLong())); } return vertices; }
@Override public int size() { return edgeMap.size(); }