@@ -5,7 +5,6 @@ |
||
| 5 | 5 | namespace Phpml\DimensionReduction; |
| 6 | 6 | |
| 7 | 7 | |
| 8 | -use Phpml\Math\Statistic\Mean; |
|
| 9 | 8 | use Phpml\Math\Matrix; |
| 10 | 9 | |
| 11 | 10 | class LDA extends EigenTransformerBase |
@@ -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 | |
@@ -118,21 +118,21 @@ discard block |
||
| 118 | 118 | protected function calculateMeans($data, $classes) : array |
| 119 | 119 | { |
| 120 | 120 | $means = []; |
| 121 | - $counts= []; |
|
| 121 | + $counts = []; |
|
| 122 | 122 | $overallMean = array_fill(0, count($data[0]), 0.0); |
| 123 | 123 | |
| 124 | 124 | foreach ($data as $index => $row) { |
| 125 | 125 | $label = array_search($classes[$index], $this->labels); |
| 126 | 126 | |
| 127 | 127 | foreach ($row as $col => $val) { |
| 128 | - if (! isset($means[$label][$col])) { |
|
| 128 | + if (!isset($means[$label][$col])) { |
|
| 129 | 129 | $means[$label][$col] = 0.0; |
| 130 | 130 | } |
| 131 | 131 | $means[$label][$col] += $val; |
| 132 | 132 | $overallMean[$col] += $val; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if (! isset($counts[$label])) { |
|
| 135 | + if (!isset($counts[$label])) { |
|
| 136 | 136 | $counts[$label] = 0; |
| 137 | 137 | } |
| 138 | 138 | $counts[$label]++; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | // Calculate overall mean of the dataset for each column |
| 148 | 148 | $numElements = array_sum($counts); |
| 149 | - $map = function ($el) use ($numElements) { |
|
| 149 | + $map = function($el) use ($numElements) { |
|
| 150 | 150 | return $el / $numElements; |
| 151 | 151 | }; |
| 152 | 152 | $this->overallMean = array_map($map, $overallMean); |
@@ -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 | |