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

x33g5p2x  于2022-01-25 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(108)

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

Matrix.aggregateColumns介绍

[英]Collects the results of a function applied to each column of a matrix.
[中]收集应用于矩阵每列的函数的结果。

代码示例

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

@Test
public void testAggregateCols() {
 Vector v = test.aggregateColumns(new VectorFunction() {
  @Override
  public double apply(Vector v) {
   return v.zSum();
  }
 });
 for (int i = 0; i < test.numCols(); i++) {
  assertEquals(test.viewColumn(i).zSum(), v.get(i), EPSILON);
 }
}

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

private void normalize(Matrix source, final double range) {
 final double max = source.aggregateColumns(new VectorFunction() {
  @Override
  public double apply(Vector column) {
   return column.maxValue();
  }
 }).maxValue();
 final double min = source.aggregateColumns(new VectorFunction() {
  @Override
  public double apply(Vector column) {
   return column.minValue();
  }
 }).minValue();
 source.assign(new DoubleFunction() {
  @Override
  public double apply(double value) {
   return (value - min) * range / (max - min);
  }
 });
}

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

@Test
public void testAggregateCols() {
 Vector v = test.aggregateColumns(new VectorFunction() {
  @Override
  public double apply(Vector v) {
   return v.zSum();
  }
 });
 for (int i = 0; i < test.numCols(); i++) {
  assertEquals(test.viewColumn(i).zSum(), v.get(i), EPSILON);
 }
}

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

int n = a.numCols();
Vector xi = a.aggregateColumns(new VectorFunction() {
 @Override
 public double apply(Vector v) {
Matrix qm = qr.getQ();
Vector s_q = qm.aggregateColumns(new VectorFunction() {
 @Override
 public double apply(Vector v) {

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

@Test
public void testInitialization() {
 // Start with super clusterable data.
 List<? extends WeightedVector> data = cubishTestData(0.01);
 // Just do initialization of ball k-means. This should drop a point into each of the clusters.
 BallKMeans r = new BallKMeans(new BruteSearch(new SquaredEuclideanDistanceMeasure()), 6, 20);
 r.cluster(data);
 // Put the centroids into a matrix.
 Matrix x = new DenseMatrix(6, 5);
 int row = 0;
 for (Centroid c : r) {
  x.viewRow(row).assign(c.viewPart(0, 5));
  row++;
 }
 // Verify that each column looks right. Should contain zeros except for a single 6.
 final Vector columnNorms = x.aggregateColumns(new VectorFunction() {
  @Override
  public double apply(Vector f) {
   // Return the sum of three discrepancy measures.
   return Math.abs(f.minValue()) + Math.abs(f.maxValue() - 6) + Math.abs(f.norm(1) - 6);
  }
 });
 // Verify all errors are nearly zero.
 assertEquals(0, columnNorms.norm(1) / columnNorms.size(), 0.1);
 // Verify that the centroids are a permutation of the original ones.
 SingularValueDecomposition svd = new SingularValueDecomposition(x);
 Vector s = svd.getS().viewDiagonal().assign(Functions.div(6));
 assertEquals(5, s.getLengthSquared(), 0.05);
 assertEquals(5, s.norm(1), 0.05);
}

相关文章