mirror of
https://github.com/nextcloud/recognize.git
synced 2025-08-16 17:09:54 +00:00
fix(Rubix\ML): Isolate rubix
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once './vendor/autoload.php';
|
||||
require_once './vendor/scoper-autoload.php';
|
||||
|
||||
use Nextcloud\CodingStandard\Config;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"nextcloud/ocp": "dev-master",
|
||||
"nextcloud/ocp": "^28.0",
|
||||
"symfony/console": "^5.4",
|
||||
"symfony/process": "^5.2"
|
||||
},
|
||||
@ -24,10 +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 )",
|
||||
"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 )",
|
||||
"composer dump-autoload"
|
||||
]
|
||||
},
|
||||
|
@ -6,11 +6,11 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Clustering;
|
||||
|
||||
use \Rubix\ML\Datasets\Labeled;
|
||||
use \Rubix\ML\Graph\Nodes\Ball;
|
||||
use \Rubix\ML\Helpers\Stats;
|
||||
use \Rubix\ML\Kernels\Distance\Distance;
|
||||
use function \Rubix\ML\argmax;
|
||||
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;
|
||||
|
||||
class DualTreeBall extends Ball {
|
||||
protected float $longestDistanceInNode = INF;
|
||||
@ -97,8 +97,8 @@ class DualTreeBall extends Ball {
|
||||
/**
|
||||
* Factory method to build a hypersphere by splitting the dataset into left and right clusters.
|
||||
*
|
||||
* @param \Rubix\ML\Datasets\Labeled $dataset
|
||||
* @param \Rubix\ML\Kernels\Distance\Distance $kernel
|
||||
* @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset
|
||||
* @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance $kernel
|
||||
* @return self
|
||||
*/
|
||||
public static function split(Labeled $dataset, Distance $kernel): self {
|
||||
|
@ -6,11 +6,11 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Clustering;
|
||||
|
||||
use \Rubix\ML\Datasets\Labeled;
|
||||
use \Rubix\ML\Graph\Nodes\Clique;
|
||||
use \Rubix\ML\Helpers\Stats;
|
||||
use \Rubix\ML\Kernels\Distance\Distance;
|
||||
use function \Rubix\ML\argmax;
|
||||
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;
|
||||
|
||||
class DualTreeClique extends Clique {
|
||||
protected float $longestDistanceInNode = INF;
|
||||
@ -80,8 +80,8 @@ class DualTreeClique extends Clique {
|
||||
/**
|
||||
* Terminate a branch with a dataset.
|
||||
*
|
||||
* @param \Rubix\ML\Datasets\Labeled $dataset
|
||||
* @param \Rubix\ML\Kernels\Distance\Distance $kernel
|
||||
* @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset
|
||||
* @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance $kernel
|
||||
* @return self
|
||||
*/
|
||||
public static function terminate(Labeled $dataset, Distance $kernel): self {
|
||||
|
@ -6,10 +6,10 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Clustering;
|
||||
|
||||
use \Rubix\ML\Datasets\Labeled;
|
||||
use \Rubix\ML\EstimatorType;
|
||||
use \Rubix\ML\Helpers\Params;
|
||||
use \Rubix\ML\Kernels\Distance\Distance;
|
||||
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
|
||||
use \OCA\Recognize\Rubix\ML\EstimatorType;
|
||||
use \OCA\Recognize\Rubix\ML\Helpers\Params;
|
||||
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;
|
||||
|
||||
/**
|
||||
* HDBSCAN
|
||||
@ -59,7 +59,7 @@ class HDBSCAN {
|
||||
* The distance kernel used for computing interpoint distances.
|
||||
*
|
||||
*/
|
||||
protected \Rubix\ML\Datasets\Labeled $dataset;
|
||||
protected \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset;
|
||||
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ class HDBSCAN {
|
||||
* @param array $oldCoreDistances
|
||||
* @param Distance $kernel
|
||||
* @param bool $useTrueMst // (Build true or approximate minimum spanning tree)
|
||||
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
|
||||
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function __construct(Labeled $dataset, int $minClusterSize = 5, int $sampleSize = 5, array $oldCoreDistances = [], ?Distance $kernel = null, bool $useTrueMst = true) {
|
||||
if ($minClusterSize < 2) {
|
||||
@ -96,7 +96,7 @@ class HDBSCAN {
|
||||
/**
|
||||
* Return the estimator type.
|
||||
*
|
||||
* @return \Rubix\ML\EstimatorType
|
||||
* @return \OCA\Recognize\Rubix\ML\EstimatorType
|
||||
*/
|
||||
public function type(): EstimatorType {
|
||||
return EstimatorType::clusterer();
|
||||
@ -105,7 +105,7 @@ class HDBSCAN {
|
||||
/**
|
||||
* Return the data types that the estimator is compatible with.
|
||||
*
|
||||
* @return list<\Rubix\ML\DataType>
|
||||
* @return list<\OCA\Recognize\Rubix\ML\DataType>
|
||||
*/
|
||||
public function compatibility(): array {
|
||||
return $this->mstSolver->kernel()->compatibility();
|
||||
|
@ -6,11 +6,11 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Clustering;
|
||||
|
||||
use \Rubix\ML\Datasets\Labeled;
|
||||
use \Rubix\ML\Graph\Nodes\Ball;
|
||||
use \Rubix\ML\Graph\Nodes\Hypersphere;
|
||||
use \Rubix\ML\Graph\Trees\BallTree;
|
||||
use \Rubix\ML\Kernels\Distance\Distance;
|
||||
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;
|
||||
|
||||
class MrdBallTree extends BallTree {
|
||||
private ?Labeled $dataset = null;
|
||||
@ -25,8 +25,8 @@ class MrdBallTree extends BallTree {
|
||||
/**
|
||||
* @param int $maxLeafSize
|
||||
* @param int $coreDistSampleSize
|
||||
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
|
||||
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
|
||||
* @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance|null $kernel
|
||||
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function __construct(int $maxLeafSize = 30, int $sampleSize = 5, ?Distance $kernel = null) {
|
||||
if ($maxLeafSize < 1) {
|
||||
@ -462,7 +462,7 @@ class MrdBallTree extends BallTree {
|
||||
*
|
||||
* @param int|string $sampleLabel
|
||||
* @param bool $useCachedValues
|
||||
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
|
||||
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
|
||||
* @return array{list<mixed>,list<float>}
|
||||
*/
|
||||
public function getCoreNeighbors($sampleLabel, bool $useCachedValues = true): array {
|
||||
@ -546,8 +546,8 @@ class MrdBallTree extends BallTree {
|
||||
*
|
||||
* @param int $sampleLabel
|
||||
* @param float $radius
|
||||
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
|
||||
* @throws \Rubix\ML\Exceptions\RuntimeException
|
||||
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
|
||||
* @throws \OCA\Recognize\Rubix\ML\Exceptions\RuntimeException
|
||||
* @return array{list<mixed>,list<float>}
|
||||
*/
|
||||
public function cachedRange($sampleLabel, float $radius): array {
|
||||
@ -624,8 +624,8 @@ class MrdBallTree extends BallTree {
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param \Rubix\ML\Datasets\Labeled $dataset
|
||||
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
|
||||
* @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset
|
||||
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function grow(Labeled $dataset): void {
|
||||
$this->dataset = $dataset;
|
||||
|
@ -6,8 +6,8 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Clustering;
|
||||
|
||||
use \Rubix\ML\Datasets\Labeled;
|
||||
use \Rubix\ML\Kernels\Distance\Distance;
|
||||
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
|
||||
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;
|
||||
|
||||
class MstSolver {
|
||||
private MrdBallTree $tree;
|
||||
|
@ -6,8 +6,8 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Clustering;
|
||||
|
||||
use \Rubix\ML\DataType;
|
||||
use \Rubix\ML\Kernels\Distance\Distance;
|
||||
use \OCA\Recognize\Rubix\ML\DataType;
|
||||
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;
|
||||
|
||||
/**
|
||||
* Squared distance
|
||||
@ -24,7 +24,7 @@ class SquaredDistance implements Distance {
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return list<\Rubix\ML\DataType>
|
||||
* @return list<\OCA\Recognize\Rubix\ML\DataType>
|
||||
*/
|
||||
public function compatibility(): array {
|
||||
return [
|
||||
|
@ -6,7 +6,7 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Dav\Faces;
|
||||
|
||||
use \Rubix\ML\Kernels\Distance\Euclidean;
|
||||
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean;
|
||||
use OCA\Recognize\Db\FaceDetection;
|
||||
use OCA\Recognize\Db\FaceDetectionMapper;
|
||||
use OCA\Recognize\Service\FaceClusterAnalyzer;
|
||||
|
@ -6,8 +6,8 @@
|
||||
declare(strict_types=1);
|
||||
namespace OCA\Recognize\Service;
|
||||
|
||||
use \Rubix\ML\Datasets\Labeled;
|
||||
use \Rubix\ML\Kernels\Distance\Euclidean;
|
||||
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
|
||||
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean;
|
||||
use OCA\Recognize\Clustering\HDBSCAN;
|
||||
use OCA\Recognize\Db\FaceCluster;
|
||||
use OCA\Recognize\Db\FaceClusterMapper;
|
||||
|
24
scoper.inc.php
Normal file
24
scoper.inc.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// scoper.inc.php
|
||||
|
||||
return [
|
||||
'patchers' => [
|
||||
static function (string $filePath, string $prefix, string $content): string {
|
||||
//
|
||||
// PHP-Parser patch conditions for file targets
|
||||
//
|
||||
if (str_contains($filePath, '/rubix/')) {
|
||||
return preg_replace(
|
||||
'%([ |<{:,])\\\\Rubix\\\\ML%',
|
||||
'$1\\\\OCA\\\\Recognize\\\\Rubix\\\\ML',
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
return $content;
|
||||
},
|
||||
],
|
||||
];
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use \Rubix\ML\Kernels\Distance\Euclidean;
|
||||
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean;
|
||||
use OCA\Recognize\Db\FaceClusterMapper;
|
||||
use OCA\Recognize\Db\FaceDetection;
|
||||
use OCA\Recognize\Db\FaceDetectionMapper;
|
||||
|
5
vendor-bin/php-scoper/composer.json
Normal file
5
vendor-bin/php-scoper/composer.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"require-dev": {
|
||||
"humbug/php-scoper": "^0.18.7"
|
||||
}
|
||||
}
|
1519
vendor-bin/php-scoper/composer.lock
generated
Normal file
1519
vendor-bin/php-scoper/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user