diff --git a/Algorithm/Frequency/Apriori.php b/Algorithm/Frequency/Apriori.php index 1df6b1c02..93f547b3c 100644 --- a/Algorithm/Frequency/Apriori.php +++ b/Algorithm/Frequency/Apriori.php @@ -91,6 +91,7 @@ final class Apriori $totalSet = \array_unique($totalSet); \sort($totalSet); + \sort($subset); // Combinations of items $combinations = self::generateSubsets($totalSet); @@ -99,6 +100,10 @@ final class Apriori $table = []; foreach ($combinations as &$c) { \sort($c); + if (!empty($subset) && $c !== $subset) { + continue; + } + $table[\implode(':', $c)] = 0; } diff --git a/Business/Recommendation/MemoryCF.php b/Business/Recommendation/MemoryCF.php index d66be710e..c81ac3a1e 100644 --- a/Business/Recommendation/MemoryCF.php +++ b/Business/Recommendation/MemoryCF.php @@ -87,7 +87,7 @@ final class MemoryCF * * @since 1.0.0 */ - public function euclideanDistance(array $ranking, array $rankings) : array + private function euclideanDistance(array $ranking, array $rankings) : array { $distances = []; foreach ($rankings as $idx => $r) { @@ -107,7 +107,7 @@ final class MemoryCF * * @since 1.0.0 */ - public function cosineDistance(array $ranking, array $rankings) : array + private function cosineDistance(array $ranking, array $rankings) : array { $distances = []; foreach ($rankings as $idx => $r) { diff --git a/tests/Algorithm/Frequency/AprioriTest.php b/tests/Algorithm/Frequency/AprioriTest.php index 61e53d164..9bfc8a44c 100644 --- a/tests/Algorithm/Frequency/AprioriTest.php +++ b/tests/Algorithm/Frequency/AprioriTest.php @@ -28,7 +28,23 @@ final class AprioriTest extends \PHPUnit\Framework\TestCase public function testApriori() : void { self::assertEquals( - [], + [ + 'theta' => 2, + 'epsilon' => 2, + 'epsilon:theta' => 0, + 'beta' => 4, + 'beta:theta' => 2, + 'beta:epsilon' => 2, + 'beta:epsilon:theta' => 0, + 'alpha' => 4, + 'alpha:theta' => 2, + 'alpha:epsilon' => 2, + 'alpha:epsilon:theta' => 0, + 'alpha:beta' => 4, + 'alpha:beta:theta' => 2, + 'alpha:beta:epsilon' => 2, + 'alpha:beta:epsilon:theta' => 0, + ], Apriori::apriori([ ['alpha', 'beta', 'epsilon'], ['alpha', 'beta', 'theta'], diff --git a/tests/Algorithm/Graph/DependencyResolverTest.php b/tests/Algorithm/Graph/DependencyResolverTest.php index bf1df2ab6..13ba3aed1 100644 --- a/tests/Algorithm/Graph/DependencyResolverTest.php +++ b/tests/Algorithm/Graph/DependencyResolverTest.php @@ -34,12 +34,12 @@ final class DependencyResolverTest extends \PHPUnit\Framework\TestCase { self::assertEquals( null, - DependencyResolver::resolve([0 => [1, 2], 1 => [0, 2]]) + DependencyResolver::resolve([0 => [1, 2], 1 => [0, 2], 2 => []]) ); self::assertEquals( [0, 1, 2, 3], - DependencyResolver::resolve([0 => [1, 2], 1 => [2, 3]]) + DependencyResolver::resolve([0 => [1, 2], 1 => [2, 3], 2 => [], 3 => []]) ); } } diff --git a/tests/Algorithm/Graph/MarkovChainTest.php b/tests/Algorithm/Graph/MarkovChainTest.php index 1733543bd..0521dc2d5 100644 --- a/tests/Algorithm/Graph/MarkovChainTest.php +++ b/tests/Algorithm/Graph/MarkovChainTest.php @@ -61,7 +61,7 @@ final class MarkovChainTest extends \PHPUnit\Framework\TestCase */ public function testStepProbability() : void { - $markov = new MarkovChain(); + $markov = new MarkovChain(2); $markov->setTraining( [ 'A A' => ['A' => 0.18, 'D' => 0.6, 'G' => 0.22], @@ -85,7 +85,7 @@ final class MarkovChainTest extends \PHPUnit\Framework\TestCase */ public function testPathProbability() : void { - $markov = new MarkovChain(); + $markov = new MarkovChain(2); $markov->setTraining( [ 'A A' => ['A' => 0.18, 'D' => 0.6, 'G' => 0.22], diff --git a/tests/Business/Recommendation/BayesianPersonalizedRankingTest.php b/tests/Business/Recommendation/BayesianPersonalizedRankingTest.php new file mode 100644 index 000000000..880c78a1c --- /dev/null +++ b/tests/Business/Recommendation/BayesianPersonalizedRankingTest.php @@ -0,0 +1,26 @@ + [1.0, 2.0], + 'B' => [2.0, 4.0], + 'C' => [2.5, 4.0], + 'D' => [4.5, 5.0], + ]); + + self::assertEquals( + ['B', 'C'], + $memory->bestMatch([2.2, 4.1], 2) + ); + } +} diff --git a/tests/DataStorage/Database/DataMapperAbstractTest.php b/tests/DataStorage/Database/DataMapperAbstractTest.php index e9710625e..ea2afe43a 100755 --- a/tests/DataStorage/Database/DataMapperAbstractTest.php +++ b/tests/DataStorage/Database/DataMapperAbstractTest.php @@ -247,7 +247,10 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase public function testGetYield() : void { BaseModelMapper::create()->execute($this->model); - self::assertCount(1, BaseModelMapper::yield()->execute()); + + foreach (BaseModelMapper::yield()->execute() as $model) { + self::assertGreaterThan(0, $model->id); + } } public function testGetFor() : void @@ -281,6 +284,7 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase $model1 = new BaseModel(); $model1->datetime = new \DateTime('now'); $id1 = BaseModelMapper::create()->execute($model1); + \sleep(1); $model2 = new BaseModel(); $model2->datetime = new \DateTime('now');