| Conditions | 5 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 46 | public function fit(array $samples, ?array $targets = null): void |
||
| 47 | { |
||
| 48 | $this->termCounts = array_fill_keys(array_keys($samples[0]), 0); |
||
| 49 | |||
| 50 | foreach ($samples as $sample) { |
||
| 51 | foreach ($sample as $index => $count) { |
||
| 52 | if ($count > 0) { |
||
| 53 | $this->termCounts[$index]++; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | $count = count($samples); |
||
| 59 | $this->idf = array_map( |
||
| 60 | function (float $value) use ($count): float { |
||
| 61 | return $value > 0.0 |
||
| 62 | ? log($count / $value, 10) |
||
| 63 | : 0; |
||
| 64 | }, |
||
| 65 | $this->termCounts |
||
| 66 | ); |
||
| 84 |