/** * Return an empty matrix of the same underlying class as the receiver * * @return a Matrix */ @Override public Matrix like() { return new PivotedMatrix(base.like()); }
/** * Returns an empty matrix of the same underlying class as the receiver and of the specified * size. * * @param rows the int number of rows * @param columns the int number of columns */ @Override public Matrix like(int rows, int columns) { return new PivotedMatrix(base.like(rows, columns)); }
public CholeskyDecomposition(Matrix a, boolean pivot) { int rows = a.rowSize(); L = new PivotedMatrix(new DenseMatrix(rows, rows)); // must be square Preconditions.checkArgument(rows == a.columnSize(), "Must be a Square Matrix"); if (pivot) { decomposeWithPivoting(a); } else { decompose(a); } }
@Override public Matrix matrixFactory(double[][] values) { Matrix base = new DenseMatrix(values); // for general tests, we just make a scrambled matrix and fill it // with the standard data. Then we can test the details of the // row and/or column swapping separately. PivotedMatrix pm = new PivotedMatrix(base.like()); pm.swap(0, 1); pm.swapRows(1, 2); pm.assign(base); return pm; }
@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); }
@Test public void testSwap() { Matrix m = new DenseMatrix(10, 10); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { m.set(i, j, 10 * i + j); } } PivotedMatrix pm = new PivotedMatrix(m); pm.swap(3, 5); assertEquals(0, pm.viewDiagonal().minus( new DenseVector(new double[]{0, 11, 22, 55, 44, 33, 66, 77, 88, 99})).norm(1), 1.0e-10); pm.swap(2, 7); assertEquals(0, pm.viewDiagonal().minus( new DenseVector(new double[]{0, 11, 77, 55, 44, 33, 66, 22, 88, 99})).norm(1), 1.0e-10); pm.swap(5, 8); assertEquals(0, pm.viewColumn(4).minus( new DenseVector(new double[]{4.0,14.0,74.0,54.0,44.0,84.0,64.0,24.0,34.0,94.0})).norm(1), 1.0e-10); assertEquals(0, pm.viewDiagonal().minus( new DenseVector(new double[]{0, 11, 77, 55, 44, 88, 66, 22, 33, 99})).norm(1), 1.0e-10); } }
/** * Return an empty matrix of the same underlying class as the receiver * * @return a Matrix */ @Override public Matrix like() { return new PivotedMatrix(base.like()); }
/** * Returns an empty matrix of the same underlying class as the receiver and of the specified * size. * * @param rows the int number of rows * @param columns the int number of columns */ @Override public Matrix like(int rows, int columns) { return new PivotedMatrix(base.like(rows, columns)); }
/** * Return an empty matrix of the same underlying class as the receiver * * @return a Matrix */ @Override public Matrix like() { return new PivotedMatrix(base.like()); }
/** * Returns an empty matrix of the same underlying class as the receiver and of the specified * size. * * @param rows the int number of rows * @param columns the int number of columns */ @Override public Matrix like(int rows, int columns) { return new PivotedMatrix(base.like(rows, columns)); }
public CholeskyDecomposition(Matrix a, boolean pivot) { int rows = a.rowSize(); L = new PivotedMatrix(new DenseMatrix(rows, rows)); // must be square Preconditions.checkArgument(rows == a.columnSize(), "Must be a Square Matrix"); if (pivot) { decomposeWithPivoting(a); } else { decompose(a); } }
public CholeskyDecomposition(Matrix a, boolean pivot) { int rows = a.rowSize(); L = new PivotedMatrix(new DenseMatrix(rows, rows)); // must be square Preconditions.checkArgument(rows == a.columnSize()); if (pivot) { decomposeWithPivoting(a); } else { decompose(a); } }
@Override public Matrix matrixFactory(double[][] values) { Matrix base = new DenseMatrix(values); // for general tests, we just make a scrambled matrix and fill it // with the standard data. Then we can test the details of the // row and/or column swapping separately. PivotedMatrix pm = new PivotedMatrix(base.like()); pm.swap(0, 1); pm.swapRows(1, 2); pm.assign(base); return pm; }
@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); }
@Test public void testSwap() { Matrix m = new DenseMatrix(10, 10); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { m.set(i, j, 10 * i + j); } } PivotedMatrix pm = new PivotedMatrix(m); pm.swap(3, 5); assertEquals(0, pm.viewDiagonal().minus( new DenseVector(new double[]{0, 11, 22, 55, 44, 33, 66, 77, 88, 99})).norm(1), 1.0e-10); pm.swap(2, 7); assertEquals(0, pm.viewDiagonal().minus( new DenseVector(new double[]{0, 11, 77, 55, 44, 33, 66, 22, 88, 99})).norm(1), 1.0e-10); pm.swap(5, 8); assertEquals(0, pm.viewColumn(4).minus( new DenseVector(new double[]{4.0,14.0,74.0,54.0,44.0,84.0,64.0,24.0,34.0,94.0})).norm(1), 1.0e-10); assertEquals(0, pm.viewDiagonal().minus( new DenseVector(new double[]{0, 11, 77, 55, 44, 88, 66, 22, 33, 99})).norm(1), 1.0e-10); } }