assertEquals($cov1, $knownCovariance[0][0], '', $epsilon); $cov1 = Covariance::fromXYArrays($x, $x); $this->assertEquals($cov1, $knownCovariance[0][0], '', $epsilon); $cov2 = Covariance::fromDataset($matrix, 0, 1); $this->assertEquals($cov2, $knownCovariance[0][1], '', $epsilon); $cov2 = Covariance::fromXYArrays($x, $y); $this->assertEquals($cov2, $knownCovariance[0][1], '', $epsilon); // Second: calculation cov matrix with automatic means for each column $covariance = Covariance::covarianceMatrix($matrix); $this->assertEquals($knownCovariance, $covariance, '', $epsilon); // Thirdly, CovMatrix: Means are precalculated and given to the method $x = array_column($matrix, 0); $y = array_column($matrix, 1); $meanX = Mean::arithmetic($x); $meanY = Mean::arithmetic($y); $covariance = Covariance::covarianceMatrix($matrix, [$meanX, $meanY]); $this->assertEquals($knownCovariance, $covariance, '', $epsilon); } public function testThrowExceptionOnEmptyX(): void { $this->expectException(InvalidArgumentException::class); Covariance::fromXYArrays([], [1, 2, 3]); } public function testThrowExceptionOnEmptyY(): void { $this->expectException(InvalidArgumentException::class); Covariance::fromXYArrays([1, 2, 3], []); } public function testThrowExceptionOnToSmallArrayIfSample(): void { $this->expectException(InvalidArgumentException::class); Covariance::fromXYArrays([1], [2], true); } public function testThrowExceptionIfEmptyDataset(): void { $this->expectException(InvalidArgumentException::class); Covariance::fromDataset([], 0, 1); } public function testThrowExceptionOnToSmallDatasetIfSample(): void { $this->expectException(InvalidArgumentException::class); Covariance::fromDataset([1], 0, 1); } public function testThrowExceptionWhenKIndexIsOutOfBound(): void { $this->expectException(InvalidArgumentException::class); Covariance::fromDataset([1, 2, 3], 2, 5); } public function testThrowExceptionWhenIIndexIsOutOfBound(): void { $this->expectException(InvalidArgumentException::class); Covariance::fromDataset([1, 2, 3], 5, 2); } }