@Override public Matrix assign(double value) { return m.assign(value); }
@Override public Matrix assign(DoubleFunction function) { return m.assign(function); }
/** * Return the eigenvector matrix * * @return V */ public Matrix getV() { return v.like().assign(v); }
@Test(expected = CardinalityException.class) public void testAssignMatrixBinaryFunctionCardinality() { test.assign(test.transpose(), Functions.PLUS); }
@Test(expected = CardinalityException.class) public void testAssignDoubleArrayArrayCardinality() { test.assign(new double[test.rowSize() + 1][test.columnSize()]); }
@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); }
@Test public void testAssignDouble() { test.assign(4.53); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', 4.53, test.getQuick( row, col), EPSILON); } } }
@Test public void testAssignDouble() { test.assign(4.53); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', 4.53, test.getQuick( row, col), EPSILON); } } }
@Test public void testAssignDoubleArrayArray() { test.assign(new double[3][2]); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', 0.0, test.getQuick(row, col), EPSILON); } } }
@Test public void testAssignUnaryFunction() { test.assign(Functions.NEGATE); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', -values[row + 1][col + 1], test.getQuick(row, col), EPSILON); } } }
@Test public void testAssignDoubleArrayArray() { test.assign(new double[3][2]); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', 0.0, test.getQuick(row, col), EPSILON); } } }
@Test public void testAssignMatrixBinaryFunction() { test.assign(test, Functions.PLUS); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', 2 * values[row][col], test.getQuick(row, col), EPSILON); } } }
@Test public void testAssignMatrixBinaryFunction() { test.assign(test, Functions.PLUS); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', 2 * values[row + 1][col + 1], test.getQuick(row, col), EPSILON); } } }
@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); }
@Test public void testAssignUnaryFunction() { test.assign(Functions.mult(-1)); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', -values[row][col], test .getQuick(row, col), EPSILON); } } }
@Test public void testAssignMatrix() { Matrix value = test.like(); value.assign(test); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', test.getQuick(row, col), value.getQuick(row, col), EPSILON); } } }
@Test public void testAssignMatrix() { Matrix value = test.like(); value.assign(test); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', test.getQuick(row, col), value.getQuick(row, col), EPSILON); } } }
@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); }