/** * Create a new array of the given size (for generics) * * @param <F> First class * @param <S> Second class * @param size array size * @return empty array of the new type. */ public static final <F, S> Pair<F, S>[] newPairArray(int size) { Class<Pair<F, S>> paircls = ClassGenericsUtil.uglyCastIntoSubclass(Pair.class); return ClassGenericsUtil.newArrayOfNull(size, paircls); }
/** * Compute the Jaccard similarity of two bit vectors. * * @param v2 Second bit vector * @return Jaccard similarity (intersection / union) */ public double jaccardSimilarity(BitVector v2) { return BitsUtil.intersectionSize(bits, v2.bits) / (double) BitsUtil.unionSize(bits, v2.bits); }
/** * Formats the float array f with ',' as separator and 2 fraction digits. * * @param f the float array to be formatted * @return a String representing the float array f */ public static String format(float[] f) { return format(f, ", ", NF2); }
/** * Get the resulting dimensionality. * * @return dimensionality */ public int getDimensionality() { return BitsUtil.cardinality(selectedAttributes); }
@Override public DBIDIter advance() { pos = BitsUtil.nextSetBit(bits, pos + 1); return this; }
/** * Test if the current column is marked as label column. * * @param col Column number * @return {@code true} when a label column. */ protected boolean isLabelColumn(int col) { return labelIndices != null && BitsUtil.get(labelIndices, col); }
/** * Get current value as double. * * @return double value * @throws NumberFormatException when current value cannot be parsed as double * value. */ public double getDouble() throws NumberFormatException { return FormatUtil.parseDouble(input, start, end); }
/** * Combine onto v using the OR operation, i.e. {@code v |= this}. * * @param v Existing bit set of same length. */ public void orOnto(long[] v) { BitsUtil.orI(v, bits); }
/** * Get current value as long. * * @return double value * @throws NumberFormatException when current value cannot be parsed as long * value. */ public long getLongBase10() throws NumberFormatException { return FormatUtil.parseLongBase10(input, start, end); }
/** * Combine onto v using the XOR operation, i.e. {@code v ^= this}. * * @param v Existing bit set of same length. */ public void xorOnto(long[] v) { BitsUtil.xorI(v, bits); }
@Override public DBIDIter advance() { pos = BitsUtil.nextClearBit(bits, pos + 1); return this; }
@Override public int compareTo(HilbertRef<T> o) { return BitsUtil.compare(this.bits, o.bits); } }
/** * Compute the vector cardinality (uncached!) * * @return Vector cardinality */ public int cardinality() { return BitsUtil.cardinality(bits); }
/** * Returns a string representation of the object. * * @return a string representation of the object. */ @Override public String toString() { return FormatUtil.format(b, FormatUtil.NF4); } }
/** * Creates a new k-dimensional subspace of the original data space. * * @param dimensions the dimensions building this subspace */ public Subspace(long[] dimensions) { this.dimensions = dimensions; dimensionality = BitsUtil.cardinality(dimensions); }
/** * Returns a string representation of this vector without adding extra * whitespace. * * @return a string representation of this vector. */ public final String toStringNoWhitespace() { return "[" + FormatUtil.format(elements, ",") + "]"; }
/** * Formats the double array d with the specified number format. * * @param d the double array to be formatted * @param nf the number format to be used for formatting * @return a String representing the double array d */ public static String format(double[] d, NumberFormat nf) { return format(d, " ", nf); }
/** * returns String-representation of Matrix. * * @return String representation of this Matrix */ public static String format(Matrix m) { return format(m, FormatUtil.NF); }
/** * Returns a String representation of the HyperBoundingBox. * * @param nf number format for output accuracy * @param pre the prefix of each line * @return a string representation of this hyper bounding box */ public String toString(String pre, NumberFormat nf) { return pre + "[Min(" + FormatUtil.format(min, ",", nf) + "), Max(" + FormatUtil.format(max, ",", nf) + ")]"; }