/** * See if passing in a matrix or not providing one to getQ and getR functions has the same result */ @Test public void checkGetNullVersusNot() { int width = 5; int height = 10; QRDecomposition<DenseMatrix64F> alg = createQRDecomposition(); SimpleMatrix A = new SimpleMatrix(height, width); RandomMatrices.setRandom(A.getMatrix(), rand); alg.decompose(A.getMatrix()); // get the results from a provided matrix DenseMatrix64F Q_provided = RandomMatrices.createRandom(height, height, rand); DenseMatrix64F R_provided = RandomMatrices.createRandom(height, width, rand); assertTrue(R_provided == alg.getR(R_provided, false)); assertTrue(Q_provided == alg.getQ(Q_provided, false)); // get the results when no matrix is provided DenseMatrix64F Q_null = alg.getQ(null, false); DenseMatrix64F R_null = alg.getR(null, false); // see if they are the same assertTrue(MatrixFeatures.isEquals(Q_provided, Q_null)); assertTrue(MatrixFeatures.isEquals(R_provided, R_null)); }
@DeployableTestMethod(estimatedDuration = 0.0) @Test(timeout = 30000) public void testConstrainedSimple() { int objectiveSize = 3; int solutionSize = 3; int constraintSize = 1; DenseMatrix64F a = new DenseMatrix64F(objectiveSize, solutionSize); CommonOps.setIdentity(a); DenseMatrix64F b = new DenseMatrix64F(objectiveSize, 1); b.zero(); DenseMatrix64F c = new DenseMatrix64F(constraintSize, solutionSize); CommonOps.setIdentity(c); DenseMatrix64F d = new DenseMatrix64F(constraintSize, 1); d.set(0, 0, -1.0); QuadraticProgram quadraticProgram = new QuadraticProgram(a, b, c, d); DenseMatrix64F initialGuess = new DenseMatrix64F(solutionSize, 1); initialGuess.set(0, 0, -10.0); initialGuess.set(1, 0, -10.0); initialGuess.set(2, 0, -10.0); ActiveSearchSolutionInfo solutionInfo = solve(quadraticProgram, initialGuess); assertTrue(solutionInfo.isConverged()); DenseMatrix64F expectedResult = new DenseMatrix64F(solutionSize, 1); expectedResult.set(0, 0, d.get(0, 0)); expectedResult.set(1, 0, 0.0); expectedResult.set(2, 0, 0.0); assertTrue(MatrixFeatures.isEquals(expectedResult, solutionInfo.getSolution(), 1e-12)); }
/** * Checks to see if the matrix is or is not modified as according to the modified flag. * * @param decomp */ public static void checkModifiedInput(DecompositionInterface decomp) { DenseMatrix64F A = RandomMatrices.createSymmPosDef(4, new Random(0x434)); DenseMatrix64F A_orig = A.copy(); assertTrue(decomp.decompose(A)); boolean modified = !MatrixFeatures.isEquals(A, A_orig); assertTrue(modified + " " + decomp.inputModified(), decomp.inputModified() == modified); }
@Test public void perfectInput() { init(30, false); // compute true essential matrix DenseMatrix64F E = MultiViewOps.createEssential(worldToCamera.getR(), worldToCamera.getT()); ModelFitter<DenseMatrix64F, AssociatedPair> alg = createAlgorithm(); // give it the perfect matrix and see if it screwed it up assertTrue(alg.fitModel(pairs, E, found)); // normalize so that they are the same CommonOps.divide(E.get(2, 2), E); CommonOps.divide(found.get(2, 2), found); assertTrue(MatrixFeatures.isEquals(E, found, 1e-8)); }