@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | namespace Phpml\DimensionReduction; |
| 4 | 4 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $eig = new EigenvalueDecomposition($matrix); |
| 54 | 54 | $eigVals = $eig->getRealEigenvalues(); |
| 55 | - $eigVects= $eig->getEigenvectors(); |
|
| 55 | + $eigVects = $eig->getEigenvectors(); |
|
| 56 | 56 | |
| 57 | 57 | $totalEigVal = array_sum($eigVals); |
| 58 | 58 | // Sort eigenvalues in descending order |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\DimensionReduction; |
| 6 | 6 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | // Calculate means for each dimension |
| 88 | 88 | $this->means = []; |
| 89 | - for ($i=0; $i < $n; $i++) { |
|
| 89 | + for ($i = 0; $i < $n; $i++) { |
|
| 90 | 90 | $column = array_column($data, $i); |
| 91 | 91 | $this->means[] = Mean::arithmetic($column); |
| 92 | 92 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | // Normalize data |
| 111 | 111 | foreach ($data as $i => $row) { |
| 112 | - for ($k=0; $k < $n; $k++) { |
|
| 112 | + for ($k = 0; $k < $n; $k++) { |
|
| 113 | 113 | $data[$i][$k] -= $this->means[$k]; |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | throw new \Exception("PCA has not been fitted with respect to original dataset, please run PCA::fit() first"); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if (! is_array($sample[0])) { |
|
| 134 | + if (!is_array($sample[0])) { |
|
| 135 | 135 | $sample = [$sample]; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Phpml\DimensionReduction; |
| 6 | 6 | |
@@ -119,21 +119,21 @@ discard block |
||
| 119 | 119 | protected function calculateMeans($data, $classes) : array |
| 120 | 120 | { |
| 121 | 121 | $means = []; |
| 122 | - $counts= []; |
|
| 122 | + $counts = []; |
|
| 123 | 123 | $overallMean = array_fill(0, count($data[0]), 0.0); |
| 124 | 124 | |
| 125 | 125 | foreach ($data as $index => $row) { |
| 126 | 126 | $label = array_search($classes[$index], $this->labels); |
| 127 | 127 | |
| 128 | 128 | foreach ($row as $col => $val) { |
| 129 | - if (! isset($means[$label][$col])) { |
|
| 129 | + if (!isset($means[$label][$col])) { |
|
| 130 | 130 | $means[$label][$col] = 0.0; |
| 131 | 131 | } |
| 132 | 132 | $means[$label][$col] += $val; |
| 133 | 133 | $overallMean[$col] += $val; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if (! isset($counts[$label])) { |
|
| 136 | + if (!isset($counts[$label])) { |
|
| 137 | 137 | $counts[$label] = 0; |
| 138 | 138 | } |
| 139 | 139 | $counts[$label]++; |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | // Calculate overall mean of the dataset for each column |
| 149 | 149 | $numElements = array_sum($counts); |
| 150 | - $map = function ($el) use ($numElements) { |
|
| 150 | + $map = function($el) use ($numElements) { |
|
| 151 | 151 | return $el / $numElements; |
| 152 | 152 | }; |
| 153 | 153 | $this->overallMean = array_map($map, $overallMean); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | throw new \Exception("LDA has not been fitted with respect to original dataset, please run LDA::fit() first"); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if (! is_array($sample[0])) { |
|
| 241 | + if (!is_array($sample[0])) { |
|
| 242 | 242 | $sample = [$sample]; |
| 243 | 243 | } |
| 244 | 244 | |