/** * Returns the number of non-zero entries in the given vector */ public static int cardinality(Vector x) { int nz = 0; for (VectorEntry e : x) if (e.get() != 0) nz++; return nz; }
@Override public double getValue() { return this.internalEntry.get(); }
@Override public double getValue() { return this.internalEntry.get(); }
private static double fuzzyCardinality(Vector aSV) { double d = 0.0; for (VectorEntry e : aSV) { d += e.get(); } return d; }
protected double norm1() { double sum = 0; for (VectorEntry e : this) sum += Math.abs(e.get()); return sum; }
protected double norm1() { double sum = 0; for (VectorEntry e : this) sum += Math.abs(e.get()); return sum; }
protected double normInf() { double max = 0; for (VectorEntry e : this) max = Math.max(Math.abs(e.get()), max); return max; }
protected double normInf() { double max = 0; for (VectorEntry e : this) max = Math.max(Math.abs(e.get()), max); return max; }
public Vector scale(double alpha) { if (alpha == 0) return zero(); else if (alpha == 1) return this; for (VectorEntry e : this) e.set(alpha * e.get()); return this; }
/** * Returns a dense array containing a copy of the given vector */ public static double[] getArray(Vector x) { double[] xd = new double[x.size()]; for (VectorEntry e : x) xd[e.index()] = e.get(); return xd; }
/** * Returns a dense array containing a copy of the given vector */ public static double[] getArray(Vector x) { double[] xd = new double[x.size()]; for (VectorEntry e : x) xd[e.index()] = e.get(); return xd; }
public double dot(Vector y) { checkSize(y); double ret = 0; for (VectorEntry e : this) ret += e.get() * y.get(e.index()); return ret; }
public Vector add(double alpha, Vector y) { checkSize(y); if (alpha == 0) return this; for (VectorEntry e : y) add(e.index(), alpha * e.get()); return this; }
public Vector add(double alpha, Vector y) { checkSize(y); if (alpha == 0) return this; for (VectorEntry e : y) add(e.index(), alpha * e.get()); return this; }
protected Vector getDegreeVector(int tokenSize, FlexCompColMatrix adjacentMatrix) { Vector degreeVector = new DenseVector(tokenSize); for (int i = 0; i < adjacentMatrix.numColumns(); i++) { SparseVector col = adjacentMatrix.getColumn(i); double sum = 0; for (VectorEntry entry : col) { sum += entry.get(); } degreeVector.set(i, sum); } return degreeVector; }
public Vector set(double alpha, Vector y) { checkSize(y); if (alpha == 0) return zero(); zero(); for (VectorEntry e : y) set(e.index(), alpha * e.get()); return this; }