Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ModelCF | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
__construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
score | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Business\Recommendation |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Business\Recommendation; |
16 | |
17 | use phpOMS\Math\Matrix\Matrix; |
18 | |
19 | /** |
20 | * Model based collaborative filtering |
21 | * |
22 | * @package phpOMS\Business\Recommendation |
23 | * @license OMS License 2.0 |
24 | * @link https://jingga.app |
25 | * @see https://realpython.com/build-recommendation-engine-collaborative-filtering/ |
26 | * @since 1.0.0 |
27 | */ |
28 | final class ModelCF |
29 | { |
30 | /** |
31 | * Constructor |
32 | * |
33 | * @since 1.0.0 |
34 | * @codeCoverageIgnore |
35 | */ |
36 | private function __construct() |
37 | { |
38 | } |
39 | |
40 | /** |
41 | * Calculate the score of a user <-> item match. |
42 | * |
43 | * This function calculates how much a user likes a certain item (product, movie etc.) |
44 | * |
45 | * $user and $item can also be Vectors resulting in a individual evaluation |
46 | * e.g. the user matrix contains a user in every row, every column represents a score for a certain attribute |
47 | * the item matrix contains in every row a score for how much it belongs to a certain attribute. Each column represents an item. |
48 | * example: users columns define how much a user likes a certain movie genre and the item rows define how much this movie belongs to a certain genre. |
49 | * the multiplication gives a score of how much the user may like that movie. |
50 | * A segnificant amount of attributes are required to calculate a good match |
51 | * |
52 | * @param Matrix $users A mxa matrix where each "m" defines how much the user likes a certain attribute type and "a" defines different users |
53 | * @param Matrix $items A bxm matrix where each "b" defines a item and "m" defines how much it belongs to a certain attribute type |
54 | * |
55 | * @return array |
56 | * |
57 | * @since 1.0.0 |
58 | */ |
59 | public static function score(Matrix $users, Matrix $items) : array |
60 | { |
61 | return $users->mult($items)->getMatrix(); |
62 | } |
63 | } |