test fixes

This commit is contained in:
Dennis Eichhorn 2023-10-22 09:37:22 +00:00
parent 65264e33ae
commit 9d2b2e2e06
3 changed files with 72 additions and 4 deletions

View File

@ -49,15 +49,29 @@ final class ModelCF
* the multiplication gives a score of how much the user may like that movie.
* A segnificant amount of attributes are required to calculate a good match
*
* @param Matrix $users A mxa matrix where each "m" defines how much the user likes a certain attribute type and "a" defines different users
* @param Matrix $items A bxm matrix where each "b" defines a item and "m" defines how much it belongs to a certain attribute type
* @param array<int|string, array<int|float>> $users A mxa matrix where each "m" defines how much the user likes a certain attribute type and "a" defines different users
* @param array<int|string, array<int|float>> $items A bxm matrix where each "b" defines a item and "m" defines how much it belongs to a certain attribute type
*
* @return array
*
* @since 1.0.0
*/
public static function score(Matrix $users, Matrix $items) : array
public static function score(array $users, array $items) : array
{
return $users->mult($items)->getMatrix();
$matrix = [];
foreach ($users as $uid => $userrow) {
foreach ($items as $iid => $itemrow) {
$matrix[$uid][$iid] = 0.0;
foreach ($userrow as $user) {
foreach ($itemrow as $item) {
$matrix[$uid][$iid] += $user * $item;
}
}
}
}
return $matrix;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\tests\Business\Recommendation;
use phpOMS\Business\Recommendation\ModelCF;
/**
* @testdox phpOMS\tests\Business\Recommendation\ModelCFTest: Article affinity/correlation
*
* @internal
*/
final class ModelCFTest extends \PHPUnit\Framework\TestCase
{
public function testScore() : void
{
self::assertEquals(
[
[],
[],
[],
],
ModelCF::score(
[
[2, 3],
[1, 4],
[3, 3],
],
[
[1, 4],
[3, 2],
[2, 2],
]
)
);
}
}

View File

@ -169,6 +169,12 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_direct')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relations')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_directp')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_relp')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relationsp')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_belongs_to_onep')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_owns_onep')->execute();
}
/**