org.apache.mahout.math.Vector.getLengthSquared()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.apache.mahout.math.Vector.getLengthSquared()方法的一些代码示例,展示了Vector.getLengthSquared()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.getLengthSquared()方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:getLengthSquared

Vector.getLengthSquared介绍

[英]Return the sum of squares of all elements in the vector. Square root of this value is the length of the vector.
[中]返回向量中所有元素的平方和。该值的平方根是向量的长度。

代码示例

代码示例来源:origin: apache/mahout

@Override
public double getLengthSquared() {
 return delegate.getLengthSquared();
}

代码示例来源:origin: apache/mahout

@Override
public double getLengthSquared() {
 return delegate.getLengthSquared();
}

代码示例来源:origin: apache/mahout

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);
}

代码示例来源:origin: apache/mahout

@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);
 }
}

代码示例来源:origin: apache/mahout

private static void doTestGetDistanceSquared(Vector v, Vector w) {
 double expected = v.minus(w).getLengthSquared();
 assertEquals(expected, v.getDistanceSquared(w), 1.0e-6);
}

代码示例来源:origin: apache/mahout

@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);
}

代码示例来源:origin: apache/mahout

} else {
 Vector other = m.viewRow(r.nextInt(numRows));
 if (other != null && other.getLengthSquared() > 0) {
  m.assignRow(c, other.clone());

代码示例来源:origin: apache/mahout

@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);
}

代码示例来源:origin: apache/mahout

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);

代码示例来源:origin: apache/mahout

+ 2 * activation * currentState.getActivationNumerator()
    + activation * activation
      * (trainingVector.getLengthSquared() - currentState.currentTrainingProjection().getLengthSquared()));
if (numPreviousEigens > 0) {
 currentState.getHelperVector().assign(currentState.currentTrainingProjection(), new PlusMult(activation));

代码示例来源:origin: apache/mahout

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);
}

代码示例来源:origin: apache/mahout

double h = ort.viewPart(m, high - m + 1).getLengthSquared();

代码示例来源:origin: apache/mahout

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);

代码示例来源:origin: org.apache.mahout/mahout-core

@Override
 public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
  return centroidLengthSquare - 2 * v.dot(centroid) + v.getLengthSquared();
 }
}

代码示例来源:origin: org.apache.mahout/mahout-mr

@Override
 public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
  return centroidLengthSquare - 2 * v.dot(centroid) + v.getLengthSquared();
 }
}

代码示例来源:origin: org.apache.mahout/mahout-core

/**
 * 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;
}

代码示例来源:origin: org.apache.mahout/mahout-mr

/**
 * 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;
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

/**
 * 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;
}

代码示例来源:origin: org.apache.mahout/mahout-core

public boolean calculateConvergence(double convergenceDelta) {
 Vector centroid = computeCentroid();
 converged = getMeasure().distance(centroid.getLengthSquared(), centroid, getCenter()) <= convergenceDelta;
 return converged;
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

public boolean calculateConvergence(double convergenceDelta) {
 Vector centroid = computeCentroid();
 converged = getMeasure().distance(centroid.getLengthSquared(), centroid, getCenter()) <= convergenceDelta;
 return converged;
}

相关文章