diff --git a/tests/Math/Matrix/CholeskyDecompositionTest.php b/tests/Math/Matrix/CholeskyDecompositionTest.php index 8d433f07c..ee9773f8c 100644 --- a/tests/Math/Matrix/CholeskyDecompositionTest.php +++ b/tests/Math/Matrix/CholeskyDecompositionTest.php @@ -36,11 +36,23 @@ class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase [-1, 1, 3], ], $cholesky->getL()->toArray(), '', 0.2); + self::assertTrue($cholesky->isSpd()); + } + + public function testSolve() + { + $A = new Matrix(); + $A->setMatrix([ + [25, 15, -5], + [15, 17, 0], + [-5, 0, 11], + ]); + + $cholesky = new CholeskyDecomposition($A); + $vec = new Vector(); $vec->setMatrix([[40], [49], [28]]); self::assertEquals([[1], [2], [3]], $cholesky->solve($vec)->toArray(), '', 0.2); - - self::assertTrue($cholesky->isSpd()); } /** diff --git a/tests/Math/Matrix/QRDecompositionTest.php b/tests/Math/Matrix/QRDecompositionTest.php new file mode 100644 index 000000000..7c473c25f --- /dev/null +++ b/tests/Math/Matrix/QRDecompositionTest.php @@ -0,0 +1,69 @@ +setMatrix([ + [12, -51, 4], + [6, 167, -68], + [-4, 24, -41], + ]); + + $QR = new QRDecomposition($A); + + self::assertTrue($QR->isFullRank()); + + self::assertEquals([ + [12, -69, -58 / 5], + [6, 158, 6 / 5], + [-4, 30, -33], + ], $QR->getH()->toArray(), '', 0.2); + + self::assertEquals([ + [6 / 7, -69 / 175, -58 / 175], + [3 / 7, 158 / 175, 6 / 175], + [-2 / 7, 6 / 35, -33 / 35], + ], $QR->getQ()->toArray(), '', 0.2); + + self::assertEquals([ + [14, 21, -14], + [0, 175, -70], + [0, 0, 35], + ], $QR->getR()->toArray(), '', 0.2); + }*/ + + public function testSolve() + { + $A = new Matrix(); + $A->setMatrix([ + [25, 15, -5], + [15, 17, 0], + [-5, 0, 11], + ]); + + $QR = new QRDecomposition($A); + + $vec = new Vector(); + $vec->setMatrix([[40], [49], [28]]); + self::assertEquals([[1], [2], [3]], $QR->solve($vec)->toArray(), '', 0.2); + } +}