public function testCholesky()
 {
     $m1 = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
     $matrix1 = Matrix::matrixFromDoubles($m1);
     $m2 = [[17, 18, 19, 20], [21, 22, 23, 24], [25, 27, 28, 29], [37, 33, 31, 30]];
     $matrix2 = Matrix::matrixFromDoubles($m2);
     $c = new CholeskyDecomposition($matrix1);
     $c->solve($matrix2);
     $mx = $c->getL();
     $this->assertEquals(1.0, $mx->get(0, 0));
     $this->assertEquals(1.0, $mx->get(1, 1));
     $this->assertEquals(1.0, $mx->get(2, 2));
     $this->assertEquals(4, $mx->getRows());
     $this->assertEquals(4, $mx->getCols());
 }
 public function testBipolar2double()
 {
     // test a 1x4
     $booleanData1 = [true, false, true, false];
     $checkData1 = [1, -1, 1, -1];
     $matrix1 = Matrix::createRowMatrix(BiPolarUtil\bipolar2double($booleanData1));
     $checkMatrix1 = Matrix::createRowMatrix($checkData1);
     $this->assertTrue($matrix1->equals($checkMatrix1));
     // test a 2x2
     $booleanData2 = [[true, false], [false, true]];
     $checkData2 = [[1, -1], [-1, 1]];
     $matrix2 = Matrix::matrixFromDoubles(BiPolarUtil\bipolar2double($booleanData2));
     $checkMatrix2 = Matrix::matrixFromDoubles($checkData2);
     $this->assertTrue($matrix2->equals($checkMatrix2));
 }
 public function testCopy()
 {
     $data = [[1.0, 2.0], [3.0, 4.0]];
     $source = Matrix::matrixFromDoubles($data);
     $target = new Matrix(2, 2);
     MatrixMath\copy($source, $target);
     $this->assertTrue($source->equals($target));
 }
/**
 * Return the transposition of a matrix.
 *
 * @param $input Matrix
 *        	The matrix to transpose.
 * @return Matrix The matrix transposed.
 */
function transpose(Matrix $input)
{
    $transposeMatrix = array();
    $d = $input->getData();
    for ($r = 0; $r < $input->getRows(); ++$r) {
        for ($c = 0; $c < $input->getCols(); ++$c) {
            $transposeMatrix[$c][$r] = $d[$r][$c];
        }
    }
    return Matrix::matrixFromDoubles($transposeMatrix);
}
 public function inverseCholesky()
 {
     $li = lowerTriangularInverse($l);
     $ic = array();
     for ($r = 0; $r < $this->n; ++$r) {
         for ($c = 0; $c < $this->n; ++$c) {
             for ($i = 0; $i < $this->n; ++$i) {
                 $ic[$r][$c] += $li[$i][$r] * $li[$i][$c];
             }
         }
     }
     return Matrix::matrixFromDoubles($ic);
 }
 public function testSize()
 {
     $data = [[1.0, 2.0], [3.0, 4.0]];
     $matrix = Matrix::matrixFromDoubles($data);
     $this->assertEquals(4, $matrix->size());
 }