public static void assertEquals( RealMatrix32F A , RealMatrix32F B , float tol ) { assertShape(A,B); for( int i = 0; i < A.getNumRows(); i++ ){ for( int j = 0; j < A.getNumCols(); j++ ) { float valA = A.get(i,j); float valB = B.get(i,j); assertTrue(!Float.isNaN(valA) && !Float.isNaN(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(!Float.isInfinite(valA) && !Float.isInfinite(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"At ("+i+","+j+") A = "+valA+" B = "+valB); } } }
/** * Checks to see if every element in A is countable. A doesn't have any element with * a value of NaN or infinite. * * @param A Matrix */ public static void assertCountable( SimpleMatrix A ) { EjmlUnitTests.assertCountable(A.getMatrix()); }
/** * <p> * Checks to see if A and B have the same shape. * </p> * * @param A Matrix * @param B Matrix */ public static void assertShape( ReshapeMatrix64F A , ReshapeMatrix64F B ) { assertTrue( A.numRows == B.numRows , "Number of rows do not match"); assertTrue( A.numCols == B.numCols , "Number of columns do not match"); }
/** * <p> * Checks to see if each element in the matrices are within tolerance of each other and countable: * </p> * * <p> * The two matrices are identical with in tolerance if:<br> * |a<sub>ij</sub> - b<sub>ij</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEquals( SimpleMatrix A , SimpleMatrix B , double tol ) { EjmlUnitTests.assertEquals(A.getMatrix(), B.getMatrix(), tol); } }
/** * <p> * Checks to see if A and B have the same shape. * </p> * * @param A Matrix * @param B Matrix */ public static void assertShape( SimpleMatrix A , SimpleMatrix B ) { EjmlUnitTests.assertShape(A.getMatrix(), B.getMatrix()); }
/** * <p> * Checks to see if each element in the matrix is within tolerance of each other: * </p> * * <p> * The two matrices are identical with in tolerance if:<br> * |a<sub>ij</sub> - b<sub>ij</sub>| ≤ tol * </p> * * <p> * In addition if an element is NaN or infinite in one matrix it must be the same in the other. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEqualsUncountable( SimpleMatrix A , SimpleMatrix B , double tol ) { EjmlUnitTests.assertEqualsUncountable(A.getMatrix(), B.getMatrix(), tol); }
/** * <p> * Checks to see if A and B have the same shape. * </p> * * @param A Matrix * @param B Matrix */ public static void assertShape( ReshapeMatrix64F A , ReshapeMatrix64F B ) { assertTrue( A.numRows == B.numRows , "Number of rows do not match"); assertTrue( A.numCols == B.numCols , "Number of columns do not match"); }
@ContinuousIntegrationTest(estimatedDuration = 0.1) @Test(timeout=300000) public void testBackAndForthSymmetricMatrix() { List<List<YoDouble>> yoArray = new ArrayList<List<YoDouble>>(); int size = 50; String prefix = "test"; YoVariableRegistry registry = new YoVariableRegistry("test"); Random random = new Random(1235612L); DenseMatrix64F matrix = RandomMatrices.createSymmPosDef(size, random); DenseMatrix64F matrixBack = new DenseMatrix64F(size, size); MatrixYoVariableConversionTools.populateYoVariablesSymmetricMatrix(yoArray, size, prefix, registry); MatrixYoVariableConversionTools.storeInYoVariablesSymmetric(matrix, yoArray); MatrixYoVariableConversionTools.getFromYoVariablesSymmetric(matrixBack, yoArray); EjmlUnitTests.assertEquals(matrix, matrixBack, 1e-12); } }
public static void assertEquals( ComplexMatrix64F A , ComplexMatrix64F B , double tol ) { assertShape(A,B); Complex64F a = new Complex64F(); Complex64F b = new Complex64F(); for( int i = 0; i < A.getNumRows(); i++ ){ for( int j = 0; j < A.getNumCols(); j++ ) { A.get(i, j, a); B.get(i, j, b); assertTrue(!Double.isNaN(a.real) && !Double.isNaN(b.real) ,"Real At ("+i+","+j+") A = "+a.real+" B = "+b.real); assertTrue(!Double.isInfinite(a.real) && !Double.isInfinite(b.real) ,"Real At ("+i+","+j+") A = "+a.real+" B = "+b.real); assertTrue(Math.abs( a.real-b.real) <= tol,"Real At ("+i+","+j+") A = "+a.real+" B = "+b.real); assertTrue(!Double.isNaN(a.imaginary) && !Double.isNaN(b.imaginary) ,"Img At ("+i+","+j+") A = "+a.imaginary+" B = "+b.imaginary); assertTrue(!Double.isInfinite(a.imaginary) && !Double.isInfinite(b.imaginary) ,"Img At ("+i+","+j+") A = "+a.imaginary+" B = "+b.imaginary); assertTrue(Math.abs( a.imaginary-b.imaginary) <= tol,"Img At ("+i+","+j+") A = "+a.imaginary+" B = "+b.imaginary); } } }
/** * <p> * Checks to see if the matrix has the specified number of rows and columns. * </p> * * @param A Matrix * @param numRows expected number of rows in the matrix * @param numCols expected number of columns in the matrix */ public static void assertShape( ReshapeMatrix64F A , int numRows , int numCols ) { assertTrue( A.numRows == numRows , "Unexpected number of rows."); assertTrue( A.numCols == numCols , "Unexpected number of columns."); }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout=300000) public void testBackAndForthVector() { List<YoDouble> yoArray = new ArrayList<YoDouble>(); int size = 50; String prefix = "test"; YoVariableRegistry registry = new YoVariableRegistry("test"); DenseMatrix64F matrix = new DenseMatrix64F(size, 1); Random random = new Random(1235612L); RandomMatrices.setRandom(matrix, random); DenseMatrix64F matrixBack = new DenseMatrix64F(size, 1); MatrixYoVariableConversionTools.populateYoVariablesVector(yoArray, size, prefix, registry); MatrixYoVariableConversionTools.storeInYoVariablesVector(matrix, yoArray); MatrixYoVariableConversionTools.getFromYoVariablesVector(matrixBack, yoArray); EjmlUnitTests.assertEquals(matrix, matrixBack, 1e-12); }
/** * <p> * Checks to see if each element in the matrices are within tolerance of each other and countable: * </p> * * <p> * The two matrices are identical with in tolerance if:<br> * |a<sub>ij</sub> - b<sub>ij</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEquals( ReshapeMatrix64F A , ReshapeMatrix64F B , double tol ) { assertShape(A,B); for( int i = 0; i < A.numRows; i++ ){ for( int j = 0; j < A.numCols; j++ ) { double valA = A.get(i,j); double valB = B.get(i,j); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"At ("+i+","+j+") A = "+valA+" B = "+valB); } } }
/** * <p> * Checks to see if the matrix has the specified number of rows and columns. * </p> * * @param A Matrix * @param numRows expected number of rows in the matrix * @param numCols expected number of columns in the matrix */ public static void assertShape( ReshapeMatrix64F A , int numRows , int numCols ) { assertTrue( A.numRows == numRows , "Unexpected number of rows."); assertTrue( A.numCols == numCols , "Unexpected number of columns."); }
@ContinuousIntegrationTest(estimatedDuration = 0.1) @Test(timeout = 30000) public void testCompareDifferentImplementations() { int numberOfStates = 30; int numberOfInputs = 10; StateSpaceSystemDiscretizer singleMatrixExponentialDiscretizer = new SingleMatrixExponentialStateSpaceSystemDiscretizer(numberOfStates, numberOfInputs); StateSpaceSystemDiscretizer splitUpMatrixExponentialDiscretizer = new SplitUpMatrixExponentialStateSpaceSystemDiscretizer(numberOfStates, numberOfInputs); StateSpaceSystemDiscretizer[] discretizers = new StateSpaceSystemDiscretizer[] { singleMatrixExponentialDiscretizer, splitUpMatrixExponentialDiscretizer }; Random random = new Random(125L); DenseMatrix64F A = RandomMatrices.createRandom(numberOfStates, numberOfStates, random); DenseMatrix64F B = RandomMatrices.createRandom(numberOfStates, numberOfInputs, random); DenseMatrix64F Q = RandomMatrices.createSymmPosDef(numberOfStates, random); DenseMatrix64F[] As = new DenseMatrix64F[] { new DenseMatrix64F(A), new DenseMatrix64F(A) }; DenseMatrix64F[] Bs = new DenseMatrix64F[] { new DenseMatrix64F(B), new DenseMatrix64F(B) }; DenseMatrix64F[] Qs = new DenseMatrix64F[] { new DenseMatrix64F(Q), new DenseMatrix64F(Q) }; double dt = 1.0; for (int i = 0; i < discretizers.length; i++) { discretizers[i].discretize(As[i], Bs[i], Qs[i], dt); } double tol = 1e-12; EjmlUnitTests.assertEquals(As[0], As[1], tol); EjmlUnitTests.assertEquals(Bs[0], Bs[1], tol); EjmlUnitTests.assertEquals(Qs[0], Qs[1], tol); }
/** * <p> * Checks to see if the transpose of B is equal to A and countable: * </p> * * <p> * |a<sub>ij</sub> - b<sub>ji</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEqualsTrans( ReshapeMatrix64F A , ReshapeMatrix64F B , double tol ) { assertShape(A,B.numCols,B.numRows); for( int i = 0; i < A.numRows; i++ ){ for( int j = 0; j < A.numCols; j++ ) { double valA = A.get(i,j); double valB = B.get(j,i); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); } } }
public static void assertEquals( Complex64F a , Complex64F b , double tol ) { assertTrue(!Double.isNaN(a.real) && !Double.isNaN(b.real) ,"real a = "+a.real+" b = "+b.real); assertTrue(!Double.isInfinite(a.real) && !Double.isInfinite(b.real) ,"real a = "+a.real+" b = "+b.real); assertTrue(Math.abs( a.real-b.real) <= tol,"real a = "+a.real+" b = "+b.real); assertTrue(!Double.isNaN(a.imaginary) && !Double.isNaN(b.imaginary) ,"imaginary a = "+a.imaginary+" b = "+b.imaginary); assertTrue(!Double.isInfinite(a.imaginary) && !Double.isInfinite(b.imaginary) ,"imaginary a = "+a.imaginary+" b = "+b.imaginary); assertTrue(Math.abs( a.imaginary-b.imaginary) <= tol,"imaginary a = "+a.imaginary+" b = "+b.imaginary); }
@ContinuousIntegrationTest(estimatedDuration = 0.3) @Test(timeout=300000) public void testBackAndForthMatrix() { List<List<YoDouble>> yoArray = new ArrayList<List<YoDouble>>(); int nRows = 50; int nColumns = 60; String prefix = "test"; YoVariableRegistry registry = new YoVariableRegistry("test"); DenseMatrix64F matrix = new DenseMatrix64F(nRows, nColumns); Random random = new Random(1235612L); RandomMatrices.setRandom(matrix, random); DenseMatrix64F matrixBack = new DenseMatrix64F(nRows, nColumns); MatrixYoVariableConversionTools.populateYoVariablesMatrix(yoArray, nRows, nColumns, prefix, registry); MatrixYoVariableConversionTools.storeInYoVariablesMatrix(matrix, yoArray); MatrixYoVariableConversionTools.getFromYoVariablesMatrix(matrixBack, yoArray); EjmlUnitTests.assertEquals(matrix, matrixBack, 1e-12); }
/** * <p> * Checks to see if each element in the matrices are within tolerance of each other and countable: * </p> * * <p> * The two matrices are identical with in tolerance if:<br> * |a<sub>ij</sub> - b<sub>ij</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEquals( ReshapeMatrix64F A , ReshapeMatrix64F B , double tol ) { assertShape(A,B); for( int i = 0; i < A.numRows; i++ ){ for( int j = 0; j < A.numCols; j++ ) { double valA = A.get(i,j); double valB = B.get(i,j); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"At ("+i+","+j+") A = "+valA+" B = "+valB); } } }
/** * <p> * Checks to see if the matrix has the specified number of rows and columns. * </p> * * @param A Matrix * @param numRows expected number of rows in the matrix * @param numCols expected number of columns in the matrix */ public static void assertShape( RealMatrix64F A , int numRows , int numCols ) { assertTrue( A.getNumRows() == numRows , "Unexpected number of rows."); assertTrue( A.getNumCols() == numCols , "Unexpected number of columns."); }
EjmlUnitTests.assertEquals(denseMatrixExpected, denseMatrixActual, EPS);