@Override public int getNumNonZeroElements() { final DoubleIterator iterator = values.values().iterator(); int numNonZeros = 0; for( int i = values.size(); i-- != 0; ) if ( iterator.nextDouble() != 0 ) numNonZeros++; return numNonZeros; }
@Override public double[] toDoubleArray() { synchronized (sync) { return collection.toDoubleArray(); } } @Override
@Override public boolean add(final double k) { synchronized (sync) { return collection.add(k); } } @Override
@Override public boolean addAll(final DoubleCollection c) { synchronized (sync) { return collection.addAll(c); } } @Override
/** * Creates a new big-array big list and fills it with a given type-specific * collection. * * @param c * a type-specific collection that will be used to fill the array * list. */ public DoubleBigArrayBigList(final DoubleCollection c) { this(c.size()); for (DoubleIterator i = c.iterator(); i.hasNext();) add(i.nextDouble()); } /**
@Override public double[] toDoubleArray() { return collection.toDoubleArray(); } /*
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @SuppressWarnings("deprecation") @Deprecated @Override public boolean add(final Double key) { return DoubleCollection.super.add(key); } /**
@Override public boolean addAll(final Collection<? extends Double> c) { synchronized (sync) { return collection.addAll(c); } } @Override
/** * Compute the sum of the elements of a map. * @param v The vector * @return The sum of the values of {@code v}. */ public static double sumAbs(Long2DoubleMap v) { double sum = 0; DoubleIterator iter = v.values().iterator(); while (iter.hasNext()) { sum += Math.abs(iter.nextDouble()); } return sum; }
@Override public boolean addAll(int index, final DoubleCollection c) { ensureIndex(index); int n = c.size(); if (n == 0) return false; grow(size + n); if (index != size) System.arraycopy(a, index, a, index + n, size - index); final DoubleIterator i = c.iterator(); size += n; while (n-- != 0) a[index++] = i.nextDouble(); assert size <= a.length; return true; } @Override
/** * Creates a queue using the elements in a type-specific collection using a * given comparator. * * <p> * This constructor is more efficient than enqueing the elements of * {@code collection} one by one. * * @param collection * a collection; its elements will be used to initialize the queue. * @param c * the comparator used in this queue, or {@code null} for the natural * order. */ public DoubleHeapPriorityQueue(final DoubleCollection collection, final DoubleComparator c) { this(collection.toDoubleArray(), c); } /**
@Override @Deprecated public boolean add(final Double k) { synchronized (sync) { return collection.add(k); } } @Override
/** * Compute the sum of the elements of a map. * @param v The vector * @return The sum of the values of {@code v}. */ public static double sum(Long2DoubleMap v) { double sum = 0; DoubleIterator iter = v.values().iterator(); while (iter.hasNext()) { sum += iter.nextDouble(); } return sum; }
/** * Evaluates the metric for the recommendations added so far. * * @return result of the metric for the recommendations previously added */ @Override public double evaluate() { double gi = 0; double[] cs = itemCount.values().toDoubleArray(); sort(cs); for (int j = 0; j < cs.length; j++) { gi += (2 * (j + (numItems - cs.length) + 1) - numItems - 1) * (cs[j] / freeNorm); } gi /= (numItems - 1); gi = 1 - gi; return gi; }
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @SuppressWarnings("deprecation") @Deprecated @Override default boolean add(final Double o) { return DoubleCollection.super.add(o); } /**
/** * Compute the sum of the squares of elements of a map. * @param v The vector * @return The sum of the squares of the values of {@code v}. */ public static double sumOfSquares(Long2DoubleMap v) { if (v instanceof Long2DoubleSortedArrayMap) { return sumOfSquares((Long2DoubleSortedArrayMap) v); } else { double sum = 0; DoubleIterator iter = v.values().iterator(); while (iter.hasNext()) { double d = iter.nextDouble(); sum += d * d; } return sum; } }
private static void convertSparseDoubleLongKeyModel(Configuration conf, FSDataOutputStream output, String modelInputDir, ModelLineConvert lineConvert) throws IOException { Long2DoubleOpenHashMap[] data = ModelLoader.loadToDoubleLongKeyMaps(modelInputDir, conf); for (int i = 0; i < data.length; i++) { Long2DoubleOpenHashMap row = data[i]; data[i] = null; if (row == null) { continue; } lineConvert.convertRowIndex(output, i); long[] indexes = row.keySet().toLongArray(); double[] values = row.values().toDoubleArray(); row = null; Sort.quickSort(indexes, values, 0, indexes.length - 1); for (int j = 0; j < indexes.length; j++) { lineConvert.convertDoubleLongKey(output, indexes[j], values[j]); } } }
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default boolean add(final Double key) { return add((key).doubleValue()); } /**
@Override public InvertibleFunction<Long2DoubleMap,Long2DoubleMap> makeTransformation(Long2DoubleMap reference) { if (reference.isEmpty()) { return new IdentityVectorNormalizer().makeTransformation(reference); } else { final double mean = Vectors.mean(reference); double var = 0; DoubleIterator iter = reference.values().iterator(); while (iter.hasNext()) { final double v = iter.nextDouble(); final double diff = v - mean; var += diff * diff; } if (Scalars.isZero(var) && Scalars.isZero(damping)) { logger.warn("found zero variance for {}, and no damping is enabled", reference); } /* damping calculation as described in Hofmann '04 * $\sigma_u^2 = \frac{\sigma^2 + q * \={\sigma}^2}{n_u + q}$ */ double stdev = Math.sqrt((var + damping * globalVariance) / (reference.size() + damping)); return new Transform(mean, stdev); } }