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

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

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

Matrix.minus介绍

[英]Return a new matrix containing the element by element difference of the recipient and the argument
[中]返回一个新矩阵,其中包含接收者和参数的元素差

代码示例

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

@Test(expected = CardinalityException.class)
public void testMinusCardinality() {
 test.minus(test.transpose());
}

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

@Test(expected = CardinalityException.class)
public void testMinusCardinality() {
 test.minus(test.transpose());
}

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

private static void assertEquals(Matrix ref, Matrix actual, double epsilon) {
 assertEquals(0, ref.minus(actual).aggregate(Functions.MAX, Functions.ABS), epsilon);
}

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

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

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

private static void check(String msg, Matrix a, Matrix b) {
 Assert.assertEquals(msg, 0, a.minus(b).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
}

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

private static void assertEquals(Matrix ref, Matrix actual, double epsilon) {
 assertEquals(0, ref.minus(actual).aggregate(Functions.MAX, Functions.ABS), epsilon);
}

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

@Test
public void testTransposeView() {
 Matrix m = Matrices.gaussianView(5, 6, 1234L);
 Matrix controlM = new DenseMatrix(5, 6).assign(m);
 System.out.printf("M=\n%s\n", m);
 System.out.printf("controlM=\n%s\n", controlM);
 Matrix mtm = Matrices.transposedView(m).times(m);
 Matrix controlMtm = controlM.transpose().times(controlM);
 System.out.printf("M'M=\n%s\n", mtm);
 Matrix diff = mtm.minus(controlMtm);
 assertEquals(0, diff.aggregate(Functions.PLUS, Functions.ABS), 1e-10);
}

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

@Test
public void testMinus() {
 Matrix value = test.minus(test);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', 0.0, value.getQuick(row, col), EPSILON);
  }
 }
}

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

@Test
public void testGaussianView() {
 Matrix m1 = Matrices.gaussianView(5, 6, 1234);
 Matrix m2 = Matrices.gaussianView(5, 6, 1234);
 Matrix diff = m1.minus(m2);
 assertEquals(0, diff.aggregate(Functions.PLUS, Functions.ABS), 1e-10);
}

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

@Test
public void testMinus() {
 Matrix value = test.minus(test);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', 0.0, value.getQuick(
     row, col), EPSILON);
  }
 }
}

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

@Test
public void testSvdHang() throws IOException, InterruptedException, ExecutionException, TimeoutException {
 System.out.printf("starting hanging-svd\n");
 final Matrix m = readTsv("hanging-svd.tsv");
 SingularValueDecomposition svd = new SingularValueDecomposition(m);
 assertEquals(0, m.minus(svd.getU().times(svd.getS()).times(svd.getV().transpose())).aggregate(Functions.PLUS, Functions.ABS), 1e-10);
 System.out.printf("No hang\n");
}

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

@Test
public void test2() {
 // Test matrix from Nicholas Higham's paper at http://eprints.ma.man.ac.uk/1199/01/covered/MIMS_ep2008_116.pdf
 double[][] values = new double[3][];
 values[0] = new double[]{1, -1, 1};
 values[1] = new double[]{-1, 1, -1};
 values[2] = new double[]{1, -1, 2};
 Matrix A = new DenseMatrix(values);
 // without pivoting
 CholeskyDecomposition cd = new CholeskyDecomposition(A, false);
 assertEquals(0, cd.getL().times(cd.getL().transpose()).minus(A).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
 // with pivoting
 cd = new CholeskyDecomposition(A);
 assertEquals(0, cd.getL().times(cd.getL().transpose()).minus(A).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
}

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

public static void checkOrthogonal(Matrix m) {
 Matrix mTm = m.transpose().times(m);
 Matrix id  = new DenseMatrix(mTm.numRows(),mTm.numRows());
 for (int i = 0; i < mTm.numRows(); i++) {
  id.set(i, i, 1);
 }
 assertEquals(0, Algebra.getNorm(mTm.minus(id)), NORM_TOLERANCE);
}

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

@Test(timeout=50000)
 public void testTimesCorrect() {
  Random raw = RandomUtils.getRandom();

  // build two large sequential sparse matrices and multiply them
  Matrix x = new SparseRowMatrix(100, 2000, false)
   .assign(Functions.random());

  Matrix y = new SparseRowMatrix(2000, 100, false)
   .assign(Functions.random());

  Matrix xd = new DenseMatrix(100, 2000).assign(x);
  Matrix yd = new DenseMatrix(2000, 100).assign(y);
  assertEquals(0, xd.times(yd).minus(x.times(y)).aggregate(Functions.PLUS, Functions.ABS), 1e-15);
  assertEquals(0, x.times(yd).minus(x.times(y)).aggregate(Functions.PLUS, Functions.ABS), 1e-15);
  assertEquals(0, xd.times(y).minus(x.times(y)).aggregate(Functions.PLUS, Functions.ABS), 1e-15);
 }
}

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

@Test
public void testRankDeficient() {
 Matrix A = rank4Matrix();
 CholeskyDecomposition cd = new CholeskyDecomposition(A);
 PivotedMatrix Ax = new PivotedMatrix(A, cd.getPivot());
 CholeskyDecomposition cd2 = new CholeskyDecomposition(Ax, false);
 assertEquals(0, cd2.getL().times(cd2.getL().transpose()).minus(Ax).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
 assertEquals(0, cd.getL().times(cd.getL().transpose()).minus(A).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
 Assert.assertFalse(cd.isPositiveDefinite());
 Matrix L = cd.getL();
 Matrix Abar = L.times(L.transpose());
 double error = A.minus(Abar).aggregate(Functions.MAX, Functions.ABS);
 Assert.assertEquals(0, error, 1.0e-10);
}

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

@Test
public void testSymmetricUniformView() {
 Matrix m1 = Matrices.symmetricUniformView(5, 6, 1234);
 Matrix m2 = Matrices.symmetricUniformView(5, 6, 1234);
 for (int row = 0; row < m1.numRows(); row++) {
  for (int col = 0; col < m1.numCols(); col++) {
   assertTrue(m1.getQuick(row, col) >= -1.0);
   assertTrue(m1.getQuick(row, col) < 1.0);
  }
 }
 Matrix diff = m1.minus(m2);
 assertEquals(0, diff.aggregate(Functions.PLUS, Functions.ABS), 1e-10);
}

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

@Test
public void testUniformView() {
 Matrix m1 = Matrices.uniformView(5, 6, 1234);
 Matrix m2 = Matrices.uniformView(5, 6, 1234);
 for (int row = 0; row < m1.numRows(); row++) {
  for (int col = 0; col < m1.numCols(); col++) {
   assertTrue(m1.getQuick(row, col) >= 0.0);
   assertTrue(m1.getQuick(row, col) < 1.0);
  }
 }
 Matrix diff = m1.minus(m2);
 assertEquals(0, diff.aggregate(Functions.PLUS, Functions.ABS), 1e-10);
}

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

@Test
public void randomMatrix() {
 Matrix a = new DenseMatrix(60, 60).assign(Functions.random());
 QRDecomposition qr = new QRDecomposition(a);
 // how close is Q to actually being orthornormal?
 double maxIdent = qr.getQ().transpose().times(qr.getQ()).viewDiagonal().assign(Functions.plus(-1)).norm(1);
 assertEquals(0, maxIdent, 1.0e-13);
 // how close is Q R to the original value of A?
 Matrix z = qr.getQ().times(qr.getR()).minus(a);
 double maxError = z.aggregate(Functions.MIN, Functions.ABS);
 assertEquals(0, maxError, 1.0e-13);
}

相关文章