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

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

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

Matrix.viewPart介绍

[英]Return a view into part of a matrix. Changes to the view will change the original matrix.
[中]将视图返回到矩阵的一部分。对视图的更改将更改原始矩阵。

代码示例

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

@Test(expected = IndexException.class)
public void testViewPartIndexOver() {
 int[] offset = {1, 1};
 int[] size = {2, 2};
 test.viewPart(offset, size);
}

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

@Test(expected = IndexException.class)
public void testViewPartCardinality() {
 int[] offset = {1, 1};
 int[] size = {3, 3};
 test.viewPart(offset, size);
}

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

@Test(expected = IndexException.class)
public void testViewPartIndexUnder() {
 int[] offset = {-1, -1};
 int[] size = {2, 2};
 test.viewPart(offset, size);
}

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

@Test(expected = IndexException.class)
public void testViewPartIndexUnder() {
 int[] offset = {-1, -1};
 int[] size = {2, 2};
 test.viewPart(offset, size);
}

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

@Test(expected = IndexException.class)
public void testViewPartCardinality() {
 int[] offset = {1, 1};
 int[] size = {3, 3};
 test.viewPart(offset, size);
}

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

@Test(expected = IndexException.class)
public void testViewPartIndexOver() {
 int[] offset = {1, 1};
 int[] size = {2, 2};
 test.viewPart(offset, size);
}

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

/** Tests MAHOUT-1046 */
@Test
public void testMatrixViewBug() {
 Matrix m = test.viewPart(0, 3, 0, 2);
 // old bug would blow cookies with an index exception here.
 m = m.viewPart(2, 1, 0, 1);
 assertEquals(5.5, m.zSum(), 0);
}

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

q = qTmp.viewPart(0, rows, 0, min).clone();
} else {
 q = qTmp;

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

@Test
public void testRightVectors() {
 Matrix A = lowRankMatrix();
 SequentialBigSvd s = new SequentialBigSvd(A, 6);
 SingularValueDecomposition svd = new SingularValueDecomposition(A);
 Matrix v1 = svd.getV().viewPart(0, 20, 0, 3).assign(Functions.ABS);
 Matrix v2 = s.getV().viewPart(0, 20, 0, 3).assign(Functions.ABS);
 assertEquals(v1, v2);
}

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

@Test
public void testViewPart() {
 int[] offset = {1, 1};
 int[] size = {2, 1};
 Matrix view = test.viewPart(offset, size);
 for (int row = 0; row < view.rowSize(); row++) {
  for (int col = 0; col < view.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']',
     values[row + 2][col + 2], view.getQuick(row, col), EPSILON);
  }
 }
}

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

@Test
public void testLeftVectors() {
 Matrix A = lowRankMatrix();
 SequentialBigSvd s = new SequentialBigSvd(A, 8);
 SingularValueDecomposition svd = new SingularValueDecomposition(A);
 // can only check first few singular vectors because once the singular values
 // go to zero, the singular vectors are not uniquely determined
 Matrix u1 = svd.getU().viewPart(0, 20, 0, 4).assign(Functions.ABS);
 Matrix u2 = s.getU().viewPart(0, 20, 0, 4).assign(Functions.ABS);
 assertEquals(0, u1.minus(u2).aggregate(Functions.PLUS, Functions.ABS), 1.0e-9);
}

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

/**
 * Predict the power law growth in number of unique samples from the first few data points.
 * Also check that the fitted growth coefficient is about right.
 *
 * @param m
 * @param currentIndex        Total data points seen so far.  Unique values should be log(currentIndex)*expectedCoefficient + offset.
 * @param expectedCoefficient What slope do we expect.
 * @return The predicted value for log(currentIndex)
 */
private static double predictSize(Matrix m, int currentIndex, double expectedCoefficient) {
 int rows = m.rowSize();
 Matrix a = m.viewPart(0, rows, 1, 2);
 Matrix b = m.viewPart(0, rows, 0, 1);
 Matrix ata = a.transpose().times(a);
 Matrix atb = a.transpose().times(b);
 QRDecomposition s = new QRDecomposition(ata);
 Matrix r = s.solve(atb).transpose();
 assertEquals(expectedCoefficient, r.get(0, 0), 0.2);
 return r.times(new DenseVector(new double[]{Math.log(currentIndex), 1})).get(0);
}

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

double predict5 = predictSize(m5.viewPart(0, k, 0, 3), i, 0.5);
assertEquals(predict5, Math.log(s5.size()), 1);
double predict9 = predictSize(m9.viewPart(0, k, 0, 3), i, 0.9);
assertEquals(predict9, Math.log(s9.size()), 1);

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

@Test
public void testViewPart() {
 int[] offset = {1, 1};
 int[] size = {2, 1};
 Matrix view = test.viewPart(offset, size);
 assertEquals(2, view.rowSize());
 assertEquals(1, view.columnSize());
 for (int row = 0; row < view.rowSize(); row++) {
  for (int col = 0; col < view.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']',
     values[row + 1][col + 1], view.get(row, col), EPSILON);
  }
 }
}

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

@Test
public void testBasics() {
 Matrix a = new DenseSymmetricMatrix(new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, false);
 System.out.println(a.toString());
 assertEquals(0, a.viewDiagonal().minus(new DenseVector(new double[]{1, 5, 8, 10})).norm(1), 1.0e-10);
 assertEquals(0, a.viewPart(0, 3, 1, 3).viewDiagonal().minus(
   new DenseVector(new double[]{2, 6, 9})).norm(1), 1.0e-10);
 assertEquals(4, a.get(0, 3), 1.0e-10);
 System.out.println(a);
 Matrix m = new DenseMatrix(4, 4).assign(a);
 assertEquals(0, m.minus(a).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
 System.out.println(m);
 assertEquals(0, m.transpose().times(m).minus(a.transpose().times(a)).aggregate(
   Functions.PLUS, Functions.ABS), 1.0e-10);
 System.out.println(a.plus(a));
 assertEquals(0, m.plus(m).minus(a.plus(a)).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
}

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

@Test
public void rank1() {
 Matrix x = new DenseMatrix(3, 3);
 x.viewRow(0).assign(new double[]{1, 2, 3});
 x.viewRow(1).assign(new double[]{2, 4, 6});
 x.viewRow(2).assign(new double[]{3, 6, 9});
 CholeskyDecomposition rr = new CholeskyDecomposition(x.transpose().times(x), false);
 assertEquals(0, new DenseVector(new double[]{3.741657, 7.483315, 11.22497}).aggregate(rr.getL().transpose().viewRow(0), Functions.PLUS, new DoubleDoubleFunction() {
  @Override
  public double apply(double arg1, double arg2) {
   return Math.abs(arg1) - Math.abs(arg2);
  }
 }), 1.0e-5);
 assertEquals(0, rr.getL().viewPart(0, 3, 1, 2).aggregate(Functions.PLUS, Functions.ABS), 1.0e-9);
}

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

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

@Test
public void testBasics() {
 Matrix a = new UpperTriangular(new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, false);
 assertEquals(0, a.viewDiagonal().minus(new DenseVector(new double[]{1, 5, 8, 10})).norm(1), 1.0e-10);
 assertEquals(0, a.viewPart(0, 3, 1, 3).viewDiagonal().minus(
   new DenseVector(new double[]{2, 6, 9})).norm(1), 1.0e-10);
 assertEquals(4, a.get(0, 3), 1.0e-10);
 print(a);
 Matrix m = new DenseMatrix(4, 4).assign(a);
 assertEquals(0, m.minus(a).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
 print(m);
 assertEquals(0, m.transpose().times(m).minus(a.transpose().times(a)).aggregate(
   Functions.PLUS, Functions.ABS), 1.0e-10);
 assertEquals(0, m.plus(m).minus(a.plus(a)).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
}

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

@Test
public void testLeftVectors() throws IOException {
 Matrix A = lowRankMatrixInMemory(20, 20);
 SequentialBigSvd s = new SequentialBigSvd(A, 6);
 SingularValueDecomposition svd = new SingularValueDecomposition(A);
 // can only check first few singular vectors
 Matrix u1 = svd.getU().viewPart(0, 20, 0, 3).assign(Functions.ABS);
 Matrix u2 = s.getU().viewPart(0, 20, 0, 3).assign(Functions.ABS);
 assertEquals(u1, u2);
}

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

@Test
public void testRightVectors() throws IOException {
 Matrix A = lowRankMatrixInMemory(20, 20);
 SequentialBigSvd s = new SequentialBigSvd(A, 6);
 SingularValueDecomposition svd = new SingularValueDecomposition(A);
 Matrix v1 = svd.getV().viewPart(0, 20, 0, 3).assign(Functions.ABS);
 Matrix v2 = s.getV().viewPart(0, 20, 0, 3).assign(Functions.ABS);
 assertEquals(v1, v2);
}

相关文章