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

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

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

Vector.aggregate介绍

[英]Generalized inner product - take two vectors, iterate over them both, using the combiner to combine together (and possibly map in some way) each pair of values, which are then aggregated with the previous accumulated value in the combiner.

Example: dot(other) could be expressed as aggregate(other, Plus, Times), and kernelized inner products (which are symmetric on the indices) work similarly.
[中]广义内积——取两个向量,对它们进行迭代,使用组合器将每对值组合在一起(可能以某种方式映射),然后与组合器中以前的累积值进行聚合。
例如:点(other)可以表示为聚合(other,Plus,Times),核化内积(在索引上是对称的)的工作原理类似。

代码示例

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

@Override
 public double apply(Vector v) {
  return v.aggregate(combiner, mapper);
 }
}).aggregate(combiner, Functions.IDENTITY);

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

@Override
public double aggregate(DoubleDoubleFunction aggregator, DoubleFunction map) {
 return delegate.aggregate(aggregator, map);
}

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

@Override
public double aggregate(DoubleDoubleFunction aggregator, DoubleFunction map) {
 return delegate.aggregate(aggregator, map);
}

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

@Override
public double aggregate(Vector other, DoubleDoubleFunction aggregator, DoubleDoubleFunction combiner) {
 return delegate.aggregate(other, aggregator, combiner);
}

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

@Override
public double aggregate(Vector other, DoubleDoubleFunction aggregator, DoubleDoubleFunction combiner) {
 return delegate.aggregate(other, aggregator, combiner);
}

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

/**
 * Collects the results of a function applied to each element of a matrix and then aggregated.
 *
 * @param combiner A function that combines the results of the mapper.
 * @param mapper   A function to apply to each element.
 * @return The result.
 */
@Override
public double aggregate(final DoubleDoubleFunction combiner, final DoubleFunction mapper) {
 return aggregateRows(new VectorFunction() {
  @Override
  public double apply(Vector v) {
   return v.aggregate(combiner, mapper);
  }
 }).aggregate(combiner, Functions.IDENTITY);
}

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

private static void assertEquals(Vector u1, Vector u2) {
 assertEquals(0, u1.minus(u2).aggregate(Functions.MAX, Functions.ABS), 1.0e-10);
}

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

double uberMax = L.viewDiagonal().aggregate(Functions.MAX, Functions.ABS);
for (int k = 0; k < n; k++) {
 double max = 0;
 double epsilon = 1.0e-10 * Math.max(uberMax, L.viewColumn(k).aggregate(Functions.MAX, Functions.ABS));

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

private void decompose(Matrix a) {
 int n = a.rowSize();
 L.assign(a);
 // column-wise submatrix cholesky with simple pivoting
 for (int k = 0; k < n; k++) {
  double akk = L.get(k, k);
  // set upper part of column to 0.
  L.viewColumn(k).viewPart(0, k).assign(0);
  double epsilon = 1.0e-10 * L.viewColumn(k).aggregate(Functions.MAX, Functions.ABS);
  if (akk <= epsilon) {
   // degenerate column case.  Set diagonal to 1, all others to zero
   L.viewColumn(k).viewPart(k, n - k).assign(0);
   isPositiveDefinite = false;
   // no need to subtract from remaining sub-matrix
  } else {
   // normalize column by diagonal element
   akk = Math.sqrt(Math.max(0, akk));
   L.set(k, k, akk);
   L.viewColumn(k).viewPart(k + 1, n - k - 1).assign(Functions.div(akk));
   // now subtract scaled version of column
   for (int j = k + 1; j < n; j++) {
    Vector columnJ = L.viewColumn(j).viewPart(j, n - j);
    Vector columnK = L.viewColumn(k).viewPart(j, n - j);
    columnJ.assign(columnK, Functions.minusMult(L.get(j, k)));
   }
  }
 }
}

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

@Test
public void testEigen() {
 Matrix a = new DenseSymmetricMatrix(new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, false);
 Matrix b = new DenseMatrix(a.numRows(), a.numCols());
 b.assign(a);
 assertEquals(0, a.minus(b).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
 EigenDecomposition edA = new EigenDecomposition(a);
 EigenDecomposition edB = new EigenDecomposition(b);
 System.out.println(edA.getV());
 assertEquals(0, edA.getV().minus(edB.getV()).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
 assertEquals(0, edA.getRealEigenvalues().minus(edA.getRealEigenvalues()).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
}

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

@Override
 public double apply(Vector v) {
  return v.aggregate(combiner, mapper);
 }
}).aggregate(combiner, Functions.IDENTITY);

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

v1.assign(dv1);
assertEquals(dv1.norm(2), Math.sqrt(v1.aggregate(Functions.PLUS, Functions.pow(2))), FUZZ);
assertEquals(dv1.dot(dv2), v1.aggregate(v2, Functions.PLUS, Functions.MULT), FUZZ);

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

/**
 *  Math.pow is clever about integer-valued doubles
 */
@Override
public double distance(Vector v1, Vector v2) {
 return Math.pow(v1.aggregate(v2, Functions.PLUS, Functions.minusAbsPow(exponent)), 1.0 / exponent);
}

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

/**
 *  Math.pow is clever about integer-valued doubles
 */
@Override
public double distance(Vector v1, Vector v2) {
 return Math.pow(v1.aggregate(v2, Functions.PLUS, Functions.minusAbsPow(exponent)), 1.0 / exponent);
}

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

@Override
public double distance(Vector v1, Vector v2) {
 if (v1.size() != v2.size()) {
  throw new CardinalityException(v1.size(), v2.size());
 }
 return v1.aggregate(v2, Functions.PLUS, Functions.MINUS_ABS);
}

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

@Override
public double distance(Vector v1, Vector v2) {
 if (v1.size() != v2.size()) {
  throw new CardinalityException(v1.size(), v2.size());
 }
 return v1.aggregate(v2, Functions.MAX_ABS, Functions.MINUS);
}

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

@Override
public double distance(Vector v1, Vector v2) {
 if (v1.size() != v2.size()) {
  throw new CardinalityException(v1.size(), v2.size());
 }
 return v1.aggregate(v2, Functions.PLUS, Functions.MINUS_ABS);
}

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

@Override
public double distance(Vector v1, Vector v2) {
 if (v1.size() != v2.size()) {
  throw new CardinalityException(v1.size(), v2.size());
 }
 return v1.aggregate(v2, Functions.MAX_ABS, Functions.MINUS);
}

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

@Override
public double distance(Vector v1, Vector v2) {
 if (v1.size() != v2.size()) {
  throw new CardinalityException(v1.size(), v2.size());
 }
 return v1.aggregate(v2, Functions.MAX_ABS, Functions.MINUS);
}

相关文章