private void add(FloatFV y, SparseFloatArray x, double d) { // w2 = w2 + x*w1 for (final Entry e : x.entries()) { y.values[e.index] += e.value * d; } }
private void add(FloatFV y, SparseFloatArray x, double d) { // w2 = w2 + x*w1 for (final Entry e : x.entries()) { y.values[e.index] += e.value * d; } }
/** * Compute the sum of values squared * @return the sum of all values */ public float sumValuesSquared() { float sum = 0; for (Entry e : entries()) sum += e.value * e.value; return sum; }
@Override public int computeHashCode(SparseFloatArray array) { double dp = 0; for (Entry e : array.entries()) dp += r[e.index] * e.value; return dp >= 0 ? 1 : 0; } }
@Override public double[] asDoubleVector() { double [] d = new double[values.length]; for (Entry e : values.entries()) { d[e.index] = e.value; } return d; }
/** * @return the largest value in the array */ public float maxValue() { float max = -Float.MAX_VALUE; for (Entry e : entries()) { if (e.value > max) max = e.value; } return max; }
/** * @return the smallest value in the array */ public float minValue() { float min = Float.MAX_VALUE; for (Entry e : entries()) { if (e.value < min) min = e.value; } return min; }
@Override public int computeHashCode(SparseFloatArray array) { double dp = 0; for (Entry e : array.entries()) dp += r[e.index] * e.value; return dp >= 0 ? 1 : 0; } }
private double dot(FloatFV v1, SparseFloatArray v2) { double d = 0; for (final Entry e : v2.entries()) { d += e.value * v1.values[e.index]; } return d; }
/** * Compute the sum of values * @return the sum of all values */ public float sumValues() { float sum = 0; for (Entry e : entries()) sum += e.value; return sum; }
@Override public double[] asDoubleVector() { double [] d = new double[values.length]; for (Entry e : values.entries()) { d[e.index] = e.value; } return d; }
private double dot(FloatFV v1, SparseFloatArray v2) { double d = 0; for (final Entry e : v2.entries()) { d += e.value * v1.values[e.index]; } return d; }
@Override public int computeHashCode(SparseFloatArray array) { double val = 0; for (Entry e : array.entries()) { val += e.value * r[e.index]; } val = (val + b) / w; return (int) Math.floor(val); } }
@Override public void writeASCII(PrintWriter out) throws IOException { out.print(this.length); out.print(" "); for (Entry e : entries()) { out.print(e.index + ":" + e.value + " "); } }
/** * Subtract the values in the given vector from * this array and return this * @param vector the vector to add * @return this */ public SparseFloatArray subtractInplace(SparseFloatArray vector) { for (Entry e : vector.entries()) { increment(e.index, (float)(-e.value)); } return this; }
/** * Add the values in the given vector to * this vector and return this * @param vector the vector to add * @return this */ public SparseFloatArray addInplace(SparseFloatArray vector) { for (Entry e : vector.entries()) { increment(e.index, e.value); } return this; }
@Override public void writeBinary(DataOutput out) throws IOException { out.writeInt(this.length); out.writeInt(this.used()); for (Entry e : entries()) { out.writeInt(e.index); out.writeFloat(e.value); } }
@Override public SparseFloatArray concatenate(List<SparseFloatArray> ins) { final SparseFloatArray result = copy(); for (int i=0; i<ins.size(); i++) { final int oldLength = result.length; result.setLength(oldLength + ins.get(i).length); for (Entry e : ins.get(i).entries()) { result.set(e.index + oldLength, e.value); } } return result; } }
/** * Multiply the values inplace by a scalar and return this * @param value scalar multiplier * @return this */ public SparseFloatArray multiplyInplace(double value) { for (Entry e : entries()) { if (this.isUsed(e.index)) set(e.index, (float)(value * e.value)); } return this; }
@Override public SparseFloatArray concatenate(SparseFloatArray... ins) { final SparseFloatArray result = copy(); for (int i=0; i<ins.length; i++) { final int oldLength = result.length; result.setLength(oldLength + ins[i].length); for (Entry e : ins[i].entries()) { result.set(e.index + oldLength, e.value); } } return result; }