/** * Returns a new DoubleColumn containing a value for each value in this column. * * No information is lost in converting from the floats to doubles * * A missing value in the receiver is converted to a missing value in the result */ @Override public DoubleColumn asDoubleColumn() { DoubleArrayList values = new DoubleArrayList(); for (float d : data) { values.add(d); } values.trim(); return DoubleColumn.create(this.name(), values.elements()); } }
int size = _values.size(); if (leftChildIndex >= size && rightChildIndex >= size) { // This is leaf node, all done. break; minIndex = leftChildIndex; } else { // Node has both left and right children, find the minimum of the two. double leftChildValue = _values.getDouble(leftChildIndex); double rightChildValue = _values.getDouble(rightChildIndex); if (compare(_values.getDouble(index), _values.getDouble(minIndex)) == 1) { swapValues(index, minIndex); index = minIndex;
@Override public DoubleColumn bottom(final int n) { DoubleArrayList bottom = new DoubleArrayList(); double[] values = data.toDoubleArray(); DoubleArrays.parallelQuickSort(values); for (int i = 0; i < n && i < values.length; i++) { bottom.add(values[i]); } return new DoubleColumn(name() + "[Bottoms " + n + "]", bottom); }
@Override public DoubleArrayList deserialize(ByteBuffer byteBuffer) { int numValues = byteBuffer.getInt(); DoubleArrayList doubleArrayList = new DoubleArrayList(numValues); for (int i = 0; i < numValues; i++) { doubleArrayList.add(byteBuffer.getDouble()); } return doubleArrayList; } };
@Override public byte[] serialize(DoubleArrayList doubleArrayList) { int size = doubleArrayList.size(); byte[] bytes = new byte[Integer.BYTES + size * Double.BYTES]; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.putInt(size); double[] values = doubleArrayList.elements(); for (int i = 0; i < size; i++) { byteBuffer.putDouble(values[i]); } return bytes; }
/** * Helper method that performs all operations required to swap two values. * <ul> * <li> Swaps the values in the array that backs the heap. </li> * <li> Updates the indexToKey and keyToIndex maps due to the swap. </li> * </ul> * @param index1 Index to swap * @param index2 Index to swap */ private void swapValues(int index1, int index2) { if (index1 == index2) { return; } double tmp = _values.getDouble(index1); _values.set(index1, _values.getDouble(index2)); _values.set(index2, tmp); swapKeys(index1, index2); }
@Override public RatingSummary get() { HashKeyIndex index = new HashKeyIndex(); DoubleArrayList sums = new DoubleArrayList(); IntArrayList counts = new IntArrayList(); assert sums.size() == counts.size(); long item = r.getItemId(); int idx = index.internId(item); if (idx >= sums.size()) { assert idx == sums.size() && idx == counts.size(); sums.add(r.getValue()); counts.add(1); } else { sums.set(idx, sums.getDouble(idx) + r.getValue()); counts.set(idx, counts.getInt(idx) + 1); int oidx = index.getIndex(items.getKey(i)); countArray[i] = counts.getInt(oidx); offsets[i] = sums.getDouble(oidx) / countArray[i] - mean; logger.info("summarized {} items with {} ratings", sums.size(), totalCount);
public static DoubleColumn create(final String name, final float[] arr) { final double[] doubles = new double[arr.length]; for (int i = 0; i < arr.length; i++) { doubles[i] = arr[i]; } return new DoubleColumn(name, new DoubleArrayList(doubles)); }
/** * Adds the given double to this column */ public DoubleColumn append(double d) { data.add(d); return this; }
@Override public DoubleColumn lag(int n) { final int srcPos = n >= 0 ? 0 : 0 - n; final double[] dest = new double[size()]; final int destPos = n <= 0 ? 0 : n; final int length = n >= 0 ? size() - n : size() + n; for (int i = 0; i < size(); i++) { dest[i] = FloatColumnType.missingValueIndicator(); } double[] array = data.toDoubleArray(); System.arraycopy(array, srcPos, dest, destPos, length); return new DoubleColumn(name() + " lag(" + n + ")", new DoubleArrayList(dest)); }
public ChannelStorage(Symbol sym, double dft) { symbol = sym; defaultValue = dft; values = new DoubleArrayList(scores.elements().length); for (int i = size() - 1; i >= 0; i--) { values.add(defaultValue); } } }
/** * Puts the element into the priority queue. * <ul> * <li> If key does not exist, it is added to the priority queue. </li> * <li> If key exists, then the value is updated, and the priority queue ordering is maintained. </li> * <li> Runtime complexity of {@code O(log(n)}). </li> * </ul> * @param key Integer key for the value * @param value Double value of the key */ public void put(int key, double value) { if (!_keyToIndexMap.containsKey(key)) { _values.add(value); int last = _values.size() - 1; updateKeyIndexMap(key, last); siftUp(last); } else { int index = _keyToIndexMap.get(key); _values.set(index, value); // Sift the value up or down, as the case may be. if (!siftDown(index)) { siftUp(index); } } }
metricsNoScore.trim(); String[] elements = metricsNoScore.toArray(new String[metricsNoScore.size()]); DoubleArrayList all = DoubleArrayList.wrap(delegate.getMetricValues(elements)); String metricName = metricsNoScore.get(i); if ("F1".equals(metricName)) { F1 = all.getDouble(i); for (int i = 0; i < metrics.length; i++) { if ("score".equals(metrics[i])) { all.add(i, observedScore); all.add(i, observedAUC); all.add(i, observedAUC_F1); return all.toDoubleArray();
public static DoubleColumn create(String name, DoubleArrayList floats) { DoubleColumn column = new DoubleColumn(name, floats.size()); column.data = new DoubleArrayList(floats.size()); column.data.addAll(floats); return column; }
@Override public double getDouble(int row) { return data.getDouble(row); }
DoubleArrayList metricValues = new DoubleArrayList(); final double[] performanceValues = perfDescriptor.estimateMetric(computationGraph, validationIterator, args().numValidation, perfDescriptor.performanceMetrics()); metricValues = DoubleArrayList.wrap(performanceValues); performanceValues); performanceLogger.logMetrics("epochs", numExamplesUsed, epoch, metricValues.toDoubleArray()); performanceLogger.logTrainingScore("epochs", epoch, trainingScore); if (args().trackingStyle == TrainingArguments.TrackStyle.PERFS) { bestValue = validationMetricValue; performanceLogger.logMetrics(bestMetricName, numExamplesUsed, epoch, metricValues.toDoubleArray()); notImproved = 0; } else {
@Override public int size() { return data.size(); }
/** * Add the vector specified. This is a vector addition that does an * element-by-element addition. * * @param other the vector to add. */ public void add(DoubleDenseVector other) { if (isSingleton) { throw new RuntimeException("Cannot add to singleton vector"); } if (other.isSingleton) { ensureCapacity(other.singletonIndex + 1); entries.set(other.singletonIndex, entries.getDouble(other.singletonIndex) + other.singletonValue); } else { ensureCapacity(other.entries.size()); for (int i = 0; i < other.entries.size(); ++i) { entries.set(i, entries.getDouble(i) + other.entries.getDouble(i)); } } }
@Override public void sortAscending() { DoubleArrays.parallelQuickSort(data.elements()); }
add(id.getId(), id.getScore()); assert ids.size() == idx + 1; assert scores.size() == idx + 1; for (SymbolValue<?> sv: chans) { TypedSymbol<?> sym = sv.getSymbol(); if (sym.getType().equals(Double.class) && channels.containsKey(sym.getRawSymbol())) { ChannelStorage chan = channels.get(sym.getRawSymbol()); assert chan.values.size() == idx + 1; if (sv instanceof DoubleSymbolValue) { chan.values.set(idx, ((DoubleSymbolValue) sv).getDoubleValue()); } else { Object v = sv.getValue(); chan.values.set(idx, (Double) v);