public void weightMatrix() { Double2DoubleOpenHashMap ratingWeightMap = new Double2DoubleOpenHashMap(); for (double rating : ratingScale) { ratingWeightMap.putIfAbsent(rating, weight(rating)); } for (MatrixEntry matrixEntry : trainMatrix) { matrixEntry.set(ratingWeightMap.get(matrixEntry.get())); } }
/** {@inheritDoc} */ @Override public double merge(final double k, final double v, final java.util.function.BiFunction<? super Double, ? super Double, ? extends Double> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0) { insert(-pos - 1, k, v); return v; } final Double newValue = remappingFunction.apply(Double.valueOf(value[pos]), Double.valueOf(v)); if (newValue == null) { if ((Double.doubleToLongBits(k) == 0)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue).doubleValue(); } /*
@Override public void putAll(Map<? extends Double, ? 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); }
/** {@inheritDoc} */ @Override public double computeIfPresent(final double k, final java.util.function.BiFunction<? super Double, ? super Double, ? extends Double> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0) return defRetValue; final Double newValue = remappingFunction.apply(Double.valueOf(k), Double.valueOf(value[pos])); if (newValue == null) { if ((Double.doubleToLongBits(k) == 0)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue).doubleValue(); } /** {@inheritDoc} */
if ((Double.doubleToLongBits(k) == 0)) { if (containsNullKey) return addToValue(n, incr); pos = n; containsNullKey = true; & mask]) == 0)) { if ((Double.doubleToLongBits(curr) == Double.doubleToLongBits(k))) return addToValue(pos, incr); while (!(Double.doubleToLongBits(curr = key[pos = (pos + 1) & mask]) == 0)) if ((Double.doubleToLongBits(curr) == Double.doubleToLongBits(k))) return addToValue(pos, incr); value[pos] = defRetValue + incr; if (size++ >= maxFill) rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable();
@Override public void clear() { Double2DoubleOpenHashMap.this.clear(); } /** {@inheritDoc} */
/** {@inheritDoc} */ @Override public double replace(final double k, final double v) { final int pos = find(k); if (pos < 0) return defRetValue; final double oldValue = value[pos]; value[pos] = v; return oldValue; } /** {@inheritDoc} */
@Override public boolean contains(double k) { return containsKey(k); } @Override
@Override public boolean contains(double v) { return containsValue(v); } @Override
/** * 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 Double2DoubleOpenHashMap(final double[] 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]); } /**
/** {@inheritDoc} */ @Override public double compute(final double k, final java.util.function.BiFunction<? super Double, ? super Double, ? extends Double> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); final Double newValue = remappingFunction.apply(Double.valueOf(k), pos >= 0 ? Double.valueOf(value[pos]) : null); if (newValue == null) { if (pos >= 0) { if ((Double.doubleToLongBits(k) == 0)) removeNullEntry(); else removeEntry(pos); } return defRetValue; } double newVal = (newValue).doubleValue(); if (pos < 0) { insert(-pos - 1, k, newVal); return newVal; } return value[pos] = newVal; } /** {@inheritDoc} */
@Override public void clear() { Double2DoubleOpenHashMap.this.clear(); } /** {@inheritDoc} */
/** {@inheritDoc} */ @Override public boolean replace(final double k, final double oldValue, final double v) { final int pos = find(k); if (pos < 0 || !(Double.doubleToLongBits(oldValue) == Double.doubleToLongBits(value[pos]))) return false; value[pos] = v; return true; } /** {@inheritDoc} */
private void weightMatrix() { Double2DoubleOpenHashMap ratingWeightMap = new Double2DoubleOpenHashMap(); for (double rating : ratingScale) { ratingWeightMap.putIfAbsent(rating, weight(rating)); } for (MatrixEntry matrixEntry : trainMatrix) { matrixEntry.set(ratingWeightMap.get(matrixEntry.get())); } }
/** {@inheritDoc} */ @Override public double computeIfAbsent(final double k, final java.util.function.DoubleUnaryOperator mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int pos = find(k); if (pos >= 0) return value[pos]; final double newValue = mappingFunction.applyAsDouble(k); insert(-pos - 1, k, newValue); return newValue; } /** {@inheritDoc} */
@Override public void clear() { Double2DoubleOpenHashMap.this.clear(); } }
/** {@inheritDoc} */ @Override public double computeIfAbsentNullable(final double k, final java.util.function.DoubleFunction<? extends Double> mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int pos = find(k); if (pos >= 0) return value[pos]; final Double newValue = mappingFunction.apply(k); if (newValue == null) return defRetValue; final double v = (newValue).doubleValue(); insert(-pos - 1, k, v); return v; } /** {@inheritDoc} */