@Override protected boolean token(XContentParser parser, String field, XContentParser.Token token, Map<String, Object> params) throws IOException { if (PERCENTS_FIELD.match(field, parser.getDeprecationHandler()) && token == XContentParser.Token.START_ARRAY) { DoubleArrayList percents = new DoubleArrayList(10); while (parser.nextToken() != XContentParser.Token.END_ARRAY) { percents.add(parser.doubleValue()); } params.put(PERCENTS_FIELD.getPreferredName(), percents.toArray()); return true; } return false; }
/** * {@inheritDoc} */ @Override public DoubleStack clone() { return (DoubleStack) super.clone(); } }
/** * Compare index-aligned elements against another * {@link DoubleIndexedContainer}. */ protected boolean equalElements(DoubleArrayList other) { int max = size(); if (other.size() != max) { return false; } for (int i = 0; i < max; i++) { if (!(Double.doubleToLongBits(other.get(i)) == Double.doubleToLongBits( get(i)))) { return false; } } return true; }
/** * Create a list from a variable number of arguments or an array of <code>double</code>. * The elements are copied from the argument to the internal buffer. */ /* */ public static DoubleArrayList from(double... elements) { final DoubleArrayList list = new DoubleArrayList(elements.length); list.add(elements); return list; } }
/** * Adds all elements from another iterable. */ public int addAll(Iterable<? extends DoubleCursor> iterable) { int size = 0; for (DoubleCursor cursor : iterable) { add(cursor.value); size++; } return size; }
@Override public double summarize(double[] values, double[] weights) { if (values.length == 0) { throw new IllegalArgumentException( "The given array has to have at least one element to determine the modus."); } DoubleArrayList weightedValues = new DoubleArrayList(values.length); for (int i = 0; i < values.length; ++i) { if (!Double.isNaN(values[i])) { weightedValues.add(weights[i] * values[i]); } } if (weightedValues.size() == 0) { return 0; } double weightedValuesAsArray[] = weightedValues.toArray(); Arrays.sort(weightedValuesAsArray); if ((weightedValuesAsArray.length & 1) > 0) { return weightedValuesAsArray[weightedValuesAsArray.length / 2]; } else { return (weightedValuesAsArray[weightedValuesAsArray.length / 2] + weightedValuesAsArray[(weightedValuesAsArray.length / 2) - 1]) / 2.0; } }
public void addFeatures(StringFeatureVector vector) { List<String> types = vector.s_types; List<String> values = vector.s_values; DoubleArrayList weights = vector.d_weights; int i, size = vector.size(); for (i=0; i<size; i++) { s_types .add(types .get(i)); s_values.add(values.get(i)); if (weights != null) d_weights.add(weights.get(i)); } }
private void initWeights(boolean hasWeight) { d_weights = hasWeight ? new DoubleArrayList() : null; b_weight = hasWeight; }
/** * Returns all feature weights. * @return all feature weights. */ public double[] getWeights() { return d_weights.toArray(); } }
/** * Adds all elements from another container. */ public int addAll(DoubleContainer container) { final int size = container.size(); ensureBufferSpace(size); for (DoubleCursor cursor : container) { add(cursor.value); } return size; }
@Override public double[] getScores(SparseFeatureVector x) { double[] scores = d_weights.get(0).toArray(); int i, index, label, size = x.size(); DoubleArrayList weight; double value = 1; // features for (i=0; i<size; i++) { index = x.getIndex(i); if (x.hasWeight()) value = x.getWeight(i); if (isRange(index)) { weight = d_weights.get(index); for (label=0; label<n_labels; label++) { if (x.hasWeight()) scores[label] += weight.get(label) * value; else scores[label] += weight.get(label); } } } return scores; }
/** * Returns the index'th feature weight. * @param index the index of the feature weight to return. * @return the index'th feature weight. */ public double getWeight(int index) { return d_weights.get(index); }
/** * Ensure this container can hold at least the given number of elements * without resizing its buffers. * * @param expectedElements * The total number of elements, inclusive. */ @Override public void ensureCapacity(int expectedElements) { final int bufferLen = (buffer == null ? 0 : buffer.length); if (expectedElements > bufferLen) { ensureBufferSpace(expectedElements - size()); } }
protected DoubleArrayList getBlankDoubleArrayList(int size) { DoubleArrayList list = new DoubleArrayList(size); int i; for (i=0; i<size; i++) list.add(0); return list; }
/** * Vararg-signature method for adding elements at the end of the list. * <p> * <b>This method is handy, but costly if used in tight loops (anonymous array * passing)</b> * </p> */ /* */ public final void add(double... elements) { add(elements, 0, elements.length); }
public void addFeatures(StringFeatureVector vector) { List<String> types = vector.s_types; List<String> values = vector.s_values; DoubleArrayList weights = vector.d_weights; int i, size = vector.size(); for (i=0; i<size; i++) { s_types .add(types .get(i)); s_values.add(values.get(i)); if (weights != null) d_weights.add(weights.get(i)); } }