1 | <?php |
||
10 | class LDA extends EigenTransformerBase |
||
11 | { |
||
12 | /** |
||
13 | * @var bool |
||
14 | */ |
||
15 | public $fit = false; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | public $labels = []; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | public $means = []; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | public $counts = []; |
||
31 | |||
32 | /** |
||
33 | * @var float[] |
||
34 | */ |
||
35 | public $overallMean = []; |
||
36 | |||
37 | /** |
||
38 | * Linear Discriminant Analysis (LDA) is used to reduce the dimensionality |
||
39 | * of the data. Unlike Principal Component Analysis (PCA), it is a supervised |
||
40 | * technique that requires the class labels in order to fit the data to a |
||
41 | * lower dimensional space. <br><br> |
||
42 | * The algorithm can be initialized by speciyfing |
||
43 | * either with the totalVariance(a value between 0.1 and 0.99) |
||
44 | * or numFeatures (number of features in the dataset) to be preserved. |
||
45 | * |
||
46 | * @param float|null $totalVariance Total explained variance to be preserved |
||
47 | * @param int|null $numFeatures Number of features to be preserved |
||
48 | * |
||
49 | * @throws \Exception |
||
50 | */ |
||
51 | public function __construct(?float $totalVariance = null, ?int $numFeatures = null) |
||
73 | |||
74 | /** |
||
75 | * Trains the algorithm to transform the given data to a lower dimensional space. |
||
76 | */ |
||
77 | public function fit(array $data, array $classes): array |
||
92 | |||
93 | /** |
||
94 | * Transforms the given sample to a lower dimensional vector by using |
||
95 | * the eigenVectors obtained in the last run of <code>fit</code>. |
||
96 | * |
||
97 | * @throws \Exception |
||
98 | */ |
||
99 | public function transform(array $sample): array |
||
111 | |||
112 | /** |
||
113 | * Returns unique labels in the dataset |
||
114 | */ |
||
115 | protected function getLabels(array $classes): array |
||
121 | |||
122 | /** |
||
123 | * Calculates mean of each column for each class and returns |
||
124 | * n by m matrix where n is number of labels and m is number of columns |
||
125 | */ |
||
126 | protected function calculateMeans(array $data, array $classes): array |
||
167 | |||
168 | /** |
||
169 | * Returns in-class scatter matrix for each class, which |
||
170 | * is a n by m matrix where n is number of classes and |
||
171 | * m is number of columns |
||
172 | */ |
||
173 | protected function calculateClassVar(array $data, array $classes): Matrix |
||
190 | |||
191 | /** |
||
192 | * Returns between-class scatter matrix for each class, which |
||
193 | * is an n by m matrix where n is number of classes and |
||
194 | * m is number of columns |
||
195 | */ |
||
196 | protected function calculateClassCov(): Matrix |
||
210 | |||
211 | /** |
||
212 | * Returns the result of the calculation (x - m)T.(x - m) |
||
213 | */ |
||
214 | protected function calculateVar(array $row, array $means): Matrix |
||
222 | } |
||
223 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: