Java Code Examples for org.apache.commons.math3.linear.RealMatrix#setColumnMatrix()
The following examples show how to use
org.apache.commons.math3.linear.RealMatrix#setColumnMatrix() .
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: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }
Example 2
Source File: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }
Example 3
Source File: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }
Example 4
Source File: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }
Example 5
Source File: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }
Example 6
Source File: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }
Example 7
Source File: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }
Example 8
Source File: CovarianceTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that diagonal entries are consistent with Variance computation and matrix matches * column-by-column covariances */ @Test public void testConsistency() { final RealMatrix matrix = createRealMatrix(swissData, 47, 5); final RealMatrix covarianceMatrix = new Covariance(matrix).getCovarianceMatrix(); // Variances on the diagonal Variance variance = new Variance(); for (int i = 0; i < 5; i++) { Assert.assertEquals(variance.evaluate(matrix.getColumn(i)), covarianceMatrix.getEntry(i,i), 10E-14); } // Symmetry, column-consistency Assert.assertEquals(covarianceMatrix.getEntry(2, 3), new Covariance().covariance(matrix.getColumn(2), matrix.getColumn(3), true), 10E-14); Assert.assertEquals(covarianceMatrix.getEntry(2, 3), covarianceMatrix.getEntry(3, 2), Double.MIN_VALUE); // All columns same -> all entries = column variance RealMatrix repeatedColumns = new Array2DRowRealMatrix(47, 3); for (int i = 0; i < 3; i++) { repeatedColumns.setColumnMatrix(i, matrix.getColumnMatrix(0)); } RealMatrix repeatedCovarianceMatrix = new Covariance(repeatedColumns).getCovarianceMatrix(); double columnVariance = variance.evaluate(matrix.getColumn(0)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.assertEquals(columnVariance, repeatedCovarianceMatrix.getEntry(i, j), 10E-14); } } // Check bias-correction defaults double[][] data = matrix.getData(); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data),Double.MIN_VALUE); TestUtils.assertEquals("Covariances", covarianceMatrix, new Covariance().computeCovarianceMatrix(data, true),Double.MIN_VALUE); double[] x = data[0]; double[] y = data[1]; Assert.assertEquals(new Covariance().covariance(x, y), new Covariance().covariance(x, y, true), Double.MIN_VALUE); }