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

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

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

Vector.dot介绍

[英]Return the dot product of the recipient and the argument
[中]返回收件人和参数的点积

代码示例

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

public WeightedVector(Vector v, Vector projection, int index) {
 super(v);
 this.index = index;
 this.weight = v.dot(projection);
}

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

@Override
public double dot(Vector x) {
 return delegate.dot(x);
}

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

@Override
public double dot(Vector x) {
 return delegate.dot(x);
}

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

private Vector localVOrtho(Vector v) {
 for (Vector old : localV) {
  if (old != null) {
   double x = v.dot(old);
   v = v.minus(old.times(x));
  }
 }
 return v;
}

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

public static VectorIterable pairwiseInnerProducts(Iterable<MatrixSlice> basis) {
 DenseMatrix out = null;
 for (MatrixSlice slice1 : basis) {
  List<Double> dots = Lists.newArrayList();
  for (MatrixSlice slice2 : basis) {
   dots.add(slice1.vector().dot(slice2.vector()));
  }
  if (out == null) {
   out = new DenseMatrix(dots.size(), dots.size());
  }
  for (int i = 0; i < dots.size(); i++) {
   out.set(slice1.index(), i, dots.get(i));
  }
 }
 return out;
}

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

private static void updateTrainingProjectionsVector(TrainingState state,
                          Vector trainingVector,
                          int previousEigenIndex) {
 Vector previousEigen = state.mostRecentEigen();
 Vector currentTrainingVectorProjection = state.currentTrainingProjection();
 double projection = previousEigen.dot(trainingVector);
 currentTrainingVectorProjection.set(previousEigenIndex, projection);
}

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

protected static void orthoganalizeAgainstAllButLast(Vector nextVector, LanczosState state) {
 for (int i = 0; i < state.getIterationNumber(); i++) {
  Vector basisVector = state.getBasisVector(i);
  double alpha;
  if (basisVector == null || (alpha = nextVector.dot(basisVector)) == 0.0) {
   continue;
  }
  nextVector.assign(basisVector, new PlusMult(-alpha));
 }
}

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

@Override
public EigenStatus verify(VectorIterable corpus, Vector vector) {
 Vector resultantVector = corpus.timesSquared(vector);
 double newNorm = resultantVector.norm(2);
 double oldNorm = vector.norm(2);
 double eigenValue;
 double cosAngle;
 if (newNorm > 0 && oldNorm > 0) {
  eigenValue = newNorm / oldNorm;
  cosAngle = resultantVector.dot(vector) / newNorm * oldNorm;
 } else {
  eigenValue = 1.0;
  cosAngle = 0.0;
 }
 return new EigenStatus(eigenValue, cosAngle, false);
}

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

@Test
public void testDot() throws Exception {
 double res = test.dot(test);
 assertEquals("dot", 1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3, res, EPSILON);
}

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

@Test
public void testDot() {
 double res = test.dot(test);
 double expected = 3.3 * 3.3 + 2.2 * 2.2 + 1.1 * 1.1;
 assertEquals("dot", expected, res, EPSILON);
}

代码示例来源: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

@Test(expected = CardinalityException.class)
public void testDotCardinality() {
 test.dot(new DenseVector(test.size() + 1));
}

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

@Test(expected = CardinalityException.class)
public void testDotCardinality() {
 test.dot(new DenseVector(test.size() + 1));
}

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

@Override
public Vector times(Vector v) {
 int columns = columnSize();
 if (columns != v.size()) {
  throw new CardinalityException(columns, v.size());
 }
 int rows = rowSize();
 Vector w = new DenseVector(rows);
 for (int row = 0; row < rows; row++) {
  w.setQuick(row, v.dot(viewRow(row)));
 }
 return w;
}

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

public static Vector mult(Matrix m, Vector v) {
 if (m.numRows() != v.size()) {
  throw new CardinalityException(m.numRows(), v.size());
 }
 // Use a Dense Vector for the moment,
 Vector result = new DenseVector(m.numRows());
 
 for (int i = 0; i < m.numRows(); i++) {
  result.set(i, m.viewRow(i).dot(v));
 }
 
 return result;
}

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

@Test
public void testDot2() {
 Vector test2 = test.clone();
 test2.set(1, 0.0);
 test2.set(3, 0.0);
 assertEquals(3.3 * 3.3, test2.dot(test), EPSILON);
}

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

private static void doTestVectors(Vector left, Vector right) {
 left.setQuick(0, 1);
 left.setQuick(1, 2);
 left.setQuick(2, 3);
 right.setQuick(0, 4);
 right.setQuick(1, 5);
 right.setQuick(2, 6);
 double result = left.dot(right);
 assertEquals(32.0, result, EPSILON);
}

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

@Test
public void testDotSuperBig() {
 Vector w = new SequentialAccessSparseVector(Integer.MAX_VALUE, 12);
 w.set(1, 0.4);
 w.set(2, 0.4);
 w.set(3, -0.666666667);
 Vector v = new SequentialAccessSparseVector(Integer.MAX_VALUE, 12);
 v.set(3, 1);
 assertEquals("super-big", -0.666666667, v.dot(w), EPSILON);
}

代码示例来源: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

@Test
public void testProjection() {
 Vector v1 = new DenseVector(10).assign(Functions.random());
 WeightedVector v2 = new WeightedVector(v1, v1, 31);
 assertEquals(v1.dot(v1), v2.getWeight(), 1.0e-13);
 assertEquals(31, v2.getIndex());
 Matrix y = new DenseMatrix(10, 4).assign(Functions.random());
 Matrix q = new QRDecomposition(y.viewPart(0, 10, 0, 3)).getQ();
 Vector nullSpace = y.viewColumn(3).minus(q.times(q.transpose().times(y.viewColumn(3))));
 WeightedVector v3 = new WeightedVector(q.viewColumn(0).plus(q.viewColumn(1)), nullSpace, 1);
 assertEquals(0, v3.getWeight(), 1.0e-13);
 Vector qx = q.viewColumn(0).plus(q.viewColumn(1)).normalize();
 WeightedVector v4 = new WeightedVector(qx, q.viewColumn(0), 2);
 assertEquals(Math.sqrt(0.5), v4.getWeight(), 1.0e-13);
 WeightedVector v5 = WeightedVector.project(q.viewColumn(0), qx);
 assertEquals(Math.sqrt(0.5), v5.getWeight(), 1.0e-13);
}

相关文章