diff --git a/composer.json b/composer.json index f80cf92b..5979f323 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ "test:unit": "phpunit --config tests/phpunit.xml", "post-install-cmd": [ "@composer bin all install --ansi", - "grep -r 'OCA\\\\Recognize\\\\Rubix' ./vendor/rubix/ml/ || ( vendor/bin/php-scoper add-prefix --prefix='OCA\\Recognize' --output-dir=\".\" --working-dir=\"./vendor/rubix/ml/\" -f --config=\"../../../scoper.inc.php\" && sed -i 's:Rubix\\\\\\\\ML\\\\\\\\:OCA\\\\\\\\Recognize\\\\\\\\Rubix\\\\\\\\ML\\\\\\\\:' vendor/composer/installed.json )", + "grep -r 'OCA\\\\Recognize\\\\Vendor\\\\Rubix' ./vendor/rubix/ml/ || vendor/bin/php-scoper add-prefix --prefix='OCA\\Recognize\\Vendor' --output-dir=\".\" --working-dir=\"./vendor/\" -f --config=\"../scoper.inc.php\"", "composer dump-autoload" ], "post-update-cmd": [ "@composer bin all update --ansi", - "grep -r 'OCA\\\\Recognize\\\\Rubix' ./vendor/rubix/ml/ || ( vendor/bin/php-scoper add-prefix --prefix='OCA\\Recognize' --output-dir=\".\" --working-dir=\"./vendor/rubix/ml/\" -f --config=\"../../../scoper.inc.php\" && sed -i 's:Rubix\\\\\\\\ML\\\\\\\\:OCA\\\\\\\\Recognize\\\\\\\\Rubix\\\\\\\\ML\\\\\\\\:' vendor/composer/installed.json )", + "grep -r 'OCA\\\\Recognize\\\\Vendor\\\\Rubix' ./vendor/rubix/ml/ || vendor/bin/php-scoper add-prefix --prefix='OCA\\Recognize\\Vendor' --output-dir=\".\" --working-dir=\"./vendor/\" -f --config=\"../scoper.inc.php\"", "composer dump-autoload" ] }, diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 81d5b5f3..97cefa71 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -45,7 +45,9 @@ public function __construct() { } public function register(IRegistrationContext $context): void { - @include_once __DIR__ . '/../../vendor/autoload.php'; + @include_once __DIR__ . '/../../vendor/scoper-autoload.php'; + @include_once __DIR__ . '/../../vendor/rubix/ml/src/functions.php'; + @include_once __DIR__ . '/../../vendor/rubix/ml/src/constants.php'; /** Register $principalBackend for the DAV collection */ $context->registerServiceAlias('principalBackend', Principal::class); diff --git a/lib/Clustering/DualTreeBall.php b/lib/Clustering/DualTreeBall.php index b2e30242..e3222250 100644 --- a/lib/Clustering/DualTreeBall.php +++ b/lib/Clustering/DualTreeBall.php @@ -6,11 +6,11 @@ declare(strict_types=1); namespace OCA\Recognize\Clustering; -use \OCA\Recognize\Rubix\ML\Datasets\Labeled; -use \OCA\Recognize\Rubix\ML\Graph\Nodes\Ball; -use \OCA\Recognize\Rubix\ML\Helpers\Stats; -use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance; -use function \OCA\Recognize\Rubix\ML\argmax; +use \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled; +use \OCA\Recognize\Vendor\Rubix\ML\Graph\Nodes\Ball; +use \OCA\Recognize\Vendor\Rubix\ML\Helpers\Stats; +use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; +use function \OCA\Recognize\Vendor\Rubix\ML\argmax; class DualTreeBall extends Ball { protected float $longestDistanceInNode = INF; @@ -97,8 +97,8 @@ public function propagateSetChanges(array &$labelToSetId) { /** * Factory method to build a hypersphere by splitting the dataset into left and right clusters. * - * @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset - * @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance $kernel + * @param \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled $dataset + * @param \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance $kernel * @return self */ public static function split(Labeled $dataset, Distance $kernel): self { diff --git a/lib/Clustering/DualTreeClique.php b/lib/Clustering/DualTreeClique.php index 0f540520..f202f110 100644 --- a/lib/Clustering/DualTreeClique.php +++ b/lib/Clustering/DualTreeClique.php @@ -6,11 +6,11 @@ declare(strict_types=1); namespace OCA\Recognize\Clustering; -use \OCA\Recognize\Rubix\ML\Datasets\Labeled; -use \OCA\Recognize\Rubix\ML\Graph\Nodes\Clique; -use \OCA\Recognize\Rubix\ML\Helpers\Stats; -use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance; -use function \OCA\Recognize\Rubix\ML\argmax; +use \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled; +use \OCA\Recognize\Vendor\Rubix\ML\Graph\Nodes\Clique; +use \OCA\Recognize\Vendor\Rubix\ML\Helpers\Stats; +use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; +use function \OCA\Recognize\Vendor\Rubix\ML\argmax; class DualTreeClique extends Clique { protected float $longestDistanceInNode = INF; @@ -80,8 +80,8 @@ public function propagateSetChanges(array &$labelToSetId) { /** * Terminate a branch with a dataset. * - * @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset - * @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance $kernel + * @param \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled $dataset + * @param \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance $kernel * @return self */ public static function terminate(Labeled $dataset, Distance $kernel): self { diff --git a/lib/Clustering/MrdBallTree.php b/lib/Clustering/MrdBallTree.php index 3f08ad95..014a0840 100644 --- a/lib/Clustering/MrdBallTree.php +++ b/lib/Clustering/MrdBallTree.php @@ -6,11 +6,11 @@ declare(strict_types=1); namespace OCA\Recognize\Clustering; -use \OCA\Recognize\Rubix\ML\Datasets\Labeled; -use \OCA\Recognize\Rubix\ML\Graph\Nodes\Ball; -use \OCA\Recognize\Rubix\ML\Graph\Nodes\Hypersphere; -use \OCA\Recognize\Rubix\ML\Graph\Trees\BallTree; -use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance; +use \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled; +use \OCA\Recognize\Vendor\Rubix\ML\Graph\Nodes\Ball; +use \OCA\Recognize\Vendor\Rubix\ML\Graph\Nodes\Hypersphere; +use \OCA\Recognize\Vendor\Rubix\ML\Graph\Trees\BallTree; +use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; class MrdBallTree extends BallTree { private ?Labeled $dataset = null; @@ -25,8 +25,8 @@ class MrdBallTree extends BallTree { /** * @param int $maxLeafSize * @param int $coreDistSampleSize - * @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance|null $kernel - * @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException + * @param \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance|null $kernel + * @throws \OCA\Recognize\Vendor\Rubix\ML\Exceptions\InvalidArgumentException */ public function __construct(int $maxLeafSize = 30, int $sampleSize = 5, ?Distance $kernel = null) { if ($maxLeafSize < 1) { @@ -462,7 +462,7 @@ public function cachedComputeNative($a, array $a_vector, $b, array $b_vector, bo * * @param int|string $sampleLabel * @param bool $useCachedValues - * @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException + * @throws \OCA\Recognize\Vendor\Rubix\ML\Exceptions\InvalidArgumentException * @return array{list,list} */ public function getCoreNeighbors($sampleLabel, bool $useCachedValues = true): array { @@ -546,8 +546,8 @@ public function getCoreNeighbors($sampleLabel, bool $useCachedValues = true): ar * * @param int $sampleLabel * @param float $radius - * @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException - * @throws \OCA\Recognize\Rubix\ML\Exceptions\RuntimeException + * @throws \OCA\Recognize\Vendor\Rubix\ML\Exceptions\InvalidArgumentException + * @throws \OCA\Recognize\Vendor\Rubix\ML\Exceptions\RuntimeException * @return array{list,list} */ public function cachedRange($sampleLabel, float $radius): array { @@ -624,8 +624,8 @@ public function cachedRange($sampleLabel, float $radius): array { * * @internal * - * @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset - * @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException + * @param \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled $dataset + * @throws \OCA\Recognize\Vendor\Rubix\ML\Exceptions\InvalidArgumentException */ public function grow(Labeled $dataset): void { $this->dataset = $dataset; diff --git a/lib/Clustering/MstSolver.php b/lib/Clustering/MstSolver.php index f7c6b974..fe3ed28d 100644 --- a/lib/Clustering/MstSolver.php +++ b/lib/Clustering/MstSolver.php @@ -6,8 +6,8 @@ declare(strict_types=1); namespace OCA\Recognize\Clustering; -use \OCA\Recognize\Rubix\ML\Datasets\Labeled; -use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance; +use \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled; +use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; class MstSolver { private MrdBallTree $tree; diff --git a/lib/Clustering/SquaredDistance.php b/lib/Clustering/SquaredDistance.php index ce6ca930..a4367f09 100644 --- a/lib/Clustering/SquaredDistance.php +++ b/lib/Clustering/SquaredDistance.php @@ -6,8 +6,8 @@ declare(strict_types=1); namespace OCA\Recognize\Clustering; -use \OCA\Recognize\Rubix\ML\DataType; -use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance; +use \OCA\Recognize\Vendor\Rubix\ML\DataType; +use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; /** * Squared distance @@ -24,7 +24,7 @@ class SquaredDistance implements Distance { * * @internal * - * @return list<\OCA\Recognize\Rubix\ML\DataType> + * @return list<\OCA\Recognize\Vendor\Rubix\ML\DataType> */ public function compatibility(): array { return [ diff --git a/lib/Dav/Faces/FacePhoto.php b/lib/Dav/Faces/FacePhoto.php index 71f82a10..24ce0311 100644 --- a/lib/Dav/Faces/FacePhoto.php +++ b/lib/Dav/Faces/FacePhoto.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace OCA\Recognize\Dav\Faces; -use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean; +use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Euclidean; use OCA\Recognize\Db\FaceDetection; use OCA\Recognize\Db\FaceDetectionMapper; use OCA\Recognize\Service\FaceClusterAnalyzer; diff --git a/lib/Service/FaceClusterAnalyzer.php b/lib/Service/FaceClusterAnalyzer.php index 43ceb1c0..759a493c 100644 --- a/lib/Service/FaceClusterAnalyzer.php +++ b/lib/Service/FaceClusterAnalyzer.php @@ -6,8 +6,8 @@ declare(strict_types=1); namespace OCA\Recognize\Service; -use \OCA\Recognize\Rubix\ML\Datasets\Labeled; -use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean; +use \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled; +use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Euclidean; use OCA\Recognize\Clustering\HDBSCAN; use OCA\Recognize\Db\FaceCluster; use OCA\Recognize\Db\FaceClusterMapper; @@ -51,7 +51,7 @@ public function calculateClusters(string $userId, int $batchSize = 0): void { ini_set('memory_limit', '-1'); } - + $sampledDetections = []; $existingClusters = $this->faceClusters->findByUserId($userId); /** @var array $maxVotesByCluster */ @@ -87,6 +87,8 @@ public function calculateClusters(string $userId, int $batchSize = 0): void { return $detection->getVector(); }, $detections), array_combine(array_keys($detections), array_keys($detections)), false); + $dataset->features(); + $n = count($detections); $hdbscan = new HDBSCAN($dataset, $this->getMinClusterSize($n), $this->getMinSampleSize($n)); diff --git a/tests/ClusterTest.php b/tests/ClusterTest.php index b27a2eed..8d31bcba 100644 --- a/tests/ClusterTest.php +++ b/tests/ClusterTest.php @@ -1,6 +1,6 @@