Java Code Examples for org.apache.commons.math.linear.RealMatrix#getColumn()
The following examples show how to use
org.apache.commons.math.linear.RealMatrix#getColumn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingularValueSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** test solve */ public void testSolve() { DecompositionSolver solver = new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)).getSolver(); RealMatrix b = MatrixUtils.createRealMatrix(new double[][] { { 1, 2, 3 }, { 0, -5, 1 } }); RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] { { -8.0 / 25.0, -263.0 / 75.0, -29.0 / 75.0 }, { 19.0 / 25.0, 78.0 / 25.0, 49.0 / 25.0 } }); // using RealMatrix assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), normTolerance); // using double[] for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, new ArrayRealVector(solver.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using Array2DRowRealMatrix for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, solver.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using RealMatrix with an alternate implementation for (int i = 0; i < b.getColumnDimension(); ++i) { ArrayRealVectorTest.RealVectorTestImpl v = new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i)); assertEquals(0, solver.solve(v).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } }
Example 2
Source File: PearsonsCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new PearsonsCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new PearsonsCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 3
Source File: SpearmansRankCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override @Test public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); SpearmansCorrelation corrInstance = new SpearmansCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); Assert.assertEquals(new SpearmansCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new SpearmansCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 4
Source File: SpearmansRankCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); SpearmansCorrelation corrInstance = new SpearmansCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new SpearmansCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new SpearmansCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 5
Source File: SpearmansRankCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); SpearmansCorrelation corrInstance = new SpearmansCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new SpearmansCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new SpearmansCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 6
Source File: PearsonsCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new PearsonsCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new PearsonsCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 7
Source File: SpearmansRankCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); SpearmansCorrelation corrInstance = new SpearmansCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new SpearmansCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new SpearmansCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 8
Source File: PearsonsCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); Assert.assertEquals(new PearsonsCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new PearsonsCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 9
Source File: PearsonsCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new PearsonsCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new PearsonsCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 10
Source File: LUSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** test solve */ public void testSolve() { DecompositionSolver solver = new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver(); RealMatrix b = MatrixUtils.createRealMatrix(new double[][] { { 1, 0 }, { 2, -5 }, { 3, 1 } }); RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] { { 19, -71 }, { -6, 22 }, { -2, 9 } }); // using RealMatrix assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), 1.0e-13); // using double[] for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, new ArrayRealVector(solver.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using ArrayRealVector for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, solver.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using RealVector with an alternate implementation for (int i = 0; i < b.getColumnDimension(); ++i) { ArrayRealVectorTest.RealVectorTestImpl v = new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i)); assertEquals(0, solver.solve(v).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } }
Example 11
Source File: SpearmansRankCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); SpearmansCorrelation corrInstance = new SpearmansCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new SpearmansCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new SpearmansCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 12
Source File: PearsonsCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new PearsonsCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new PearsonsCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 13
Source File: SpearmansRankCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); SpearmansCorrelation corrInstance = new SpearmansCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new SpearmansCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new SpearmansCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 14
Source File: SpearmansRankCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); SpearmansCorrelation corrInstance = new SpearmansCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new SpearmansCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new SpearmansCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 15
Source File: PearsonsCorrelationTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testConsistency() { RealMatrix matrix = createRealMatrix(longleyData, 16, 7); PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix); double[][] data = matrix.getData(); double[] x = matrix.getColumn(0); double[] y = matrix.getColumn(1); assertEquals(new PearsonsCorrelation().correlation(x, y), corrInstance.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); TestUtils.assertEquals("Correlation matrix", corrInstance.getCorrelationMatrix(), new PearsonsCorrelation().computeCorrelationMatrix(data), Double.MIN_VALUE); }
Example 16
Source File: LUSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** test solve */ public void testSolve() { DecompositionSolver solver = new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver(); RealMatrix b = MatrixUtils.createRealMatrix(new double[][] { { 1, 0 }, { 2, -5 }, { 3, 1 } }); RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] { { 19, -71 }, { -6, 22 }, { -2, 9 } }); // using RealMatrix assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), 1.0e-13); // using double[] for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, new ArrayRealVector(solver.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using ArrayRealVector for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, solver.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using RealVector with an alternate implementation for (int i = 0; i < b.getColumnDimension(); ++i) { ArrayRealVectorTest.RealVectorTestImpl v = new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i)); assertEquals(0, solver.solve(v).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } }
Example 17
Source File: CholeskySolverTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** test solve */ public void testSolve() throws MathException { DecompositionSolver solver = new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver(); RealMatrix b = MatrixUtils.createRealMatrix(new double[][] { { 78, -13, 1 }, { 414, -62, -1 }, { 1312, -202, -37 }, { 2989, -542, 145 }, { 5510, -1465, 201 } }); RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] { { 1, 0, 1 }, { 0, 1, 1 }, { 2, 1, -4 }, { 2, 2, 2 }, { 5, -3, 0 } }); // using RealMatrix assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), 1.0e-13); // using double[] for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, new ArrayRealVector(solver.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using ArrayRealVector for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, solver.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using RealVector with an alternate implementation for (int i = 0; i < b.getColumnDimension(); ++i) { ArrayRealVectorTest.RealVectorTestImpl v = new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i)); assertEquals(0, solver.solve(v).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } }
Example 18
Source File: EigenSolverTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** test solve */ public void testSolve() { RealMatrix m = MatrixUtils.createRealMatrix(new double[][] { { 91, 5, 29, 32, 40, 14 }, { 5, 34, -1, 0, 2, -1 }, { 29, -1, 12, 9, 21, 8 }, { 32, 0, 9, 14, 9, 0 }, { 40, 2, 21, 9, 51, 19 }, { 14, -1, 8, 0, 19, 14 } }); DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver(); RealMatrix b = MatrixUtils.createRealMatrix(new double[][] { { 1561, 269, 188 }, { 69, -21, 70 }, { 739, 108, 63 }, { 324, 86, 59 }, { 1624, 194, 107 }, { 796, 69, 36 } }); RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] { { 1, 2, 1 }, { 2, -1, 2 }, { 4, 2, 3 }, { 8, -1, 0 }, { 16, 2, 0 }, { 32, -1, 0 } }); // using RealMatrix assertEquals(0, es.solve(b).subtract(xRef).getNorm(), 2.0e-12); // using double[] for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, new ArrayRealVector(es.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(), 2.0e-11); } // using Array2DRowRealMatrix for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, es.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(), 2.0e-11); } // using RealMatrix with an alternate implementation for (int i = 0; i < b.getColumnDimension(); ++i) { ArrayRealVectorTest.RealVectorTestImpl v = new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i)); assertEquals(0, es.solve(v).subtract(xRef.getColumnVector(i)).getNorm(), 2.0e-11); } }
Example 19
Source File: EigenSolverTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** test solve */ public void testSolve() { RealMatrix m = MatrixUtils.createRealMatrix(new double[][] { { 91, 5, 29, 32, 40, 14 }, { 5, 34, -1, 0, 2, -1 }, { 29, -1, 12, 9, 21, 8 }, { 32, 0, 9, 14, 9, 0 }, { 40, 2, 21, 9, 51, 19 }, { 14, -1, 8, 0, 19, 14 } }); DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver(); RealMatrix b = MatrixUtils.createRealMatrix(new double[][] { { 1561, 269, 188 }, { 69, -21, 70 }, { 739, 108, 63 }, { 324, 86, 59 }, { 1624, 194, 107 }, { 796, 69, 36 } }); RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] { { 1, 2, 1 }, { 2, -1, 2 }, { 4, 2, 3 }, { 8, -1, 0 }, { 16, 2, 0 }, { 32, -1, 0 } }); // using RealMatrix assertEquals(0, es.solve(b).subtract(xRef).getNorm(), 2.0e-12); // using double[] for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, new ArrayRealVector(es.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(), 2.0e-11); } // using Array2DRowRealMatrix for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, es.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(), 2.0e-11); } // using RealMatrix with an alternate implementation for (int i = 0; i < b.getColumnDimension(); ++i) { ArrayRealVectorTest.RealVectorTestImpl v = new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i)); assertEquals(0, es.solve(v).subtract(xRef.getColumnVector(i)).getNorm(), 2.0e-11); } }
Example 20
Source File: CholeskySolverTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** test solve */ public void testSolve() throws MathException { DecompositionSolver solver = new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver(); RealMatrix b = MatrixUtils.createRealMatrix(new double[][] { { 78, -13, 1 }, { 414, -62, -1 }, { 1312, -202, -37 }, { 2989, -542, 145 }, { 5510, -1465, 201 } }); RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] { { 1, 0, 1 }, { 0, 1, 1 }, { 2, 1, -4 }, { 2, 2, 2 }, { 5, -3, 0 } }); // using RealMatrix assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), 1.0e-13); // using double[] for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, new ArrayRealVector(solver.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using ArrayRealVector for (int i = 0; i < b.getColumnDimension(); ++i) { assertEquals(0, solver.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } // using RealVector with an alternate implementation for (int i = 0; i < b.getColumnDimension(); ++i) { ArrayRealVectorTest.RealVectorTestImpl v = new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i)); assertEquals(0, solver.solve(v).subtract(xRef.getColumnVector(i)).getNorm(), 1.0e-13); } }