@Override public double getLengthSquared() { return delegate.getLengthSquared(); }
@Override public double getLengthSquared() { return delegate.getLengthSquared(); }
public static void assertEigen(int i, Vector e, VectorIterable corpus, double errorMargin, boolean isSymmetric) { if (e.getLengthSquared() == 0) { return; } Vector afterMultiply = isSymmetric ? corpus.times(e) : corpus.timesSquared(e); double dot = afterMultiply.dot(e); double afterNorm = afterMultiply.getLengthSquared(); double error = 1 - Math.abs(dot / Math.sqrt(afterNorm * e.getLengthSquared())); log.info("the eigen-error: {} for eigen {}", error, i); assertTrue("Error: {" + error + " too high! (for eigen " + i + ')', Math.abs(error) < errorMargin); }
@Override public double getDistanceSquared(Vector that) { if (size != that.size()) { throw new CardinalityException(size, that.size()); } double thisLength = getLengthSquared(); double thatLength = that.getLengthSquared(); double dot = dot(that); double distanceEstimate = thisLength + thatLength - 2 * dot; if (distanceEstimate > 1.0e-3 * (thisLength + thatLength)) { // The vectors are far enough from each other that the formula is accurate. return Math.max(distanceEstimate, 0); } else { return aggregate(that, Functions.PLUS, Functions.MINUS_SQUARED); } }
private static void doTestGetDistanceSquared(Vector v, Vector w) { double expected = v.minus(w).getLengthSquared(); assertEquals(expected, v.getDistanceSquared(w), 1.0e-6); }
@Test public void testLength() { Vector v = new DenseVector(new double[]{0.9921337470551008, 1.0031004325833064, 0.9963963182745947}); Centroid c = new Centroid(3, new DenseVector(v), 2); assertEquals(c.getVector().getLengthSquared(), c.getLengthSquared(), 1.0e-17); // previously, this wouldn't clear the cached squared length value correctly which would cause bad distances c.set(0, -1); System.out.printf("c = %.9f\nv = %.9f\n", c.getLengthSquared(), c.getVector().getLengthSquared()); assertEquals(c.getVector().getLengthSquared(), c.getLengthSquared(), 1.0e-17); }
} else { Vector other = m.viewRow(r.nextInt(numRows)); if (other != null && other.getLengthSquared() > 0) { m.assignRow(c, other.clone());
@Test public void testGetDistanceSquared() { Vector other = new RandomAccessSparseVector(test.size()); other.set(1, -2); other.set(2, -5); other.set(3, -9); other.set(4, 1); double expected = test.minus(other).getLengthSquared(); assertTrue("a.getDistanceSquared(b) != a.minus(b).getLengthSquared", Math.abs(expected - test.getDistanceSquared(other)) < 10.0E-7); }
private static void doTestGetLengthSquared(Vector v) { double expected = lengthSquaredSlowly(v); assertEquals("v.getLengthSquared() != sum_of_squared_elements(v)", expected, v.getLengthSquared(), 0.0); assertEquals("mutation via set() fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via setQuick() fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via sparse iterator.set fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via assign(double) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via assign(square) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via assign(double[]) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via v.getElement().set() fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via normalize() fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via normalize(double) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via times(double) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via times(vector) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON); assertEquals("mutation via assign(pow, 3.0) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);
+ 2 * activation * currentState.getActivationNumerator() + activation * activation * (trainingVector.getLengthSquared() - currentState.currentTrainingProjection().getLengthSquared())); if (numPreviousEigens > 0) { currentState.getHelperVector().assign(currentState.currentTrainingProjection(), new PlusMult(activation));
private static void doTestAggregation(Vector v, Vector w) { assertEquals("aggregate(plus, pow(2)) not equal to " + v.getLengthSquared(), v.getLengthSquared(), v.aggregate(Functions.PLUS, Functions.pow(2)), EPSILON); assertEquals("aggregate(plus, abs) not equal to " + v.norm(1), v.norm(1), v.aggregate(Functions.PLUS, Functions.ABS), EPSILON); assertEquals("aggregate(max, abs) not equal to " + v.norm(Double.POSITIVE_INFINITY), v.norm(Double.POSITIVE_INFINITY), v.aggregate(Functions.MAX, Functions.ABS), EPSILON); assertEquals("v.dot(w) != v.aggregate(w, plus, mult)", v.dot(w), v.aggregate(w, Functions.PLUS, Functions.MULT), EPSILON); assertEquals("|(v-w)|^2 != v.aggregate(w, plus, chain(pow(2), minus))", v.minus(w).dot(v.minus(w)), v.aggregate(w, Functions.PLUS, Functions.chain(Functions.pow(2), Functions.MINUS)), EPSILON); }
double h = ort.viewPart(m, high - m + 1).getLengthSquared();
assertEquals(dv1.getLengthSquared(), v1.getLengthSquared(), FUZZ); assertEquals(dv1.getDistanceSquared(dv2), v1.getDistanceSquared(v2), FUZZ); assertEquals(dv1.getDistanceSquared(dv2), dv1.getDistanceSquared(v2), FUZZ); v3.assign(0); assertEquals(0, dv1.getDistanceSquared(v1), FUZZ); assertEquals(0, v3.getLengthSquared(), FUZZ);
@Override public double distance(double centroidLengthSquare, Vector centroid, Vector v) { return centroidLengthSquare - 2 * v.dot(centroid) + v.getLengthSquared(); } }
@Override public double distance(double centroidLengthSquare, Vector centroid, Vector v) { return centroidLengthSquare - 2 * v.dot(centroid) + v.getLengthSquared(); } }
/** * Return if the point is covered by the canopy * * @param point * a point * @return if the point is covered */ public boolean canopyCovers(Canopy canopy, Vector point) { return measure.distance(canopy.getCenter().getLengthSquared(), canopy.getCenter(), point) < t1; }
/** * Return if the point is covered by the canopy * * @param point * a point * @return if the point is covered */ public boolean canopyCovers(Canopy canopy, Vector point) { return measure.distance(canopy.getCenter().getLengthSquared(), canopy.getCenter(), point) < t1; }
/** * Return if the point is covered by the canopy * * @param point * a point * @return if the point is covered */ public boolean canopyCovers(Canopy canopy, Vector point) { return measure.distance(canopy.getCenter().getLengthSquared(), canopy.getCenter(), point) < t1; }
public boolean calculateConvergence(double convergenceDelta) { Vector centroid = computeCentroid(); converged = getMeasure().distance(centroid.getLengthSquared(), centroid, getCenter()) <= convergenceDelta; return converged; }
public boolean calculateConvergence(double convergenceDelta) { Vector centroid = computeCentroid(); converged = getMeasure().distance(centroid.getLengthSquared(), centroid, getCenter()) <= convergenceDelta; return converged; }