Optimization efforts

This commit is contained in:
Jens True 2024-02-15 09:08:01 +00:00
parent b966a930a4
commit 5bebd9310d
6 changed files with 12 additions and 14 deletions

2
.gitignore vendored

@ -1,4 +1,4 @@
.vscode .*/
vendor vendor
.*.cache/ .*.cache/
*.phar *.phar

@ -4,6 +4,7 @@
"runner.php_disable_ini": true, "runner.php_disable_ini": true,
"runner.retry_threshold": 5, "runner.retry_threshold": 5,
"runner.iterations": 10, "runner.iterations": 10,
"storage.xml_storage_path": "output/benchmarking/",
"report.outputs": { "report.outputs": {
"build-artifact": { "build-artifact": {
"renderer": "html", "renderer": "html",
@ -11,4 +12,5 @@
"title": "Benchmarking" "title": "Benchmarking"
} }
} }
} }

@ -15,11 +15,11 @@ class BasicMath
/** /**
* Squares the input (x^2 = x * x) * Squares the input (x^2 = x * x)
* *
* @param float $x Value to square (x) * @param $x Value to square (x)
* *
* @return float The squared value (x^2) * @return float The squared value (x^2)
*/ */
public static function square($x): float public static function square(float $x): float
{ {
return $x * $x; return $x * $x;
} }

@ -12,13 +12,11 @@ class DiagonalMatrix extends Matrix
public function __construct(array $diagonalValues) public function __construct(array $diagonalValues)
{ {
$diagonalCount = count($diagonalValues); $diagonalCount = count($diagonalValues);
$rowCount = $diagonalCount;
$colCount = $rowCount;
parent::__construct($rowCount, $colCount); parent::__construct($diagonalCount, $diagonalCount);
for ($currentRow = 0; $currentRow < $rowCount; $currentRow++) { for ($currentRow = 0; $currentRow < $diagonalCount; $currentRow++) {
for ($currentCol = 0; $currentCol < $colCount; $currentCol++) { for ($currentCol = 0; $currentCol < $diagonalCount; $currentCol++) {
if ($currentRow === $currentCol) { if ($currentRow === $currentCol) {
$this->setValue($currentRow, $currentCol, $diagonalValues[$currentRow]); $this->setValue($currentRow, $currentCol, $diagonalValues[$currentRow]);
} else { } else {

@ -8,18 +8,17 @@ class SquareMatrix extends Matrix
{ {
public function __construct(float|int ...$allValues) public function __construct(float|int ...$allValues)
{ {
$rows = (int)sqrt(count($allValues)); $size = (int)sqrt(count($allValues));
$cols = $rows;
$matrixData = []; $matrixData = [];
$allValuesIndex = 0; $allValuesIndex = 0;
for ($currentRow = 0; $currentRow < $rows; $currentRow++) { for ($currentRow = 0; $currentRow < $size; $currentRow++) {
for ($currentColumn = 0; $currentColumn < $cols; $currentColumn++) { for ($currentColumn = 0; $currentColumn < $size; $currentColumn++) {
$matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++]; $matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++];
} }
} }
parent::__construct($rows, $cols, $matrixData); parent::__construct($size, $size, $matrixData);
} }
} }

@ -181,7 +181,6 @@ class GaussianWeightedSumFactor extends GaussianFactor
} }
$newPrecision = 1.0 / $inverseOfNewPrecisionSum; $newPrecision = 1.0 / $inverseOfNewPrecisionSum;
$anotherNewPrecision = 1.0 / $anotherInverseOfNewPrecisionSum;
$newPrecisionMean = $newPrecision * $weightedMeanSum; $newPrecisionMean = $newPrecision * $weightedMeanSum;