diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01304f1a3..6643cdfaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: operating-system: [windows-latest, ubuntu-latest, macos-latest] - php-versions: ['8.0', '8.1', '8.2'] + php-versions: ['8.4'] steps: - name: Checkout @@ -24,9 +24,10 @@ jobs: ini-values: memory_limit=-1 - name: Install OpenBLAS + if: matrix.operating-system == 'ubuntu-latest' run: | - apt-get update -q - apt-get install -qy libopenblas-dev + sudo apt-get update -q + sudo apt-get install -qy libopenblas-dev liblapacke-dev - name: Install NumPower run: | @@ -35,8 +36,8 @@ jobs: phpize ./configure make - make install - echo "extension=ndarray.so" >> $(php -i | grep "Loaded Configuration File" | sed -e "s|.*=>\s*||") + sudo make install + sudo echo "extension=ndarray.so" >> $(php -i | grep "Loaded Configuration File" | sed -e "s|.*=>\s*||") - name: Validate composer.json run: composer validate diff --git a/benchmarks/AnomalyDetectors/GaussianMLEBench.php b/benchmarks/AnomalyDetectors/GaussianMLEBench.php index 33e554d88..6324a959e 100644 --- a/benchmarks/AnomalyDetectors/GaussianMLEBench.php +++ b/benchmarks/AnomalyDetectors/GaussianMLEBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\AnomalyDetectors\GaussianMLE; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"AnomalyDetectors"}) @@ -12,24 +13,15 @@ */ class GaussianMLEBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var GaussianMLE - */ - protected $estimator; + protected GaussianMLE $estimator; public function setUp() : void { diff --git a/benchmarks/AnomalyDetectors/IsolationForestBench.php b/benchmarks/AnomalyDetectors/IsolationForestBench.php index 33e162b02..5b2cdf5c8 100644 --- a/benchmarks/AnomalyDetectors/IsolationForestBench.php +++ b/benchmarks/AnomalyDetectors/IsolationForestBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; use Rubix\ML\AnomalyDetectors\IsolationForest; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"AnomalyDetectors"}) @@ -12,24 +13,15 @@ */ class IsolationForestBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var IsolationForest - */ - protected $estimator; + protected IsolationForest $estimator; public function setUp() : void { diff --git a/benchmarks/AnomalyDetectors/LocalOutlierFactorBench.php b/benchmarks/AnomalyDetectors/LocalOutlierFactorBench.php index ac3b8397b..ba66487f6 100644 --- a/benchmarks/AnomalyDetectors/LocalOutlierFactorBench.php +++ b/benchmarks/AnomalyDetectors/LocalOutlierFactorBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\AnomalyDetectors\LocalOutlierFactor; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"AnomalyDetectors"}) @@ -12,24 +13,15 @@ */ class LocalOutlierFactorBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var LocalOutlierFactor - */ - protected $estimator; + protected LocalOutlierFactor $estimator; public function setUp() : void { diff --git a/benchmarks/AnomalyDetectors/LodaBench.php b/benchmarks/AnomalyDetectors/LodaBench.php index 3b742217a..550f7ba3c 100644 --- a/benchmarks/AnomalyDetectors/LodaBench.php +++ b/benchmarks/AnomalyDetectors/LodaBench.php @@ -5,6 +5,7 @@ use Rubix\ML\AnomalyDetectors\Loda; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"AnomalyDetectors"}) @@ -12,24 +13,15 @@ */ class LodaBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var Loda - */ - protected $estimator; + protected Loda $estimator; public function setUp() : void { diff --git a/benchmarks/AnomalyDetectors/OneClassSVMBench.php b/benchmarks/AnomalyDetectors/OneClassSVMBench.php index 1d722c3dc..dc513b080 100644 --- a/benchmarks/AnomalyDetectors/OneClassSVMBench.php +++ b/benchmarks/AnomalyDetectors/OneClassSVMBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\AnomalyDetectors\OneClassSVM; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"AnomalyDetectors"}) @@ -12,24 +13,15 @@ */ class OneClassSVMBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var OneClassSVM - */ - protected $estimator; + protected OneClassSVM $estimator; public function setUp() : void { diff --git a/benchmarks/AnomalyDetectors/RobustZScoreBench.php b/benchmarks/AnomalyDetectors/RobustZScoreBench.php index a4851c804..2e9a66d85 100644 --- a/benchmarks/AnomalyDetectors/RobustZScoreBench.php +++ b/benchmarks/AnomalyDetectors/RobustZScoreBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\AnomalyDetectors\RobustZScore; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"AnomalyDetectors"}) @@ -12,24 +13,15 @@ */ class RobustZScoreBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var RobustZScore - */ - protected $estimator; + protected RobustZScore $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/AdaBoostBench.php b/benchmarks/Classifiers/AdaBoostBench.php index faad0eda6..a443b593f 100644 --- a/benchmarks/Classifiers/AdaBoostBench.php +++ b/benchmarks/Classifiers/AdaBoostBench.php @@ -6,6 +6,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\ClassificationTree; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -13,24 +14,15 @@ */ class AdaBoostBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var AdaBoost - */ - protected $estimator; + protected AdaBoost $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/ClassificationTreeBench.php b/benchmarks/Classifiers/ClassificationTreeBench.php index 94e0e6e14..0ab3c2f64 100644 --- a/benchmarks/Classifiers/ClassificationTreeBench.php +++ b/benchmarks/Classifiers/ClassificationTreeBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\ClassificationTree; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class ClassificationTreeBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var ClassificationTree - */ - protected $estimator; + protected ClassificationTree $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/ExtraTreeClassifierBench.php b/benchmarks/Classifiers/ExtraTreeClassifierBench.php index c24f51449..296198039 100644 --- a/benchmarks/Classifiers/ExtraTreeClassifierBench.php +++ b/benchmarks/Classifiers/ExtraTreeClassifierBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\ExtraTreeClassifier; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class ExtraTreeClassifierBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var ExtraTreeClassifier - */ - protected $estimator; + protected ExtraTreeClassifier $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/GaussianNBBench.php b/benchmarks/Classifiers/GaussianNBBench.php index 0e93b05b3..ca1fd6970 100644 --- a/benchmarks/Classifiers/GaussianNBBench.php +++ b/benchmarks/Classifiers/GaussianNBBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Classifiers\GaussianNB; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class GaussianNBBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var GaussianNB - */ - protected $estimator; + protected GaussianNB $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/KDNeighborsBench.php b/benchmarks/Classifiers/KDNeighborsBench.php index 351700830..b0d78144f 100644 --- a/benchmarks/Classifiers/KDNeighborsBench.php +++ b/benchmarks/Classifiers/KDNeighborsBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Classifiers\KDNeighbors; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class KDNeighborsBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var KDNeighbors - */ - protected $estimator; + protected KDNeighbors $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/KNearestNeighborsBench.php b/benchmarks/Classifiers/KNearestNeighborsBench.php index 1d0c3f7cb..1af81fcc7 100644 --- a/benchmarks/Classifiers/KNearestNeighborsBench.php +++ b/benchmarks/Classifiers/KNearestNeighborsBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\KNearestNeighbors; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class KNearestNeighborsBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var KNearestNeighbors - */ - protected $estimator; + protected KNearestNeighbors $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/LogisticRegressionBench.php b/benchmarks/Classifiers/LogisticRegressionBench.php index fd00b295b..e557327d6 100644 --- a/benchmarks/Classifiers/LogisticRegressionBench.php +++ b/benchmarks/Classifiers/LogisticRegressionBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\LogisticRegression; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class LogisticRegressionBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var LogisticRegression - */ - protected $estimator; + protected LogisticRegression $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/LogitBoostBench.php b/benchmarks/Classifiers/LogitBoostBench.php index b1b2b0ee0..213e2f0e4 100644 --- a/benchmarks/Classifiers/LogitBoostBench.php +++ b/benchmarks/Classifiers/LogitBoostBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Classifiers\LogitBoost; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class LogitBoostBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var LogitBoost - */ - protected $estimator; + protected LogitBoost $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/MultilayerPerceptronBench.php b/benchmarks/Classifiers/MultilayerPerceptronBench.php index fa6b23087..2ce15a04c 100644 --- a/benchmarks/Classifiers/MultilayerPerceptronBench.php +++ b/benchmarks/Classifiers/MultilayerPerceptronBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Classifiers; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\NeuralNet\Layers\Dense; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\NeuralNet\Layers\Activation; @@ -15,24 +16,15 @@ */ class MultilayerPerceptronBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var MultilayerPerceptron - */ - protected $estimator; + protected MultilayerPerceptron $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/NaiveBayesBench.php b/benchmarks/Classifiers/NaiveBayesBench.php index 81f59183e..9033a0e4d 100644 --- a/benchmarks/Classifiers/NaiveBayesBench.php +++ b/benchmarks/Classifiers/NaiveBayesBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Classifiers\NaiveBayes; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Transformers\IntervalDiscretizer; /** @@ -13,24 +14,15 @@ */ class NaiveBayesBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var NaiveBayes - */ - protected $estimator; + protected NaiveBayes $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/OneVsRestBench.php b/benchmarks/Classifiers/OneVsRestBench.php index b56b1d504..f26ba4cee 100644 --- a/benchmarks/Classifiers/OneVsRestBench.php +++ b/benchmarks/Classifiers/OneVsRestBench.php @@ -6,6 +6,7 @@ use Rubix\ML\Classifiers\OneVsRest; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\LogisticRegression; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\NeuralNet\Optimizers\Stochastic; use Rubix\ML\Datasets\Generators\Agglomerate; use Rubix\ML\Tests\DataProvider\BackendProviderTrait; @@ -18,24 +19,15 @@ class OneVsRestBench { use BackendProviderTrait; - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var OneVsRest - */ - protected $estimator; + protected OneVsRest $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/RadiusNeighborsBench.php b/benchmarks/Classifiers/RadiusNeighborsBench.php index b7e1bce1a..53e46d4c7 100644 --- a/benchmarks/Classifiers/RadiusNeighborsBench.php +++ b/benchmarks/Classifiers/RadiusNeighborsBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\RadiusNeighbors; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class RadiusNeighborsBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var RadiusNeighbors - */ - protected $estimator; + protected RadiusNeighbors $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/RandomForestBench.php b/benchmarks/Classifiers/RandomForestBench.php index 674090014..dbff5a904 100644 --- a/benchmarks/Classifiers/RandomForestBench.php +++ b/benchmarks/Classifiers/RandomForestBench.php @@ -7,6 +7,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\ClassificationTree; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Tests\DataProvider\BackendProviderTrait; use Rubix\ML\Transformers\IntervalDiscretizer; @@ -17,24 +18,15 @@ class RandomForestBench { use BackendProviderTrait; - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var RandomForest - */ - protected $estimator; + protected RandomForest $estimator; public function setUpContinuous() : void { diff --git a/benchmarks/Classifiers/SVCBench.php b/benchmarks/Classifiers/SVCBench.php index 5789ad476..aef3ec110 100644 --- a/benchmarks/Classifiers/SVCBench.php +++ b/benchmarks/Classifiers/SVCBench.php @@ -3,6 +3,7 @@ namespace Rubix\ML\Benchmarks\Classifiers; use Rubix\ML\Classifiers\SVC; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Kernels\SVM\Polynomial; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; @@ -13,24 +14,15 @@ */ class SVCBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var SVC - */ - protected $estimator; + protected SVC $estimator; public function setUp() : void { diff --git a/benchmarks/Classifiers/SoftmaxClassifierBench.php b/benchmarks/Classifiers/SoftmaxClassifierBench.php index 64b598af1..bb888fe79 100644 --- a/benchmarks/Classifiers/SoftmaxClassifierBench.php +++ b/benchmarks/Classifiers/SoftmaxClassifierBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Classifiers\SoftmaxClassifier; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Classifiers"}) @@ -12,24 +13,15 @@ */ class SoftmaxClassifierBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var SoftmaxClassifier - */ - protected $estimator; + protected SoftmaxClassifier $estimator; public function setUp() : void { diff --git a/benchmarks/Clusterers/DBSCANBench.php b/benchmarks/Clusterers/DBSCANBench.php index 41baee8dd..f231a3ece 100644 --- a/benchmarks/Clusterers/DBSCANBench.php +++ b/benchmarks/Clusterers/DBSCANBench.php @@ -15,7 +15,7 @@ class DBSCANBench protected const TESTING_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $testing; diff --git a/benchmarks/Clusterers/FuzzyCMeansBench.php b/benchmarks/Clusterers/FuzzyCMeansBench.php index 3c629633e..b7b43ac82 100644 --- a/benchmarks/Clusterers/FuzzyCMeansBench.php +++ b/benchmarks/Clusterers/FuzzyCMeansBench.php @@ -17,12 +17,12 @@ class FuzzyCMeansBench protected const TESTING_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $training; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $testing; diff --git a/benchmarks/Clusterers/GaussianMixtureBench.php b/benchmarks/Clusterers/GaussianMixtureBench.php index 0d2167837..d2fdf0c14 100644 --- a/benchmarks/Clusterers/GaussianMixtureBench.php +++ b/benchmarks/Clusterers/GaussianMixtureBench.php @@ -17,12 +17,12 @@ class GaussianMixtureBench protected const TESTING_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $training; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $testing; diff --git a/benchmarks/Clusterers/KMeansBench.php b/benchmarks/Clusterers/KMeansBench.php index 598e0b0d9..1badd41b9 100644 --- a/benchmarks/Clusterers/KMeansBench.php +++ b/benchmarks/Clusterers/KMeansBench.php @@ -17,12 +17,12 @@ class KMeansBench protected const TESTING_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $training; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $testing; diff --git a/benchmarks/Clusterers/MeanShiftBench.php b/benchmarks/Clusterers/MeanShiftBench.php index 0ae0d9afd..16db1fb12 100644 --- a/benchmarks/Clusterers/MeanShiftBench.php +++ b/benchmarks/Clusterers/MeanShiftBench.php @@ -5,6 +5,7 @@ use Rubix\ML\Clusterers\MeanShift; use Rubix\ML\Datasets\Generators\Blob; use Rubix\ML\Datasets\Generators\Agglomerate; +use Rubix\ML\Datasets\Labeled; /** * @Groups({"Clusterers"}) @@ -12,24 +13,15 @@ */ class MeanShiftBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var MeanShift - */ - protected $estimator; + protected MeanShift $estimator; public function setUp() : void { diff --git a/benchmarks/Datasets/RandomizationBench.php b/benchmarks/Datasets/RandomizationBench.php index 4b1f234c8..e93679576 100644 --- a/benchmarks/Datasets/RandomizationBench.php +++ b/benchmarks/Datasets/RandomizationBench.php @@ -17,7 +17,7 @@ class RandomizationBench protected const SUBSAMPLE_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $dataset; diff --git a/benchmarks/Datasets/SortingBench.php b/benchmarks/Datasets/SortingBench.php index 4ca135901..c049257e6 100644 --- a/benchmarks/Datasets/SortingBench.php +++ b/benchmarks/Datasets/SortingBench.php @@ -14,7 +14,7 @@ class SortingBench protected const DATASET_SIZE = 2500; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $dataset; diff --git a/benchmarks/Datasets/SplittingBench.php b/benchmarks/Datasets/SplittingBench.php index 214c14980..a4751651f 100644 --- a/benchmarks/Datasets/SplittingBench.php +++ b/benchmarks/Datasets/SplittingBench.php @@ -14,7 +14,7 @@ class SplittingBench protected const DATASET_SIZE = 25000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $dataset; diff --git a/benchmarks/Graph/Trees/BallTreeBench.php b/benchmarks/Graph/Trees/BallTreeBench.php index c4066c4a5..b673e99a7 100644 --- a/benchmarks/Graph/Trees/BallTreeBench.php +++ b/benchmarks/Graph/Trees/BallTreeBench.php @@ -15,7 +15,7 @@ class BallTreeBench protected const DATASET_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $dataset; diff --git a/benchmarks/Graph/Trees/KDTreeBench.php b/benchmarks/Graph/Trees/KDTreeBench.php index ad4f479d2..c7164e75f 100644 --- a/benchmarks/Graph/Trees/KDTreeBench.php +++ b/benchmarks/Graph/Trees/KDTreeBench.php @@ -15,7 +15,7 @@ class KDTreeBench protected const DATASET_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $dataset; diff --git a/benchmarks/Graph/Trees/VantageTreeBench.php b/benchmarks/Graph/Trees/VantageTreeBench.php index b2e878256..0d7b19a97 100644 --- a/benchmarks/Graph/Trees/VantageTreeBench.php +++ b/benchmarks/Graph/Trees/VantageTreeBench.php @@ -15,7 +15,7 @@ class VantageTreeBench protected const DATASET_SIZE = 10000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $dataset; diff --git a/benchmarks/Regressors/AdalineBench.php b/benchmarks/Regressors/AdalineBench.php index e9e026182..71e4a125f 100644 --- a/benchmarks/Regressors/AdalineBench.php +++ b/benchmarks/Regressors/AdalineBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\Adaline; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class AdalineBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var Adaline - */ - protected $estimator; + protected Adaline $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/ExtraTreeRegressorBench.php b/benchmarks/Regressors/ExtraTreeRegressorBench.php index ae7f04680..51e5e71e1 100644 --- a/benchmarks/Regressors/ExtraTreeRegressorBench.php +++ b/benchmarks/Regressors/ExtraTreeRegressorBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\ExtraTreeRegressor; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class ExtraTreeRegressorBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var ExtraTreeRegressor - */ - protected $estimator; + protected ExtraTreeRegressor $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/GradientBoostBench.php b/benchmarks/Regressors/GradientBoostBench.php index 0321a697b..0c374ab8c 100644 --- a/benchmarks/Regressors/GradientBoostBench.php +++ b/benchmarks/Regressors/GradientBoostBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\GradientBoost; use Rubix\ML\Datasets\Generators\Hyperplane; use Rubix\ML\Transformers\IntervalDiscretizer; @@ -11,24 +12,15 @@ */ class GradientBoostBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var GradientBoost - */ - protected $estimator; + protected GradientBoost $estimator; public function setUpContinuous() : void { diff --git a/benchmarks/Regressors/KDNeighborsRegressorBench.php b/benchmarks/Regressors/KDNeighborsRegressorBench.php index d9f26890d..07b18f94e 100644 --- a/benchmarks/Regressors/KDNeighborsRegressorBench.php +++ b/benchmarks/Regressors/KDNeighborsRegressorBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\KDNeighborsRegressor; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class KDNeighborsRegressorBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var KDNeighborsRegressor - */ - protected $estimator; + protected KDNeighborsRegressor $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/KNNRegressorBench.php b/benchmarks/Regressors/KNNRegressorBench.php index 993de0d00..5c5b1d38a 100644 --- a/benchmarks/Regressors/KNNRegressorBench.php +++ b/benchmarks/Regressors/KNNRegressorBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\KNNRegressor; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class KNNRegressorBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var KNNRegressor - */ - protected $estimator; + protected KNNRegressor $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/MLPRegressorBench.php b/benchmarks/Regressors/MLPRegressorBench.php index 8aaa0c6ab..552f2f805 100644 --- a/benchmarks/Regressors/MLPRegressorBench.php +++ b/benchmarks/Regressors/MLPRegressorBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\NeuralNet\Layers\Dense; use Rubix\ML\Regressors\MLPRegressor; use Rubix\ML\NeuralNet\Layers\Activation; @@ -14,24 +15,15 @@ */ class MLPRegressorBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var MLPRegressor - */ - protected $estimator; + protected MLPRegressor $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/RadiusNeighborsRegressorBench.php b/benchmarks/Regressors/RadiusNeighborsRegressorBench.php index 9813dfbaf..4b6f4d5aa 100644 --- a/benchmarks/Regressors/RadiusNeighborsRegressorBench.php +++ b/benchmarks/Regressors/RadiusNeighborsRegressorBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\RadiusNeighborsRegressor; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class RadiusNeighborsRegressorBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var RadiusNeighborsRegressor - */ - protected $estimator; + protected RadiusNeighborsRegressor $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/RegressionTreeBench.php b/benchmarks/Regressors/RegressionTreeBench.php index fab6d1abf..31dc6dfb2 100644 --- a/benchmarks/Regressors/RegressionTreeBench.php +++ b/benchmarks/Regressors/RegressionTreeBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\RegressionTree; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class RegressionTreeBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var RegressionTree - */ - protected $estimator; + protected RegressionTree $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/RidgeBench.php b/benchmarks/Regressors/RidgeBench.php index d6f6f61f5..fb0e0653a 100644 --- a/benchmarks/Regressors/RidgeBench.php +++ b/benchmarks/Regressors/RidgeBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\Ridge; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class RidgeBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var Ridge - */ - protected $estimator; + protected Ridge $estimator; public function setUp() : void { diff --git a/benchmarks/Regressors/SVRBench.php b/benchmarks/Regressors/SVRBench.php index 64fd4f333..3e2fb40bd 100644 --- a/benchmarks/Regressors/SVRBench.php +++ b/benchmarks/Regressors/SVRBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Regressors; +use Rubix\ML\Datasets\Labeled; use Rubix\ML\Regressors\SVR; use Rubix\ML\Datasets\Generators\Hyperplane; @@ -11,24 +12,15 @@ */ class SVRBench { - protected const TRAINING_SIZE = 10000; + protected const int TRAINING_SIZE = 10000; - protected const TESTING_SIZE = 10000; + protected const int TESTING_SIZE = 10000; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $training; + protected Labeled $training; - /** - * @var \Rubix\ML\Datasets\Labeled; - */ - protected $testing; + protected Labeled $testing; - /** - * @var SVR - */ - protected $estimator; + protected SVR $estimator; public function setUp() : void { diff --git a/benchmarks/Tokenizers/KSkipNGramBench.php b/benchmarks/Tokenizers/KSkipNGramBench.php index 88dd3485f..322314f4a 100644 --- a/benchmarks/Tokenizers/KSkipNGramBench.php +++ b/benchmarks/Tokenizers/KSkipNGramBench.php @@ -10,12 +10,9 @@ */ class KSkipNGramBench { - protected const SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; + protected const string SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; - /** - * @var \Rubix\ML\Tokenizers\KSkipNGram; - */ - protected $tokenizer; + protected KSkipNGram $tokenizer; public function setUp() : void { diff --git a/benchmarks/Tokenizers/NGramBench.php b/benchmarks/Tokenizers/NGramBench.php index fc9da151d..759daea66 100644 --- a/benchmarks/Tokenizers/NGramBench.php +++ b/benchmarks/Tokenizers/NGramBench.php @@ -10,12 +10,9 @@ */ class NGramBench { - protected const SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; + protected const string SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; - /** - * @var \Rubix\ML\Tokenizers\NGram; - */ - protected $tokenizer; + protected NGram $tokenizer; public function setUp() : void { diff --git a/benchmarks/Tokenizers/SentenceBench.php b/benchmarks/Tokenizers/SentenceBench.php index c7da03d0d..f4021967b 100644 --- a/benchmarks/Tokenizers/SentenceBench.php +++ b/benchmarks/Tokenizers/SentenceBench.php @@ -10,12 +10,9 @@ */ class SentenceBench { - protected const SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; + protected const string SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; - /** - * @var \Rubix\ML\Tokenizers\Sentence; - */ - protected $tokenizer; + protected Sentence $tokenizer; public function setUp() : void { diff --git a/benchmarks/Tokenizers/WhitespaceBench.php b/benchmarks/Tokenizers/WhitespaceBench.php index a9dd9f11a..b04432358 100644 --- a/benchmarks/Tokenizers/WhitespaceBench.php +++ b/benchmarks/Tokenizers/WhitespaceBench.php @@ -10,12 +10,9 @@ */ class WhitespaceBench { - protected const SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; + protected const string SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; - /** - * @var \Rubix\ML\Tokenizers\Whitespace; - */ - protected $tokenizer; + protected Whitespace $tokenizer; public function setUp() : void { diff --git a/benchmarks/Tokenizers/WordBench.php b/benchmarks/Tokenizers/WordBench.php index 3538b3e4c..448001d14 100644 --- a/benchmarks/Tokenizers/WordBench.php +++ b/benchmarks/Tokenizers/WordBench.php @@ -10,12 +10,9 @@ */ class WordBench { - protected const SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; + protected const string SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; - /** - * @var \Rubix\ML\Tokenizers\Word; - */ - protected $tokenizer; + protected Word $tokenizer; public function setUp() : void { diff --git a/benchmarks/Tokenizers/WordStemmerBench.php b/benchmarks/Tokenizers/WordStemmerBench.php index 9c459790e..c6c16aa85 100644 --- a/benchmarks/Tokenizers/WordStemmerBench.php +++ b/benchmarks/Tokenizers/WordStemmerBench.php @@ -2,6 +2,7 @@ namespace Rubix\ML\Benchmarks\Tokenizers; +use Rubix\ML\Tokenizers\Word; use Rubix\ML\Tokenizers\WordStemmer; /** @@ -10,12 +11,9 @@ */ class WordStemmerBench { - protected const SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; + protected const string SAMPLE_TEXT = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb."; - /** - * @var \Rubix\ML\Tokenizers\Word; - */ - protected $tokenizer; + protected Word $tokenizer; public function setUp() : void { diff --git a/benchmarks/Transformers/TSNEBench.php b/benchmarks/Transformers/TSNEBench.php index d17ce1226..1eea75663 100644 --- a/benchmarks/Transformers/TSNEBench.php +++ b/benchmarks/Transformers/TSNEBench.php @@ -15,7 +15,7 @@ class TSNEBench protected const TESTING_SIZE = 1000; /** - * @var \Rubix\ML\Datasets\Labeled; + * @var \Rubix\ML\Datasets\Labeled */ protected $testing; diff --git a/composer.json b/composer.json index 8f7bf5089..6e0fa9a6a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "svm", "text mining", "tf-idf", "tf idf", "t-sne", "tsne", "unsupervised learning" ], "authors": [ - { + { "name": "Andrew DalPino", "homepage": "https://github.com/andrewdalpino" }, @@ -31,32 +31,32 @@ } ], "require": { - "php": ">=8.0", + "php": ">=8.4", "ext-json": "*", + "ext-numpower": ">=0.6", "amphp/parallel": "^1.3", "andrewdalpino/okbloomer": "^1.0", + "numpower/numpower": "^0.6", "psr/log": "^1.1|^2.0|^3.0", "rubix/tensor": "^3.0", "symfony/polyfill-mbstring": "^1.0", - "symfony/polyfill-php81": "^1.26", - "symfony/polyfill-php82": "^1.27", - "symfony/polyfill-php83": "^1.27", "wamania/php-stemmer": "^3.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", "phpbench/phpbench": "^1.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.0", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^11.0", "swoole/ide-helper": "^5.1" }, "suggest": { "ext-tensor": "For fast Matrix/Vector computing", "ext-gd": "For image support", "ext-mbstring": "For fast multibyte string manipulation", - "ext-svm": "For Support Vector Machine engine (libsvm)" + "ext-svm": "For support Vector Machine engine (libsvm)", + "ext-swoole": "For support Swoole runner" }, "autoload": { "psr-4": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 000000000..205d03a26 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,1579 @@ +parameters: + ignoreErrors: + - + message: '#^Method Rubix\\ML\\BootstrapAggregator\:\:params\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/BootstrapAggregator.php + + - + message: '#^Method Rubix\\ML\\BootstrapAggregator\:\:predict\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/BootstrapAggregator.php + + - + message: '#^Method Rubix\\ML\\Classifiers\\AdaBoost\:\:losses\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^Method Rubix\\ML\\Classifiers\\AdaBoost\:\:predict\(\) should return list\ but returns list\\.$#' + identifier: return.type + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^Method Rubix\\ML\\Classifiers\\AdaBoost\:\:score\(\) should return list\\> but returns array\, array\\>\.$#' + identifier: return.type + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^Method Rubix\\ML\\Classifiers\\AdaBoost\:\:steps\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^PHPDoc tag @return contains unresolvable type\.$#' + identifier: return.unresolvableType + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^PHPDoc tag @var for property Rubix\\ML\\Classifiers\\AdaBoost\:\:\$losses contains unresolvable type\.$#' + identifier: property.unresolvableType + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^PHPDoc tag @var for property Rubix\\ML\\Classifiers\\AdaBoost\:\:\$losses with type mixed is not subtype of native type array\|null\.$#' + identifier: property.phpDocType + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^Property Rubix\\ML\\Classifiers\\AdaBoost\:\:\$losses type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/Classifiers/AdaBoost.php + + - + message: '#^Property Rubix\\ML\\Classifiers\\ClassificationTree\:\:\$classes \(list\\) does not accept array\\.$#' + identifier: assign.propertyType + count: 1 + path: src/Classifiers/ClassificationTree.php + + - + message: '#^Parameter \#1 \$sample of method Rubix\\ML\\Classifiers\\GaussianNB\:\:jointLogLikelihood\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 2 + path: src/Classifiers/GaussianNB.php + + - + message: '#^Method Rubix\\ML\\Classifiers\\KNearestNeighbors\:\:nearest\(\) should return array\{list\, list\\} but returns array\{array\, string\>, array\, float\>\}\.$#' + identifier: return.type + count: 1 + path: src/Classifiers/KNearestNeighbors.php + + - + message: '#^Parameter \#2 \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Metric\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Classifiers/LogitBoost.php + + - + message: '#^Instanceof between Rubix\\ML\\NeuralNet\\Layers\\Hidden and Rubix\\ML\\NeuralNet\\Layers\\Hidden will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Classifiers/MultilayerPerceptron.php + + - + message: '#^Parameter \#2 \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Metric\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Classifiers/MultilayerPerceptron.php + + - + message: '#^Method Rubix\\ML\\Classifiers\\NaiveBayes\:\:counts\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/Classifiers/NaiveBayes.php + + - + message: '#^PHPDoc tag @return has invalid value \(array\\>\>\>\>\|null\)\: Unexpected token "\>", expected TOKEN_HORIZONTAL_WS at offset 121 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/Classifiers/NaiveBayes.php + + - + message: '#^Property Rubix\\ML\\Classifiers\\NaiveBayes\:\:\$counts \(array\\>\>\>\) does not accept non\-empty\-array\\>\>\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Classifiers/NaiveBayes.php + + - + message: '#^Property Rubix\\ML\\Classifiers\\NaiveBayes\:\:\$probs \(array\\>\>\) does not accept non\-empty\-array\\>\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Classifiers/NaiveBayes.php + + - + message: '#^Method Rubix\\ML\\Classifiers\\RandomForest\:\:proba\(\) should return list\\> but returns array\\>\.$#' + identifier: return.type + count: 1 + path: src/Classifiers/RandomForest.php + + - + message: '#^PHPDoc tag @var with type array\ is not subtype of native type array\\>\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Classifiers/RandomForest.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function min expects non\-empty\-array, array\\> given\.$#' + identifier: argument.type + count: 1 + path: src/Classifiers/RandomForest.php + + - + message: '#^Property Rubix\\ML\\Classifiers\\RandomForest\:\:\$trees \(list\\|null\) does not accept array\\.$#' + identifier: assign.propertyType + count: 1 + path: src/Classifiers/RandomForest.php + + - + message: '#^Method Rubix\\ML\\Clusterers\\DBSCAN\:\:predict\(\) should return list\ but returns array\\>\.$#' + identifier: return.type + count: 1 + path: src/Clusterers/DBSCAN.php + + - + message: '#^Parameter \#1 \$sample of method Rubix\\ML\\Clusterers\\FuzzyCMeans\:\:probaSample\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Clusterers/FuzzyCMeans.php + + - + message: '#^Parameter \#2 \$memberships of method Rubix\\ML\\Clusterers\\FuzzyCMeans\:\:inertia\(\) expects list\\>, list\\> given\.$#' + identifier: argument.type + count: 1 + path: src/Clusterers/FuzzyCMeans.php + + - + message: '#^Parameter \#1 \$sample of method Rubix\\ML\\Clusterers\\GaussianMixture\:\:jointLogLikelihood\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Clusterers/GaussianMixture.php + + - + message: '#^Property Rubix\\ML\\Clusterers\\GaussianMixture\:\:\$means \(list\\>\) does not accept non\-empty\-array\, list\\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Clusterers/GaussianMixture.php + + - + message: '#^Property Rubix\\ML\\Clusterers\\GaussianMixture\:\:\$means \(list\\>\) does not accept non\-empty\-array\, list\\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Clusterers/GaussianMixture.php + + - + message: '#^Property Rubix\\ML\\Clusterers\\GaussianMixture\:\:\$variances \(list\\>\) does not accept non\-empty\-array\, list\\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Clusterers/GaussianMixture.php + + - + message: '#^Property Rubix\\ML\\Clusterers\\GaussianMixture\:\:\$variances \(list\\>\) does not accept non\-empty\-array\, list\\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Clusterers/GaussianMixture.php + + - + message: '#^Parameter \#2 \$labels of method Rubix\\ML\\Clusterers\\KMeans\:\:inertia\(\) expects list\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Clusterers/KMeans.php + + - + message: '#^Parameter \#1 \$current of method Rubix\\ML\\Clusterers\\MeanShift\:\:shift\(\) expects list\\>, array\, list\\> given\.$#' + identifier: argument.type + count: 1 + path: src/Clusterers/MeanShift.php + + - + message: '#^Parameter \#2 \$b of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 2 + path: src/Clusterers/MeanShift.php + + - + message: '#^Parameter \#2 \$previous of method Rubix\\ML\\Clusterers\\MeanShift\:\:shift\(\) expects list\\>, array\, list\\> given\.$#' + identifier: argument.type + count: 1 + path: src/Clusterers/MeanShift.php + + - + message: '#^Property Rubix\\ML\\Clusterers\\Seeders\\Preset\:\:\$centroids \(list\\>\) does not accept non\-empty\-list\\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Clusterers/Seeders/Preset.php + + - + message: '#^Instanceof between Rubix\\ML\\Learner and Rubix\\ML\\Learner will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/CommitteeMachine.php + + - + message: '#^Property Rubix\\ML\\CommitteeMachine\:\:\$experts \(list\\) does not accept array\\.$#' + identifier: assign.propertyType + count: 1 + path: src/CommitteeMachine.php + + - + message: '#^Parameter \#2 \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Metric\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/CrossValidation/HoldOut.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/Accuracy.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/Completeness.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/FBeta.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/Homogeneity.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/Informedness.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/MCC.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/MeanAbsoluteError.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/MeanSquaredError.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/MedianAbsoluteError.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 105 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/Metric.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 105 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/ProbabilisticMetric.php + + - + message: '#^Parameter \#1 \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\MeanSquaredError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/CrossValidation/Metrics/RMSE.php + + - + message: '#^Parameter \#2 \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\MeanSquaredError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/CrossValidation/Metrics/RMSE.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/RSquared.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/RandIndex.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/SMAPE.php + + - + message: '#^PHPDoc tag @return has invalid value \(\\Rubix\\ML\\Tuple\{float,float\}\)\: Unexpected token "\{", expected TOKEN_HORIZONTAL_WS at offset 112 on line 4$#' + identifier: phpDoc.parseError + count: 1 + path: src/CrossValidation/Metrics/VMeasure.php + + - + message: '#^Instanceof between Rubix\\ML\\CrossValidation\\Reports\\ReportGenerator and Rubix\\ML\\CrossValidation\\Reports\\ReportGenerator will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/CrossValidation/Reports/AggregateReport.php + + - + message: '#^Method Rubix\\ML\\CrossValidation\\Reports\\AggregateReport\:\:compatibility\(\) should return list\ but returns array\\.$#' + identifier: return.type + count: 1 + path: src/CrossValidation/Reports/AggregateReport.php + + - + message: '#^Method Rubix\\ML\\Datasets\\Dataset\:\:types\(\) should return list\ but returns array\\.$#' + identifier: return.type + count: 1 + path: src/Datasets/Dataset.php + + - + message: '#^Method Rubix\\ML\\Datasets\\Dataset\:\:uniqueTypes\(\) should return list\ but returns array\, Rubix\\ML\\DataType\>\.$#' + identifier: return.type + count: 1 + path: src/Datasets/Dataset.php + + - + message: '#^Offset 0 on non\-empty\-list\\> on left side of \?\? always exists and is not nullable\.$#' + identifier: nullCoalesce.offset + count: 1 + path: src/Datasets/Dataset.php + + - + message: '#^Property Rubix\\ML\\Datasets\\Dataset\:\:\$samples \(list\\>\) does not accept array\\.$#' + identifier: assign.propertyType + count: 1 + path: src/Datasets/Dataset.php + + - + message: '#^Instanceof between Rubix\\ML\\Datasets\\Generators\\Generator and Rubix\\ML\\Datasets\\Generators\\Generator will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Datasets/Generators/Agglomerate.php + + - + message: '#^Ternary operator condition is always true\.$#' + identifier: ternary.alwaysTrue + count: 1 + path: src/Datasets/Generators/Agglomerate.php + + - + message: '#^Instanceof between Rubix\\ML\\Datasets\\Labeled and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Datasets/Labeled.php + + - + message: '#^PHPDoc tag @var with type array\ is not subtype of native type array\\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Datasets/Labeled.php + + - + message: '#^PHPDoc tag @var with type list\ is not subtype of native type array\\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Datasets/Labeled.php + + - + message: '#^Parameter \#2 \$b of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 2 + path: src/Datasets/Labeled.php + + - + message: '#^Property Rubix\\ML\\Datasets\\Labeled\:\:\$labels \(list\\) does not accept array\\.$#' + identifier: assign.propertyType + count: 1 + path: src/Datasets/Labeled.php + + - + message: '#^Instanceof between Rubix\\ML\\Datasets\\Dataset and Rubix\\ML\\Datasets\\Dataset will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Datasets/Unlabeled.php + + - + message: '#^Parameter \#2 \$b of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 2 + path: src/Datasets/Unlabeled.php + + - + message: '#^Call to function is_array\(\) with non\-empty\-array\ will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: src/Extractors/CSV.php + + - + message: '#^Parameter \#1 \$keys of function array_combine expects array\, list\ given\.$#' + identifier: argument.type + count: 1 + path: src/Extractors/CSV.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, list\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Nodes/Ball.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, list\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Nodes/Clique.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Nodes/Isolator.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function min expects non\-empty\-array, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Nodes/Isolator.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, list\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Nodes/VantagePoint.php + + - + message: '#^Method Rubix\\ML\\Graph\\Trees\\BallTree\:\:nearest\(\) should return array\{list\\>, list\, list\\} but returns array\{list\\>, array\, list\\}\.$#' + identifier: return.type + count: 1 + path: src/Graph/Trees/BallTree.php + + - + message: '#^Parameter \#1 \$labels of method Rubix\\ML\\Graph\\Trees\\DecisionTree\:\:impurity\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Trees/DecisionTree.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Trees/ExtraTree.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function min expects non\-empty\-array, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Graph/Trees/ExtraTree.php + + - + message: '#^Method Rubix\\ML\\Graph\\Trees\\KDTree\:\:nearest\(\) should return array\{list\\>, list\, list\\} but returns array\{list\\>, array\, list\\}\.$#' + identifier: return.type + count: 1 + path: src/Graph/Trees/KDTree.php + + - + message: '#^Instanceof between Rubix\\ML\\Datasets\\Labeled and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Graph/Trees/VantageTree.php + + - + message: '#^Parameter \#1 \$a of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 5 + path: src/Graph/Trees/VantageTree.php + + - + message: '#^Method Rubix\\ML\\GridSearch\:\:combine\(\) should return list\\> but returns list\, mixed\>\>\.$#' + identifier: return.type + count: 1 + path: src/GridSearch.php + + - + message: '#^Parameter \#1 \$array \(list\\) of array_values is already a list, call has no effect\.$#' + identifier: arrayValues.list + count: 1 + path: src/GridSearch.php + + - + message: '#^Property Rubix\\ML\\GridSearch\:\:\$params \(list\\>\) does not accept list\\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/GridSearch.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, list\\> given\.$#' + identifier: argument.type + count: 1 + path: src/Kernels/Distance/Diagonal.php + + - + message: '#^Parameter \#1 \$labels of method Rubix\\ML\\NeuralNet\\Network\:\:backpropagate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/NeuralNet/Network.php + + - + message: '#^Instanceof between Rubix\\ML\\Transformers\\Transformer and Rubix\\ML\\Transformers\\Transformer will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Pipeline.php + + - + message: '#^Parameter \#2 \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Metric\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Regressors/GradientBoost.php + + - + message: '#^Method Rubix\\ML\\Regressors\\KNNRegressor\:\:nearest\(\) should return array\{list\, list\\} but returns array\{array\, float\|int\>, array\, float\>\}\.$#' + identifier: return.type + count: 1 + path: src/Regressors/KNNRegressor.php + + - + message: '#^Parameter \#1 \$a of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Regressors/KNNRegressor.php + + - + message: '#^Parameter \#1 \$array \(list\\) of array_values is already a list, call has no effect\.$#' + identifier: arrayValues.list + count: 1 + path: src/Regressors/KNNRegressor.php + + - + message: '#^Parameter \#2 \$b of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Regressors/KNNRegressor.php + + - + message: '#^Property Rubix\\ML\\Regressors\\KNNRegressor\:\:\$labels \(list\\) does not accept array\\.$#' + identifier: assign.propertyType + count: 1 + path: src/Regressors/KNNRegressor.php + + - + message: '#^Instanceof between Rubix\\ML\\NeuralNet\\Layers\\Hidden and Rubix\\ML\\NeuralNet\\Layers\\Hidden will always evaluate to true\.$#' + identifier: instanceof.alwaysTrue + count: 1 + path: src/Regressors/MLPRegressor.php + + - + message: '#^Parameter \#2 \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Metric\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Regressors/MLPRegressor.php + + - + message: '#^Parameter \#2 \$callback of function array_walk expects callable\(array\, int\|string\)\: mixed, array\{\$this\(Rubix\\ML\\Transformers\\BooleanConverter\), ''convert''\} given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/BooleanConverter.php + + - + message: '#^Parameter \#1 \$width of function imagecreatetruecolor expects int\<1, max\>, int given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/ImageResizer.php + + - + message: '#^Parameter \#2 \$callback of function array_walk expects callable\(array\, int\|string\)\: mixed, array\{\$this\(Rubix\\ML\\Transformers\\ImageResizer\), ''resize''\} given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/ImageResizer.php + + - + message: '#^Parameter \#2 \$height of function imagecreatetruecolor expects int\<1, max\>, int given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/ImageResizer.php + + - + message: '#^Ternary operator condition is always true\.$#' + identifier: ternary.alwaysTrue + count: 2 + path: src/Transformers/ImageResizer.php + + - + message: '#^Ternary operator condition is always true\.$#' + identifier: ternary.alwaysTrue + count: 2 + path: src/Transformers/ImageVectorizer.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/IntervalDiscretizer.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function min expects non\-empty\-array, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/IntervalDiscretizer.php + + - + message: '#^Property Rubix\\ML\\Transformers\\MissingDataImputer\:\:\$strategies \(list\\|null\) does not accept non\-empty\-array\, Rubix\\ML\\Strategies\\Strategy\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Transformers/MissingDataImputer.php + + - + message: '#^Property Rubix\\ML\\Transformers\\MissingDataImputer\:\:\$types \(list\\|null\) does not accept non\-empty\-array\, Rubix\\ML\\DataType\>\.$#' + identifier: assign.propertyType + count: 1 + path: src/Transformers/MissingDataImputer.php + + - + message: '#^Parameter \#2 \$callback of function array_walk expects callable\(array\, int\|string\)\: mixed, array\{\$this\(Rubix\\ML\\Transformers\\MultibyteTextNormalizer\), ''normalize''\} given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/MultibyteTextNormalizer.php + + - + message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: src/Transformers/RegexFilter.php + + - + message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: src/Transformers/StopWordFilter.php + + - + message: '#^Parameter \#1 \$a of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/TSNE.php + + - + message: '#^Parameter \#2 \$b of method Rubix\\ML\\Kernels\\Distance\\Distance\:\:compute\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/TSNE.php + + - + message: '#^Parameter \#2 \$callback of function array_walk expects callable\(array\, int\|string\)\: mixed, array\{\$this\(Rubix\\ML\\Transformers\\TextNormalizer\), ''normalize''\} given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/TextNormalizer.php + + - + message: '#^Parameter \#2 \$callback of function array_walk expects callable\(array\, int\|string\)\: mixed, array\{\$this\(Rubix\\ML\\Transformers\\TokenHashingVectorizer\), ''vectorize''\} given\.$#' + identifier: argument.type + count: 1 + path: src/Transformers/TokenHashingVectorizer.php + + - + message: '#^Parameter &\$sample by\-ref type of method Rubix\\ML\\Transformers\\TokenHashingVectorizer\:\:vectorize\(\) expects list\, array\, mixed\> given\.$#' + identifier: parameterByRef.type + count: 1 + path: src/Transformers/TokenHashingVectorizer.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, array\<\(int&T\)\|\(string&T\), float\|int\> given\.$#' + identifier: argument.type + count: 1 + path: src/functions.php + + - + message: '#^Parameter \#1 \.\.\.\$arg1 of function min expects non\-empty\-array, array\<\(int&T\)\|\(string&T\), float\|int\> given\.$#' + identifier: argument.type + count: 1 + path: src/functions.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/AnomalyDetectors/LodaTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\RSquared\:\:score\(\) expects list\, array given\.$#' + identifier: argument.type + count: 1 + path: tests/Base/BootstrapAggregatorTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Encoding'' and Rubix\\ML\\Encoding will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Base/ReportTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/AdaBoostTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Encoding'' and Rubix\\ML\\Encoding will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 2 + path: tests/Classifiers/ClassificationTreeTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\ will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Classifiers/ClassificationTreeTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 2 + path: tests/Classifiers/ClassificationTreeTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\ will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Classifiers/ExtraTreeClassifierTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 2 + path: tests/Classifiers/ExtraTreeClassifierTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/GaussianNBTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/KDNeighborsTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/KNearestNeighborsTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/KNearestNeighborsTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\ will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Classifiers/LogisticRegressionTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/LogisticRegressionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\ will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Classifiers/LogitBoostTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/LogitBoostTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Encoding'' and Rubix\\ML\\Encoding will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Classifiers/MultilayerPerceptronTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/MultilayerPerceptronTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/NaiveBayesTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/OneVsRestTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/RadiusNeighborsTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\ will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Classifiers/RandomForestTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/RandomForestTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/SVCTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Classifiers/SoftmaxClassifierTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\VMeasure\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Clusterers/DBSCANTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with list\\> will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Clusterers/FuzzyCMeansTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\VMeasure\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Clusterers/FuzzyCMeansTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\ will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Clusterers/GaussianMixtureTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with list\\> will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 2 + path: tests/Clusterers/GaussianMixtureTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\VMeasure\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Clusterers/GaussianMixtureTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\ will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Clusterers/KMeansTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with list\\> will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Clusterers/KMeansTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\VMeasure\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Clusterers/KMeansTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with list\\> will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Clusterers/MeanShiftTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsFloat\(\) with float will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Clusterers/MeanShiftTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\VMeasure\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/Clusterers/MeanShiftTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/AccuracyTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\AccuracyTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/AccuracyTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Accuracy\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/AccuracyTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\Accuracy\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/AccuracyTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/BrierScoreTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\BrierScoreTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/BrierScoreTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/CompletenessTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\CompletenessTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/CompletenessTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Completeness\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/CompletenessTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\Completeness\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/CompletenessTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/FBetaTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\FBetaTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/FBetaTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/FBetaTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\FBeta\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/FBetaTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/HomogeneityTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\HomogeneityTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/HomogeneityTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Homogeneity\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/HomogeneityTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\Homogeneity\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/HomogeneityTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/InformednessTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\InformednessTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/InformednessTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\Informedness\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/InformednessTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\Informedness\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/InformednessTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/MCCTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\MCCTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/MCCTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\MCC\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MCCTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\MCC\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MCCTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\MeanAbsoluteErrorTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\MeanAbsoluteError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\MeanAbsoluteError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/MeanSquaredErrorTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\MeanSquaredErrorTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/MeanSquaredErrorTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\MeanSquaredError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MeanSquaredErrorTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\MeanSquaredError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MeanSquaredErrorTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\MedianAbsoluteErrorTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\MedianAbsoluteError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\MedianAbsoluteError\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/ProbabilisticAccuracyTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\ProbabilisticAccuracyTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/ProbabilisticAccuracyTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/RMSETest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\RMSETest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/RMSETest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/RSquaredTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\RSquaredTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/RSquaredTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\RSquared\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/RSquaredTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\RSquared\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/RSquaredTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/RandIndexTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\RandIndexTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/RandIndexTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\RandIndex\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/RandIndexTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\RandIndex\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/RandIndexTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/SMAPETest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\SMAPETest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/SMAPETest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\SMAPETest\:\:testScore\(\) has parameter \$labels with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/SMAPETest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\SMAPETest\:\:testScore\(\) has parameter \$predictions with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/SMAPETest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\SMAPE\:\:score\(\) expects list\, array given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/SMAPETest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\SMAPE\:\:score\(\) expects list\, array given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/SMAPETest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/TopKAccuracyTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\TopKAccuracyTest\:\:score\(\) has parameter \$labels with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/TopKAccuracyTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\TopKAccuracyTest\:\:score\(\) has parameter \$probabilities with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/TopKAccuracyTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\TopKAccuracyTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/TopKAccuracyTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\TopKAccuracy\:\:score\(\) expects list\, array given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/TopKAccuracyTest.php + + - + message: '#^Parameter \$probabilities of method Rubix\\ML\\CrossValidation\\Metrics\\TopKAccuracy\:\:score\(\) expects list\\>, array given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/TopKAccuracyTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Tuple'' and Rubix\\ML\\Tuple will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Metrics/VMeasureTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Metrics\\VMeasureTest\:\:scoreProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Metrics/VMeasureTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Metrics\\VMeasure\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/VMeasureTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Metrics\\VMeasure\:\:score\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Metrics/VMeasureTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Report'' and Rubix\\ML\\Report will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Reports/AggregateReportTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Report'' and Rubix\\ML\\Report will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Reports/ConfusionMatrixTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Reports\\ConfusionMatrixTest\:\:generateProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Reports/ConfusionMatrixTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Reports\\ConfusionMatrixTest\:\:testGenerate\(\) has parameter \$expected with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Reports/ConfusionMatrixTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Reports\\ConfusionMatrix\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/ConfusionMatrixTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Reports\\ConfusionMatrix\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/ConfusionMatrixTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Report'' and Rubix\\ML\\Report will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Reports/ContingencyTableTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Reports\\ContingencyTableTest\:\:generateProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Reports/ContingencyTableTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Reports\\ContingencyTableTest\:\:testGenerate\(\) has parameter \$expected with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Reports/ContingencyTableTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Reports\\ContingencyTable\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/ContingencyTableTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Reports\\ContingencyTable\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/ContingencyTableTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Report'' and Rubix\\ML\\Report will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Reports/ErrorAnalysisTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Reports\\ErrorAnalysisTest\:\:generateProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Reports/ErrorAnalysisTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Reports\\ErrorAnalysis\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/ErrorAnalysisTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Reports\\ErrorAnalysis\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/ErrorAnalysisTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Report'' and Rubix\\ML\\Report will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/CrossValidation/Reports/MulticlassBreakdownTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Reports\\MulticlassBreakdownTest\:\:generateProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Reports/MulticlassBreakdownTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\CrossValidation\\Reports\\MulticlassBreakdownTest\:\:testGenerate\(\) has parameter \$expected with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/CrossValidation/Reports/MulticlassBreakdownTest.php + + - + message: '#^Parameter \$labels of method Rubix\\ML\\CrossValidation\\Reports\\MulticlassBreakdown\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/MulticlassBreakdownTest.php + + - + message: '#^Parameter \$predictions of method Rubix\\ML\\CrossValidation\\Reports\\MulticlassBreakdown\:\:generate\(\) expects list\, array\ given\.$#' + identifier: argument.type + count: 1 + path: tests/CrossValidation/Reports/MulticlassBreakdownTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Dataset'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/AgglomerateTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Labeled'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/AgglomerateTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Dataset'' and Rubix\\ML\\Datasets\\Unlabeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/BlobTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Generators\\\\Blob'' and Rubix\\ML\\Datasets\\Generators\\Blob will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/BlobTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Generators\\\\Generator'' and Rubix\\ML\\Datasets\\Generators\\Blob will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/BlobTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Unlabeled'' and Rubix\\ML\\Datasets\\Unlabeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/BlobTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Dataset'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/CircleTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Labeled'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/CircleTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Dataset'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/HalfMoonTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Labeled'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/HalfMoonTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Dataset'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/HyperplaneTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Labeled'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/HyperplaneTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Dataset'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/SwissRollTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Labeled'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Datasets/Generators/SwissRollTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Datasets\\\\Labeled'' and Rubix\\ML\\Datasets\\Labeled will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 8 + path: tests/Datasets/LabeledTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Report'' and Rubix\\ML\\Report will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 2 + path: tests/Datasets/LabeledTest.php + + - + message: '#^Parameter \#1 \$array \(list\\>\) of array_values is already a list, call has no effect\.$#' + identifier: arrayValues.list + count: 1 + path: tests/Extractors/NDJSONTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Rubix\\\\ML\\\\Encoding'' and Rubix\\ML\\Encoding will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Helpers/GraphvizTest.php + + - + message: '#^Method Rubix\\ML\\Tests\\Helpers\\ParamsTest\:\:stringify\(\) has parameter \$params with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: tests/Helpers/ParamsTest.php diff --git a/phpstan.neon b/phpstan.neon index 4d1ae5782..72e6086ac 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,5 @@ +includes: + - phpstan-baseline.neon parameters: level: 8 paths: @@ -7,3 +9,4 @@ parameters: excludePaths: - src/Backends/Amp.php - src/Backends/Swoole.php + - tests/Backends/SwooleTest.php diff --git a/phpunit.xml b/phpunit.xml index f2656a836..22063bc22 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,32 +2,33 @@ - + src - + - - tests - tests/AnomalyDetectors tests/Backends + + tests/Base + tests/Classifiers @@ -55,7 +56,7 @@ tests/Loggers - + tests/NeuralNet @@ -64,6 +65,9 @@ tests/Regressors + + tests/Serializers + tests/Specifications @@ -71,7 +75,7 @@ tests/Strategies - tests/Transformers + tests/Tokenizers tests/Transformers diff --git a/src/AnomalyDetectors/GaussianMLE.php b/src/AnomalyDetectors/GaussianMLE.php index 39c2435d4..1c221dc6a 100644 --- a/src/AnomalyDetectors/GaussianMLE.php +++ b/src/AnomalyDetectors/GaussianMLE.php @@ -133,7 +133,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -208,9 +208,11 @@ public function train(Dataset $dataset) : void $this->variances[$column] = $variance; } - $epsilon = max($this->smoothing * max($this->variances), CPU::epsilon()); + /** @var non-empty-array $variances */ + $variances = $this->variances; + $epsilon = max($this->smoothing * max($variances), CPU::epsilon()); - foreach ($this->variances as &$variance) { + foreach ($variances as &$variance) { $variance += $epsilon; } diff --git a/src/AnomalyDetectors/IsolationForest.php b/src/AnomalyDetectors/IsolationForest.php index 3cd055198..2cdfdc2fb 100644 --- a/src/AnomalyDetectors/IsolationForest.php +++ b/src/AnomalyDetectors/IsolationForest.php @@ -97,7 +97,7 @@ class IsolationForest implements Estimator, Learner, Scoring, Persistable /** * The isolation trees that make up the forest. * - * @var \Rubix\ML\Graph\Trees\ITree[] + * @var ITree[] */ protected array $trees = [ // @@ -162,7 +162,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/AnomalyDetectors/Loda.php b/src/AnomalyDetectors/Loda.php index 9cb149820..c8fdbf2bf 100644 --- a/src/AnomalyDetectors/Loda.php +++ b/src/AnomalyDetectors/Loda.php @@ -171,7 +171,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -239,6 +239,7 @@ public function train(Dataset $dataset) : void ->asArray(); foreach ($projections as $values) { + /** @var non-empty-array $values */ $min = (float) min($values); $max = (float) max($values); @@ -327,7 +328,7 @@ public function partial(Dataset $dataset) : void * Make predictions from a dataset. * * @param Dataset $dataset - * @return list + * @return array */ public function predict(Dataset $dataset) : array { @@ -339,7 +340,7 @@ public function predict(Dataset $dataset) : array * * @param Dataset $dataset * @throws RuntimeException - * @return list + * @return array */ public function score(Dataset $dataset) : array { @@ -362,7 +363,7 @@ public function score(Dataset $dataset) : array * created during training. * * @param list> $projections - * @return list + * @return array */ protected function densities(array $projections) : array { diff --git a/src/AnomalyDetectors/OneClassSVM.php b/src/AnomalyDetectors/OneClassSVM.php index a7ee88df2..b7c96bbde 100644 --- a/src/AnomalyDetectors/OneClassSVM.php +++ b/src/AnomalyDetectors/OneClassSVM.php @@ -139,7 +139,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/AnomalyDetectors/RobustZScore.php b/src/AnomalyDetectors/RobustZScore.php index f271b0b75..a6baff2b2 100644 --- a/src/AnomalyDetectors/RobustZScore.php +++ b/src/AnomalyDetectors/RobustZScore.php @@ -49,29 +49,21 @@ class RobustZScore implements Estimator, Learner, Scoring, Persistable /** * The expected value of the MAD as n asymptotes. - * - * @var float */ - protected const ETA = 0.6745; + protected const float ETA = 0.6745; /** * The minimum z score to be flagged as an anomaly. - * - * @var float */ protected float $threshold; /** * The weight of the maximum per sample z score in the overall anomaly score. - * - * @var float */ protected float $beta; /** * The amount of epsilon smoothing added to the median absolute deviation (MAD) of each feature. - * - * @var float */ protected float $smoothing; @@ -138,7 +130,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -214,9 +206,11 @@ public function train(Dataset $dataset) : void $this->mads[$column] = $mad; } - $epsilon = max($this->smoothing * max($this->mads), CPU::epsilon()); + /** @var non-empty-array $mads */ + $mads = $this->mads; + $epsilon = max($this->smoothing * max($mads), CPU::epsilon()); - foreach ($this->mads as &$mad) { + foreach ($mads as &$mad) { $mad += $epsilon; } } @@ -286,10 +280,9 @@ protected function zHat(array $sample) : float ); } - $zHat = (1.0 - $this->beta) * Stats::mean($scores) + /** @var non-empty-array $scores */ + return (1.0 - $this->beta) * Stats::mean($scores) + $this->beta * max($scores); - - return $zHat; } /** diff --git a/src/Backends/Amp.php b/src/Backends/Amp.php index eab64149b..49299ad8a 100644 --- a/src/Backends/Amp.php +++ b/src/Backends/Amp.php @@ -104,7 +104,7 @@ public function enqueue(Task $task, ?callable $after = null, mixed $context = nu * @param AmpTask $task * @param callable(mixed,mixed):void $after * @param mixed $context - * @return \Generator<\Amp\Promise> + * @return Generator<\Amp\Promise> */ public function coroutine(AmpTask $task, ?callable $after = null, mixed $context = null) : Generator { @@ -138,7 +138,7 @@ public function process() : array * * @internal * - * @return \Generator<\Amp\Promise> + * @return Generator<\Amp\Promise> */ public function gather() : Generator { diff --git a/src/Backends/Tasks/TrainAndValidate.php b/src/Backends/Tasks/TrainAndValidate.php index c51cc9007..70837dd8b 100644 --- a/src/Backends/Tasks/TrainAndValidate.php +++ b/src/Backends/Tasks/TrainAndValidate.php @@ -40,9 +40,12 @@ public static function score( $predictions = $estimator->predict($testing); - $score = $metric->score($predictions, $testing->labels()); - - return $score; + /** @var list $labels */ + $labels = $testing->labels(); + return $metric->score( + predictions: $predictions, + labels: $labels + ); } /** diff --git a/src/BootstrapAggregator.php b/src/BootstrapAggregator.php index fc30cc882..7878326b8 100644 --- a/src/BootstrapAggregator.php +++ b/src/BootstrapAggregator.php @@ -46,7 +46,7 @@ class BootstrapAggregator implements Estimator, Learner, Parallel, Persistable * * @var list */ - protected const COMPATIBLE_ESTIMATOR_TYPES = [ + protected const array COMPATIBLE_ESTIMATOR_TYPES = [ EstimatorType::CLASSIFIER, EstimatorType::REGRESSOR, EstimatorType::ANOMALY_DETECTOR, @@ -54,36 +54,28 @@ class BootstrapAggregator implements Estimator, Learner, Parallel, Persistable /** * The minimum size of each training subset. - * - * @var int */ - protected const MIN_SUBSAMPLE = 1; + protected const int MIN_SUBSAMPLE = 1; /** * The base learner. - * - * @var Learner */ protected Learner $base; /** * The number of base learners to train in the ensemble. - * - * @var int */ protected int $estimators; /** * The ratio of samples from the training set to randomly subsample to train each base learner. - * - * @var float */ protected float $ratio; /** * The ensemble of estimators. * - * @var list<\Rubix\ML\Learner> + * @var list */ protected array $ensemble = [ // @@ -136,7 +128,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -148,7 +140,7 @@ public function compatibility() : array * * @internal * - * @return mixed[] + * @return array */ public function params() : array { @@ -207,7 +199,9 @@ public function train(Dataset $dataset) : void $this->backend->enqueue($task); } - $this->ensemble = $this->backend->process(); + /** @var list $process */ + $process = $this->backend->process(); + $this->ensemble = $process; } /** @@ -215,7 +209,7 @@ public function train(Dataset $dataset) : void * * @param Dataset $dataset * @throws RuntimeException - * @return mixed[] + * @return array */ public function predict(Dataset $dataset) : array { @@ -251,7 +245,7 @@ public function predict(Dataset $dataset) : array */ protected function decideDiscrete(array $votes) : string { - /** @var array $counts */ + /** @var array> $counts */ $counts = array_count_values($votes); return argmax($counts); diff --git a/src/Classifiers/AdaBoost.php b/src/Classifiers/AdaBoost.php index f3237967d..1bae4d7de 100644 --- a/src/Classifiers/AdaBoost.php +++ b/src/Classifiers/AdaBoost.php @@ -112,7 +112,7 @@ class AdaBoost implements Estimator, Learner, Probabilistic, Verbose, Persistabl /** * The ensemble of *weak* classifiers. * - * @var \Rubix\ML\Learner[]|null + * @var Learner[]|null */ protected ?array $ensemble = null; @@ -133,7 +133,7 @@ class AdaBoost implements Estimator, Learner, Probabilistic, Verbose, Persistabl /** * The loss at each epoch from the last training session. * - * @var list]|null + * @var list|null */ protected ?array $losses = null; @@ -255,7 +255,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { @@ -274,7 +274,7 @@ public function steps() : Generator /** * Return the loss at each epoch of the last training session. * - * @return float[]|null + * @return list|null */ public function losses() : ?array { @@ -337,9 +337,7 @@ public function train(Dataset $dataset) : void } if (is_nan($loss)) { - if ($this->logger) { - $this->logger->warning('Numerical instability detected'); - } + $this->logger?->warning('Numerical instability detected'); break; } diff --git a/src/Classifiers/ClassificationTree.php b/src/Classifiers/ClassificationTree.php index 94a926b45..4095f4a66 100644 --- a/src/Classifiers/ClassificationTree.php +++ b/src/Classifiers/ClassificationTree.php @@ -94,7 +94,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Classifiers/ExtraTreeClassifier.php b/src/Classifiers/ExtraTreeClassifier.php index d977df1a6..c71d08cf7 100644 --- a/src/Classifiers/ExtraTreeClassifier.php +++ b/src/Classifiers/ExtraTreeClassifier.php @@ -93,7 +93,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Classifiers/GaussianNB.php b/src/Classifiers/GaussianNB.php index a0e0fa126..7adb31127 100644 --- a/src/Classifiers/GaussianNB.php +++ b/src/Classifiers/GaussianNB.php @@ -161,7 +161,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Classifiers/LogisticRegression.php b/src/Classifiers/LogisticRegression.php index 686d850fe..6b62dbb3d 100644 --- a/src/Classifiers/LogisticRegression.php +++ b/src/Classifiers/LogisticRegression.php @@ -196,7 +196,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -238,7 +238,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Classifiers/LogitBoost.php b/src/Classifiers/LogitBoost.php index 4760be17f..ad9e7be22 100644 --- a/src/Classifiers/LogitBoost.php +++ b/src/Classifiers/LogitBoost.php @@ -321,7 +321,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Classifiers/MultilayerPerceptron.php b/src/Classifiers/MultilayerPerceptron.php index cc37aacba..465a7e422 100644 --- a/src/Classifiers/MultilayerPerceptron.php +++ b/src/Classifiers/MultilayerPerceptron.php @@ -69,7 +69,7 @@ class MultilayerPerceptron implements Estimator, Learner, Online, Probabilistic, /** * An array composing the user-specified hidden layers of the network in order. * - * @var \Rubix\ML\NeuralNet\Layers\Hidden[] + * @var Hidden[] */ protected array $hiddenLayers; @@ -165,7 +165,7 @@ class MultilayerPerceptron implements Estimator, Learner, Online, Probabilistic, protected ?array $losses = null; /** - * @param \Rubix\ML\NeuralNet\Layers\Hidden[] $hiddenLayers + * @param Hidden[] $hiddenLayers * @param int $batchSize * @param Optimizer|null $optimizer * @param int $epochs @@ -259,7 +259,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -304,7 +304,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Classifiers/NaiveBayes.php b/src/Classifiers/NaiveBayes.php index b6f727cd3..2815ee971 100644 --- a/src/Classifiers/NaiveBayes.php +++ b/src/Classifiers/NaiveBayes.php @@ -151,7 +151,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Classifiers/OneVsRest.php b/src/Classifiers/OneVsRest.php index 841fb2751..8be21399c 100644 --- a/src/Classifiers/OneVsRest.php +++ b/src/Classifiers/OneVsRest.php @@ -56,7 +56,7 @@ class OneVsRest implements Estimator, Learner, Probabilistic, Parallel, Persista /** * A map of each class to its binary classifier. * - * @var array<\Rubix\ML\Learner> + * @var array */ protected array $classifiers = [ // diff --git a/src/Classifiers/SVC.php b/src/Classifiers/SVC.php index f8d1bece1..fd42edee4 100644 --- a/src/Classifiers/SVC.php +++ b/src/Classifiers/SVC.php @@ -150,7 +150,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Classifiers/SoftmaxClassifier.php b/src/Classifiers/SoftmaxClassifier.php index 849ce08e8..aa047436c 100644 --- a/src/Classifiers/SoftmaxClassifier.php +++ b/src/Classifiers/SoftmaxClassifier.php @@ -192,7 +192,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -234,7 +234,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Clusterers/FuzzyCMeans.php b/src/Clusterers/FuzzyCMeans.php index 106a17725..93ce67759 100644 --- a/src/Clusterers/FuzzyCMeans.php +++ b/src/Clusterers/FuzzyCMeans.php @@ -176,7 +176,7 @@ public function type() : EstimatorType /** * Return the data types that the estimator is compatible with. * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -225,7 +225,7 @@ public function centroids() : array /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Clusterers/GaussianMixture.php b/src/Clusterers/GaussianMixture.php index fbc5d5db1..96495e329 100644 --- a/src/Clusterers/GaussianMixture.php +++ b/src/Clusterers/GaussianMixture.php @@ -188,7 +188,7 @@ public function type() : EstimatorType /** * Return the data types that the estimator is compatible with. * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -256,7 +256,7 @@ public function variances() : array /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Clusterers/KMeans.php b/src/Clusterers/KMeans.php index 420844d63..dbb409600 100644 --- a/src/Clusterers/KMeans.php +++ b/src/Clusterers/KMeans.php @@ -196,7 +196,7 @@ public function type() : EstimatorType /** * Return the data types that the estimator is compatible with. * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -256,7 +256,7 @@ public function sizes() : array /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Clusterers/MeanShift.php b/src/Clusterers/MeanShift.php index e8ac31e53..1860b603d 100644 --- a/src/Clusterers/MeanShift.php +++ b/src/Clusterers/MeanShift.php @@ -229,7 +229,7 @@ public function type() : EstimatorType /** * Return the data types that the estimator is compatible with. * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -278,7 +278,7 @@ public function centroids() : array /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/CommitteeMachine.php b/src/CommitteeMachine.php index e1dcd6940..4116b4737 100644 --- a/src/CommitteeMachine.php +++ b/src/CommitteeMachine.php @@ -56,7 +56,7 @@ class CommitteeMachine implements Estimator, Learner, Parallel, Persistable /** * The committee of experts. i.e. the ensemble of estimators. * - * @var list<\Rubix\ML\Learner> + * @var list */ protected array $experts; @@ -70,7 +70,7 @@ class CommitteeMachine implements Estimator, Learner, Parallel, Persistable /** * The data types that the committee is compatible with. * - * @var list<\Rubix\ML\DataType> + * @var list */ protected array $compatibility; @@ -84,7 +84,7 @@ class CommitteeMachine implements Estimator, Learner, Parallel, Persistable ]; /** - * @param \Rubix\ML\Learner[] $experts + * @param Learner[] $experts * @param (int|float)[]|null $influences * @throws InvalidArgumentException */ @@ -173,7 +173,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -208,7 +208,7 @@ public function trained() : bool /** * Return the learner instances of the committee. * - * @return list<\Rubix\ML\Learner> + * @return list */ public function experts() : array { diff --git a/src/CrossValidation/Metrics/Accuracy.php b/src/CrossValidation/Metrics/Accuracy.php index 51b9052d5..f61821777 100644 --- a/src/CrossValidation/Metrics/Accuracy.php +++ b/src/CrossValidation/Metrics/Accuracy.php @@ -37,7 +37,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/Completeness.php b/src/CrossValidation/Metrics/Completeness.php index ad00d93bf..45e5d7486 100644 --- a/src/CrossValidation/Metrics/Completeness.php +++ b/src/CrossValidation/Metrics/Completeness.php @@ -42,7 +42,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/FBeta.php b/src/CrossValidation/Metrics/FBeta.php index dcad00ce7..5df4d7990 100644 --- a/src/CrossValidation/Metrics/FBeta.php +++ b/src/CrossValidation/Metrics/FBeta.php @@ -92,7 +92,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/Homogeneity.php b/src/CrossValidation/Metrics/Homogeneity.php index 04eb9fd55..622d86f04 100644 --- a/src/CrossValidation/Metrics/Homogeneity.php +++ b/src/CrossValidation/Metrics/Homogeneity.php @@ -42,7 +42,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/Informedness.php b/src/CrossValidation/Metrics/Informedness.php index 71d9eb5c7..75db35103 100644 --- a/src/CrossValidation/Metrics/Informedness.php +++ b/src/CrossValidation/Metrics/Informedness.php @@ -56,7 +56,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/MCC.php b/src/CrossValidation/Metrics/MCC.php index f460952bf..473962868 100644 --- a/src/CrossValidation/Metrics/MCC.php +++ b/src/CrossValidation/Metrics/MCC.php @@ -60,7 +60,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/MeanAbsoluteError.php b/src/CrossValidation/Metrics/MeanAbsoluteError.php index 7e56151bc..8880d74de 100644 --- a/src/CrossValidation/Metrics/MeanAbsoluteError.php +++ b/src/CrossValidation/Metrics/MeanAbsoluteError.php @@ -39,7 +39,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/MeanSquaredError.php b/src/CrossValidation/Metrics/MeanSquaredError.php index 8a732b484..f7409640e 100644 --- a/src/CrossValidation/Metrics/MeanSquaredError.php +++ b/src/CrossValidation/Metrics/MeanSquaredError.php @@ -39,7 +39,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/MedianAbsoluteError.php b/src/CrossValidation/Metrics/MedianAbsoluteError.php index 02f233d5f..dd7d6acde 100644 --- a/src/CrossValidation/Metrics/MedianAbsoluteError.php +++ b/src/CrossValidation/Metrics/MedianAbsoluteError.php @@ -38,7 +38,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/Metric.php b/src/CrossValidation/Metrics/Metric.php index fe962242a..dc2cb39ac 100644 --- a/src/CrossValidation/Metrics/Metric.php +++ b/src/CrossValidation/Metrics/Metric.php @@ -12,16 +12,16 @@ interface Metric extends Stringable * * @return \Rubix\ML\Tuple{float,float} */ - public function range() : Tuple; + public function range(): Tuple; /** * The estimator types that this metric is compatible with. * + * @return list<\Rubix\ML\EstimatorType> * @internal * - * @return list<\Rubix\ML\EstimatorType> */ - public function compatibility() : array; + public function compatibility(): array; /** * Score a set of predictions and their ground-truth labels. @@ -30,5 +30,5 @@ public function compatibility() : array; * @param list $labels * @return float */ - public function score(array $predictions, array $labels) : float; + public function score(array $predictions, array $labels): float; } diff --git a/src/CrossValidation/Metrics/RSquared.php b/src/CrossValidation/Metrics/RSquared.php index db84e579c..e110ff5a1 100644 --- a/src/CrossValidation/Metrics/RSquared.php +++ b/src/CrossValidation/Metrics/RSquared.php @@ -37,7 +37,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/RandIndex.php b/src/CrossValidation/Metrics/RandIndex.php index 7ae1b7eff..ce6d90203 100644 --- a/src/CrossValidation/Metrics/RandIndex.php +++ b/src/CrossValidation/Metrics/RandIndex.php @@ -54,7 +54,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/SMAPE.php b/src/CrossValidation/Metrics/SMAPE.php index bcbf0d13b..79b5e7063 100644 --- a/src/CrossValidation/Metrics/SMAPE.php +++ b/src/CrossValidation/Metrics/SMAPE.php @@ -44,7 +44,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Metrics/VMeasure.php b/src/CrossValidation/Metrics/VMeasure.php index 01c2e148f..80aa2ee2f 100644 --- a/src/CrossValidation/Metrics/VMeasure.php +++ b/src/CrossValidation/Metrics/VMeasure.php @@ -61,7 +61,7 @@ public function range() : Tuple * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Reports/AggregateReport.php b/src/CrossValidation/Reports/AggregateReport.php index e2c6c8a51..e57ba8032 100644 --- a/src/CrossValidation/Reports/AggregateReport.php +++ b/src/CrossValidation/Reports/AggregateReport.php @@ -22,7 +22,7 @@ class AggregateReport implements ReportGenerator * The report middleware stack. i.e. the reports to generate when the reports * method is called. * - * @var \Rubix\ML\CrossValidation\Reports\ReportGenerator[] + * @var ReportGenerator[] */ protected $reports = [ // @@ -36,7 +36,7 @@ class AggregateReport implements ReportGenerator protected $compatibility; /** - * @param \Rubix\ML\CrossValidation\Reports\ReportGenerator[] $reports + * @param ReportGenerator[] $reports * @throws InvalidArgumentException */ public function __construct(array $reports) diff --git a/src/CrossValidation/Reports/ConfusionMatrix.php b/src/CrossValidation/Reports/ConfusionMatrix.php index ec5105b71..ddf1dd4fa 100644 --- a/src/CrossValidation/Reports/ConfusionMatrix.php +++ b/src/CrossValidation/Reports/ConfusionMatrix.php @@ -28,7 +28,7 @@ class ConfusionMatrix implements ReportGenerator * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Reports/ContingencyTable.php b/src/CrossValidation/Reports/ContingencyTable.php index 8cbe77ccb..a6e6f9b58 100644 --- a/src/CrossValidation/Reports/ContingencyTable.php +++ b/src/CrossValidation/Reports/ContingencyTable.php @@ -28,7 +28,7 @@ class ContingencyTable implements ReportGenerator * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Reports/ErrorAnalysis.php b/src/CrossValidation/Reports/ErrorAnalysis.php index af15c996c..bcf9a9a36 100644 --- a/src/CrossValidation/Reports/ErrorAnalysis.php +++ b/src/CrossValidation/Reports/ErrorAnalysis.php @@ -30,7 +30,7 @@ class ErrorAnalysis implements ReportGenerator * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/CrossValidation/Reports/MulticlassBreakdown.php b/src/CrossValidation/Reports/MulticlassBreakdown.php index 50c4ba86f..8752ac99a 100644 --- a/src/CrossValidation/Reports/MulticlassBreakdown.php +++ b/src/CrossValidation/Reports/MulticlassBreakdown.php @@ -32,7 +32,7 @@ class MulticlassBreakdown implements ReportGenerator * * @internal * - * @return list<\Rubix\ML\EstimatorType> + * @return list */ public function compatibility() : array { diff --git a/src/Datasets/Dataset.php b/src/Datasets/Dataset.php index 0eb3db770..dfee28192 100644 --- a/src/Datasets/Dataset.php +++ b/src/Datasets/Dataset.php @@ -103,7 +103,7 @@ abstract public static function fromIterator(iterable $iterator) : self; /** * Stack a number of datasets on top of each other to form a single dataset. * - * @param iterable<\Rubix\ML\Datasets\Dataset> $datasets + * @param iterable $datasets * @return static */ abstract public static function stack(iterable $datasets) : self; @@ -131,7 +131,7 @@ public function size() : int /** * Return the high-level data types of each column in the data table. * - * @return list<\Rubix\ML\DataType> + * @return list */ public function types() : array { @@ -267,7 +267,7 @@ public function featureType(int $offset) : DataType /** * Return an array of feature column data types autodetected using the first sample in the dataset. * - * @return list<\Rubix\ML\DataType> + * @return list */ public function featureTypes() : array { @@ -281,7 +281,7 @@ public function featureTypes() : array /** * Return the unique feature types. * - * @return list<\Rubix\ML\DataType> + * @return list */ public function uniqueTypes() : array { diff --git a/src/Datasets/Generators/Agglomerate.php b/src/Datasets/Generators/Agglomerate.php index 7cb0307b0..4118a6aaf 100644 --- a/src/Datasets/Generators/Agglomerate.php +++ b/src/Datasets/Generators/Agglomerate.php @@ -24,7 +24,7 @@ class Agglomerate implements Generator /** * An array of generators. * - * @var \Rubix\ML\Datasets\Generators\Generator[] + * @var Generator[] */ protected array $generators; @@ -44,7 +44,7 @@ class Agglomerate implements Generator protected int $dimensions; /** - * @param \Rubix\ML\Datasets\Generators\Generator[] $generators + * @param Generator[] $generators * @param (int|float)[]|null $weights * @throws InvalidArgumentException */ diff --git a/src/Datasets/Labeled.php b/src/Datasets/Labeled.php index be7fde2e6..99bc4f690 100644 --- a/src/Datasets/Labeled.php +++ b/src/Datasets/Labeled.php @@ -95,7 +95,7 @@ public static function fromIterator(iterable $iterator) : self /** * Stack a number of datasets on top of each other to form a single dataset. * - * @param iterable<\Rubix\ML\Datasets\Labeled> $datasets + * @param iterable $datasets * @throws InvalidArgumentException * @return self */ diff --git a/src/Datasets/Unlabeled.php b/src/Datasets/Unlabeled.php index 3f9dcef03..2977f2c02 100644 --- a/src/Datasets/Unlabeled.php +++ b/src/Datasets/Unlabeled.php @@ -68,7 +68,7 @@ public static function fromIterator(iterable $iterator) : self /** * Stack a number of datasets on top of each other to form a single dataset. * - * @param iterable<\Rubix\ML\Datasets\Dataset> $datasets + * @param iterable $datasets * @throws InvalidArgumentException * @return self */ diff --git a/src/Estimator.php b/src/Estimator.php index 1572f769d..367273a73 100644 --- a/src/Estimator.php +++ b/src/Estimator.php @@ -28,7 +28,7 @@ public function type() : EstimatorType; * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array; diff --git a/src/Graph/Nodes/Ball.php b/src/Graph/Nodes/Ball.php index 8c788669b..ee6178240 100644 --- a/src/Graph/Nodes/Ball.php +++ b/src/Graph/Nodes/Ball.php @@ -44,7 +44,7 @@ class Ball implements Hypersphere, HasBinaryChildren /** * The left and right subsets of the training data. * - * @var array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} + * @var array{Labeled,Labeled} */ protected array $subsets; @@ -93,7 +93,7 @@ public static function split(Labeled $dataset, Distance $kernel) : self /** * @param list $center * @param float $radius - * @param array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} $subsets + * @param array{Labeled,Labeled} $subsets */ public function __construct(array $center, float $radius, array $subsets) { @@ -136,7 +136,7 @@ public function isPoint() : bool * Return the left and right subsets of the training data. * * @throws RuntimeException - * @return array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} + * @return array{Labeled,Labeled} */ public function subsets() : array { diff --git a/src/Graph/Nodes/Best.php b/src/Graph/Nodes/Best.php index f3ea77349..c1fa54f9e 100644 --- a/src/Graph/Nodes/Best.php +++ b/src/Graph/Nodes/Best.php @@ -48,7 +48,6 @@ class Best implements Outcome * @param (int|float)[] $probabilities * @param float $impurity * @param int $n - * @throws \Rubix\ML\Exceptions\InvalidArgumentException */ public function __construct(string $outcome, array $probabilities, float $impurity, int $n) { diff --git a/src/Graph/Nodes/Box.php b/src/Graph/Nodes/Box.php index f64470926..dbd9aa925 100644 --- a/src/Graph/Nodes/Box.php +++ b/src/Graph/Nodes/Box.php @@ -44,7 +44,7 @@ class Box implements Hypercube, HasBinaryChildren /** * The left and right subsets of the training data. * - * @var array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} + * @var array{Labeled,Labeled} */ protected array $subsets; @@ -92,7 +92,7 @@ public static function split(Labeled $dataset) : self /** * @param int $column * @param string|int|float $value - * @param array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} $subsets + * @param array{Labeled,Labeled} $subsets * @param list $min * @param list $max */ @@ -129,7 +129,7 @@ public function value() : string|int|float * Return the left and right subsets of the training data. * * @throws RuntimeException - * @return array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} + * @return array{Labeled,Labeled} */ public function subsets() : array { diff --git a/src/Graph/Nodes/Depth.php b/src/Graph/Nodes/Depth.php index 889278f46..b92317b74 100644 --- a/src/Graph/Nodes/Depth.php +++ b/src/Graph/Nodes/Depth.php @@ -61,7 +61,6 @@ public static function terminate(Dataset $dataset, int $depth) : self /** * @param float $depth - * @throws \Rubix\ML\Exceptions\InvalidArgumentException */ public function __construct(float $depth) { diff --git a/src/Graph/Nodes/HasBinaryChildren.php b/src/Graph/Nodes/HasBinaryChildren.php index 569965f8f..c935da12b 100644 --- a/src/Graph/Nodes/HasBinaryChildren.php +++ b/src/Graph/Nodes/HasBinaryChildren.php @@ -32,7 +32,7 @@ public function right() : ?BinaryNode; /** * Return the children of this node in an iterator. * - * @return \Traversable<\Rubix\ML\Graph\Nodes\BinaryNode> + * @return Traversable */ public function children() : Traversable; diff --git a/src/Graph/Nodes/Hypercube.php b/src/Graph/Nodes/Hypercube.php index 20ad310bc..c670f635a 100644 --- a/src/Graph/Nodes/Hypercube.php +++ b/src/Graph/Nodes/Hypercube.php @@ -18,7 +18,7 @@ interface Hypercube extends Node /** * Return the minimum bounding box surrounding this node. * - * @return \Traversable> + * @return Traversable> */ public function sides() : Traversable; diff --git a/src/Graph/Nodes/Isolator.php b/src/Graph/Nodes/Isolator.php index ffa1478f7..cd5df0bc5 100644 --- a/src/Graph/Nodes/Isolator.php +++ b/src/Graph/Nodes/Isolator.php @@ -48,7 +48,7 @@ class Isolator implements HasBinaryChildren /** * The left and right subsets of the training data. * - * @var array{\Rubix\ML\Datasets\Dataset,\Rubix\ML\Datasets\Dataset} + * @var array{Dataset,Dataset} */ protected array $subsets; @@ -90,8 +90,7 @@ public static function split(Dataset $dataset) : self /** * @param int $column * @param string|int|float $value - * @param array{\Rubix\ML\Datasets\Dataset,\Rubix\ML\Datasets\Dataset} $subsets - * @throws \Rubix\ML\Exceptions\InvalidArgumentException + * @param array{Dataset,Dataset} $subsets */ public function __construct(int $column, string|int|float $value, array $subsets) { @@ -124,7 +123,7 @@ public function value() : string|int|float * Return the left and right subsets of the training data. * * @throws RuntimeException - * @return array{\Rubix\ML\Datasets\Dataset,\Rubix\ML\Datasets\Dataset} + * @return array{Dataset,Dataset} */ public function subsets() : array { diff --git a/src/Graph/Nodes/Split.php b/src/Graph/Nodes/Split.php index bc60487aa..ace5aef47 100644 --- a/src/Graph/Nodes/Split.php +++ b/src/Graph/Nodes/Split.php @@ -61,7 +61,6 @@ class Split implements Decision, HasBinaryChildren * @param array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} $subsets * @param float $impurity * @param int<0,max> $n - * @throws \Rubix\ML\Exceptions\InvalidArgumentException */ public function __construct(int $column, string|int|float $value, array $subsets, float $impurity, int $n) { diff --git a/src/Graph/Nodes/Traits/HasBinaryChildrenTrait.php b/src/Graph/Nodes/Traits/HasBinaryChildrenTrait.php index 504441672..f4bfca1fa 100644 --- a/src/Graph/Nodes/Traits/HasBinaryChildrenTrait.php +++ b/src/Graph/Nodes/Traits/HasBinaryChildrenTrait.php @@ -35,7 +35,7 @@ trait HasBinaryChildrenTrait /** * Return the children of this node in a generator. * - * @return \Generator<\Rubix\ML\Graph\Nodes\BinaryNode> + * @return \Generator */ public function children() : Traversable { diff --git a/src/Graph/Nodes/VantagePoint.php b/src/Graph/Nodes/VantagePoint.php index 595108452..9cb4ca572 100644 --- a/src/Graph/Nodes/VantagePoint.php +++ b/src/Graph/Nodes/VantagePoint.php @@ -129,7 +129,7 @@ public function radius() : float * Return the left and right subsets of the training data. * * @throws RuntimeException - * @return array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} + * @return array{Labeled,Labeled} */ public function subsets() : array { diff --git a/src/Graph/Trees/BallTree.php b/src/Graph/Trees/BallTree.php index 649ad0b55..70efb870c 100644 --- a/src/Graph/Trees/BallTree.php +++ b/src/Graph/Trees/BallTree.php @@ -301,7 +301,7 @@ public function destroy() : void * Return the path of a sample taken from the root node to a leaf node in an array. * * @param list $sample - * @return list<\Rubix\ML\Graph\Nodes\Hypersphere> + * @return list */ protected function path(array $sample) : array { diff --git a/src/Graph/Trees/DecisionTree.php b/src/Graph/Trees/DecisionTree.php index 764cb42a2..cb24c564c 100644 --- a/src/Graph/Trees/DecisionTree.php +++ b/src/Graph/Trees/DecisionTree.php @@ -303,7 +303,7 @@ public function featureImportances() : array /** * Return an iterator for all the nodes in the tree starting at the root and traversing depth first. * - * @return \Generator<\Rubix\ML\Graph\Nodes\BinaryNode> + * @return \Generator */ public function getIterator() : Traversable { @@ -377,7 +377,7 @@ abstract protected function impurity(array $labels) : float; /** * Calculate the impurity of a given split. * - * @param array{\Rubix\ML\Datasets\Labeled,\Rubix\ML\Datasets\Labeled} $subsets + * @param array{Labeled,Labeled} $subsets * @return float */ protected function splitImpurity(array $subsets) : float diff --git a/src/GridSearch.php b/src/GridSearch.php index bff17ddd4..6d4a95fb8 100644 --- a/src/GridSearch.php +++ b/src/GridSearch.php @@ -196,7 +196,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Canberra.php b/src/Kernels/Distance/Canberra.php index a69ce6255..92aed3130 100644 --- a/src/Kernels/Distance/Canberra.php +++ b/src/Kernels/Distance/Canberra.php @@ -28,7 +28,7 @@ class Canberra implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Cosine.php b/src/Kernels/Distance/Cosine.php index e1a71b2bc..0635a20ce 100644 --- a/src/Kernels/Distance/Cosine.php +++ b/src/Kernels/Distance/Cosine.php @@ -27,7 +27,7 @@ class Cosine implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Diagonal.php b/src/Kernels/Distance/Diagonal.php index ea03044e2..ff14e79b9 100644 --- a/src/Kernels/Distance/Diagonal.php +++ b/src/Kernels/Distance/Diagonal.php @@ -22,7 +22,7 @@ class Diagonal implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Euclidean.php b/src/Kernels/Distance/Euclidean.php index eb478cecf..5f27dc84b 100644 --- a/src/Kernels/Distance/Euclidean.php +++ b/src/Kernels/Distance/Euclidean.php @@ -21,7 +21,7 @@ class Euclidean implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Gower.php b/src/Kernels/Distance/Gower.php index 3932ec4b7..741db1172 100644 --- a/src/Kernels/Distance/Gower.php +++ b/src/Kernels/Distance/Gower.php @@ -51,7 +51,7 @@ public function __construct(float $range = 1.0) /** * Return the data types that this kernel is compatible with. * - * @return \Rubix\ML\DataType[] + * @return DataType[] */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Hamming.php b/src/Kernels/Distance/Hamming.php index 8756f2fea..28def1d7a 100644 --- a/src/Kernels/Distance/Hamming.php +++ b/src/Kernels/Distance/Hamming.php @@ -24,7 +24,7 @@ class Hamming implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Jaccard.php b/src/Kernels/Distance/Jaccard.php index 7534afb49..7a2cec004 100644 --- a/src/Kernels/Distance/Jaccard.php +++ b/src/Kernels/Distance/Jaccard.php @@ -24,7 +24,7 @@ class Jaccard implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Manhattan.php b/src/Kernels/Distance/Manhattan.php index 9008726ea..803cffb3d 100644 --- a/src/Kernels/Distance/Manhattan.php +++ b/src/Kernels/Distance/Manhattan.php @@ -21,7 +21,7 @@ class Manhattan implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/Minkowski.php b/src/Kernels/Distance/Minkowski.php index 35f58f6c8..60a0f2f33 100644 --- a/src/Kernels/Distance/Minkowski.php +++ b/src/Kernels/Distance/Minkowski.php @@ -54,7 +54,7 @@ public function __construct(float $lambda = 3.0) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/SafeEuclidean.php b/src/Kernels/Distance/SafeEuclidean.php index 84824c85b..b8bc9d009 100644 --- a/src/Kernels/Distance/SafeEuclidean.php +++ b/src/Kernels/Distance/SafeEuclidean.php @@ -30,7 +30,7 @@ class SafeEuclidean implements Distance, NaNSafe * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Kernels/Distance/SparseCosine.php b/src/Kernels/Distance/SparseCosine.php index 5ee9d5ae8..52e547c04 100644 --- a/src/Kernels/Distance/SparseCosine.php +++ b/src/Kernels/Distance/SparseCosine.php @@ -20,7 +20,7 @@ class SparseCosine implements Distance * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/NeuralNet/Layers/BatchNorm.php b/src/NeuralNet/Layers/BatchNorm.php index 2fdddb8f1..421ec9607 100644 --- a/src/NeuralNet/Layers/BatchNorm.php +++ b/src/NeuralNet/Layers/BatchNorm.php @@ -299,7 +299,7 @@ public function gradient(Matrix $dOut, ColumnVector $gamma, ColumnVector $stdInv * @internal * * @throws RuntimeException - * @return \Generator<\Rubix\ML\NeuralNet\Parameter> + * @return Generator */ public function parameters() : Generator { @@ -316,7 +316,7 @@ public function parameters() : Generator * * @internal * - * @param \Rubix\ML\NeuralNet\Parameter[] $parameters + * @param Parameter[] $parameters */ public function restore(array $parameters) : void { diff --git a/src/NeuralNet/Layers/Binary.php b/src/NeuralNet/Layers/Binary.php index 0d3316b92..15de3942c 100644 --- a/src/NeuralNet/Layers/Binary.php +++ b/src/NeuralNet/Layers/Binary.php @@ -149,7 +149,7 @@ public function infer(Matrix $input) : Matrix * @param string[] $labels * @param Optimizer $optimizer * @throws RuntimeException - * @return (\Rubix\ML\Deferred|float)[] + * @return (Deferred|float)[] */ public function back(array $labels, Optimizer $optimizer) : array { diff --git a/src/NeuralNet/Layers/Continuous.php b/src/NeuralNet/Layers/Continuous.php index 8a67fb2b3..10805e09a 100644 --- a/src/NeuralNet/Layers/Continuous.php +++ b/src/NeuralNet/Layers/Continuous.php @@ -103,7 +103,7 @@ public function infer(Matrix $input) : Matrix * @param (int|float)[] $labels * @param Optimizer $optimizer * @throws RuntimeException - * @return (\Rubix\ML\Deferred|float)[] + * @return (Deferred|float)[] */ public function back(array $labels, Optimizer $optimizer) : array { diff --git a/src/NeuralNet/Layers/Dense.php b/src/NeuralNet/Layers/Dense.php index 9b84629ed..6c3afc583 100644 --- a/src/NeuralNet/Layers/Dense.php +++ b/src/NeuralNet/Layers/Dense.php @@ -285,7 +285,7 @@ public function gradient(Matrix $weights, Matrix $dOut) : Matrix * @internal * * @throws RuntimeException - * @return \Generator<\Rubix\ML\NeuralNet\Parameter> + * @return Generator */ public function parameters() : Generator { @@ -305,7 +305,7 @@ public function parameters() : Generator * * @internal * - * @param \Rubix\ML\NeuralNet\Parameter[] $parameters + * @param Parameter[] $parameters */ public function restore(array $parameters) : void { diff --git a/src/NeuralNet/Layers/Multiclass.php b/src/NeuralNet/Layers/Multiclass.php index da9119774..f7f731337 100644 --- a/src/NeuralNet/Layers/Multiclass.php +++ b/src/NeuralNet/Layers/Multiclass.php @@ -149,7 +149,7 @@ public function infer(Matrix $input) : Matrix * @param string[] $labels * @param Optimizer $optimizer * @throws RuntimeException - * @return (\Rubix\ML\Deferred|float)[] + * @return (Deferred|float)[] */ public function back(array $labels, Optimizer $optimizer) : array { diff --git a/src/NeuralNet/Layers/PReLU.php b/src/NeuralNet/Layers/PReLU.php index 874d6fadf..3a262db82 100644 --- a/src/NeuralNet/Layers/PReLU.php +++ b/src/NeuralNet/Layers/PReLU.php @@ -185,7 +185,7 @@ public function gradient($input, $dOut) : Matrix * @internal * * @throws \RuntimeException - * @return \Generator<\Rubix\ML\NeuralNet\Parameter> + * @return Generator */ public function parameters() : Generator { @@ -201,7 +201,7 @@ public function parameters() : Generator * * @internal * - * @param \Rubix\ML\NeuralNet\Parameter[] $parameters + * @param Parameter[] $parameters */ public function restore(array $parameters) : void { diff --git a/src/NeuralNet/Layers/Parametric.php b/src/NeuralNet/Layers/Parametric.php index 256cb14db..8b373cb26 100644 --- a/src/NeuralNet/Layers/Parametric.php +++ b/src/NeuralNet/Layers/Parametric.php @@ -18,7 +18,7 @@ interface Parametric /** * Return the parameters of the layer. * - * @return \Generator<\Rubix\ML\NeuralNet\Parameter> + * @return Generator<\Rubix\ML\NeuralNet\Parameter> */ public function parameters() : Generator; diff --git a/src/NeuralNet/Layers/Swish.php b/src/NeuralNet/Layers/Swish.php index 2c60805ce..9666183a8 100644 --- a/src/NeuralNet/Layers/Swish.php +++ b/src/NeuralNet/Layers/Swish.php @@ -207,7 +207,7 @@ public function gradient($input, $output, $dOut) : Matrix * @internal * * @throws \RuntimeException - * @return \Generator<\Rubix\ML\NeuralNet\Parameter> + * @return Generator */ public function parameters() : Generator { @@ -223,7 +223,7 @@ public function parameters() : Generator * * @internal * - * @param \Rubix\ML\NeuralNet\Parameter[] $parameters + * @param Parameter[] $parameters */ public function restore(array $parameters) : void { diff --git a/src/NeuralNet/Network.php b/src/NeuralNet/Network.php index 331fd539a..57e7cfd25 100644 --- a/src/NeuralNet/Network.php +++ b/src/NeuralNet/Network.php @@ -39,7 +39,7 @@ class Network /** * The hidden layers of the network. * - * @var list<\Rubix\ML\NeuralNet\Layers\Hidden> + * @var list */ protected array $hidden = [ // @@ -48,7 +48,7 @@ class Network /** * The pathing of the backward pass through the hidden layers. * - * @var list<\Rubix\ML\NeuralNet\Layers\Hidden> + * @var list */ protected array $backPass = [ // @@ -70,7 +70,7 @@ class Network /** * @param Input $input - * @param \Rubix\ML\NeuralNet\Layers\Hidden[] $hidden + * @param Layers\Hidden[] $hidden * @param Output $output * @param Optimizer $optimizer */ @@ -100,7 +100,7 @@ public function input() : Input /** * Return an array of hidden layers indexed left to right. * - * @return list<\Rubix\ML\NeuralNet\Layers\Hidden> + * @return list */ public function hidden() : array { @@ -120,7 +120,7 @@ public function output() : Output /** * Return all the layers in the network. * - * @return \Traversable<\Rubix\ML\NeuralNet\Layers\Layer> + * @return Traversable */ public function layers() : Traversable { diff --git a/src/NeuralNet/Optimizers/AdaGrad.php b/src/NeuralNet/Optimizers/AdaGrad.php index 699a86ead..fe2421d48 100644 --- a/src/NeuralNet/Optimizers/AdaGrad.php +++ b/src/NeuralNet/Optimizers/AdaGrad.php @@ -38,7 +38,7 @@ class AdaGrad implements Optimizer, Adaptive /** * The cache of sum of squared gradients. * - * @var \Tensor\Tensor[] + * @var Tensor[] */ protected array $cache = [ // @@ -83,8 +83,8 @@ public function warm(Parameter $param) : void * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Optimizers/AdaMax.php b/src/NeuralNet/Optimizers/AdaMax.php index 25d99e13f..d5dad548b 100644 --- a/src/NeuralNet/Optimizers/AdaMax.php +++ b/src/NeuralNet/Optimizers/AdaMax.php @@ -75,8 +75,8 @@ public function __construct(float $rate = 0.001, float $momentumDecay = 0.1, flo * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Optimizers/Adam.php b/src/NeuralNet/Optimizers/Adam.php index a2955917f..1e7fbf9d0 100644 --- a/src/NeuralNet/Optimizers/Adam.php +++ b/src/NeuralNet/Optimizers/Adam.php @@ -54,7 +54,7 @@ class Adam implements Optimizer, Adaptive /** * The parameter cache of running velocity and squared gradients. * - * @var array<\Tensor\Tensor[]> + * @var array */ protected array $cache = [ // @@ -115,8 +115,8 @@ public function warm(Parameter $param) : void * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Optimizers/Cyclical.php b/src/NeuralNet/Optimizers/Cyclical.php index 498134613..dcce49bf2 100644 --- a/src/NeuralNet/Optimizers/Cyclical.php +++ b/src/NeuralNet/Optimizers/Cyclical.php @@ -112,8 +112,8 @@ public function __construct( * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Optimizers/Momentum.php b/src/NeuralNet/Optimizers/Momentum.php index 84526727f..dac39e841 100644 --- a/src/NeuralNet/Optimizers/Momentum.php +++ b/src/NeuralNet/Optimizers/Momentum.php @@ -50,7 +50,7 @@ class Momentum implements Optimizer, Adaptive /** * The parameter cache of velocity matrices. * - * @var \Tensor\Tensor[] + * @var Tensor[] */ protected array $cache = [ // @@ -104,8 +104,8 @@ public function warm(Parameter $param) : void * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Optimizers/Optimizer.php b/src/NeuralNet/Optimizers/Optimizer.php index ab80c14d3..d96ea4fa2 100644 --- a/src/NeuralNet/Optimizers/Optimizer.php +++ b/src/NeuralNet/Optimizers/Optimizer.php @@ -21,8 +21,8 @@ interface Optimizer extends Stringable * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor; } diff --git a/src/NeuralNet/Optimizers/RMSProp.php b/src/NeuralNet/Optimizers/RMSProp.php index 66a05d147..be24b213b 100644 --- a/src/NeuralNet/Optimizers/RMSProp.php +++ b/src/NeuralNet/Optimizers/RMSProp.php @@ -51,7 +51,7 @@ class RMSProp implements Optimizer, Adaptive /** * The cache of running squared gradients. * - * @var \Tensor\Tensor[] + * @var Tensor[] */ protected array $cache = [ // @@ -104,8 +104,8 @@ public function warm(Parameter $param) : void * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Optimizers/StepDecay.php b/src/NeuralNet/Optimizers/StepDecay.php index 8db70defe..782f94002 100644 --- a/src/NeuralNet/Optimizers/StepDecay.php +++ b/src/NeuralNet/Optimizers/StepDecay.php @@ -81,8 +81,8 @@ public function __construct(float $rate = 0.01, int $losses = 100, float $decay * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Optimizers/Stochastic.php b/src/NeuralNet/Optimizers/Stochastic.php index 929d7a885..0e1151b0a 100644 --- a/src/NeuralNet/Optimizers/Stochastic.php +++ b/src/NeuralNet/Optimizers/Stochastic.php @@ -44,8 +44,8 @@ public function __construct(float $rate = 0.01) * @internal * * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @return \Tensor\Tensor + * @param Tensor $gradient + * @return Tensor */ public function step(Parameter $param, Tensor $gradient) : Tensor { diff --git a/src/NeuralNet/Snapshot.php b/src/NeuralNet/Snapshot.php index 552438271..b259b9158 100644 --- a/src/NeuralNet/Snapshot.php +++ b/src/NeuralNet/Snapshot.php @@ -21,14 +21,14 @@ class Snapshot /** * The parametric layers of the network. * - * @var \Rubix\ML\NeuralNet\Layers\Parametric[] + * @var Parametric[] */ protected array $layers; /** * The parameters corresponding to each layer in the network at the time of the snapshot. * - * @var list<\Rubix\ML\NeuralNet\Parameter[]> + * @var list */ protected array $parameters; @@ -56,8 +56,8 @@ public static function take(Network $network) : self } /** - * @param \Rubix\ML\NeuralNet\Layers\Parametric[] $layers - * @param list<\Rubix\ML\NeuralNet\Parameter[]> $parameters + * @param Parametric[] $layers + * @param list $parameters * @throws InvalidArgumentException */ public function __construct(array $layers, array $parameters) diff --git a/src/PersistentModel.php b/src/PersistentModel.php index c1d631a5a..5e0129b04 100644 --- a/src/PersistentModel.php +++ b/src/PersistentModel.php @@ -101,7 +101,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Pipeline.php b/src/Pipeline.php index 4d491940c..3cae2397b 100644 --- a/src/Pipeline.php +++ b/src/Pipeline.php @@ -32,7 +32,7 @@ class Pipeline implements Online, Probabilistic, Scoring, Persistable, Estimator /** * A list of transformers to be applied in series. * - * @var list<\Rubix\ML\Transformers\Transformer> + * @var list */ protected array $transformers = [ // @@ -53,7 +53,7 @@ class Pipeline implements Online, Probabilistic, Scoring, Persistable, Estimator protected bool $elastic; /** - * @param \Rubix\ML\Transformers\Transformer[] $transformers + * @param Transformer[] $transformers * @param Estimator $base * @param bool $elastic * @throws InvalidArgumentException @@ -89,7 +89,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Regressors/Adaline.php b/src/Regressors/Adaline.php index 38686a550..0b54e47e2 100644 --- a/src/Regressors/Adaline.php +++ b/src/Regressors/Adaline.php @@ -190,7 +190,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -232,7 +232,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Regressors/ExtraTreeRegressor.php b/src/Regressors/ExtraTreeRegressor.php index 0965bd7f5..70fec0131 100644 --- a/src/Regressors/ExtraTreeRegressor.php +++ b/src/Regressors/ExtraTreeRegressor.php @@ -74,7 +74,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Regressors/GradientBoost.php b/src/Regressors/GradientBoost.php index b9562b970..d203a401a 100644 --- a/src/Regressors/GradientBoost.php +++ b/src/Regressors/GradientBoost.php @@ -318,7 +318,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Regressors/MLPRegressor.php b/src/Regressors/MLPRegressor.php index 4a901c162..e7c4663a9 100644 --- a/src/Regressors/MLPRegressor.php +++ b/src/Regressors/MLPRegressor.php @@ -66,7 +66,7 @@ class MLPRegressor implements Estimator, Learner, Online, Verbose, Persistable /** * An array composing the user-specified hidden layers of the network in order. * - * @var \Rubix\ML\NeuralNet\Layers\Hidden[] + * @var Hidden[] */ protected array $hiddenLayers = [ // @@ -157,7 +157,7 @@ class MLPRegressor implements Estimator, Learner, Online, Verbose, Persistable protected ?array $losses = null; /** - * @param \Rubix\ML\NeuralNet\Layers\Hidden[] $hiddenLayers + * @param Hidden[] $hiddenLayers * @param int $batchSize * @param Optimizer|null $optimizer * @param int $epochs @@ -251,7 +251,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { @@ -296,7 +296,7 @@ public function trained() : bool /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Regressors/RegressionTree.php b/src/Regressors/RegressionTree.php index 7655b1c03..cce46f8c9 100644 --- a/src/Regressors/RegressionTree.php +++ b/src/Regressors/RegressionTree.php @@ -76,7 +76,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Regressors/Ridge.php b/src/Regressors/Ridge.php index 990ec9707..7afb48b65 100644 --- a/src/Regressors/Ridge.php +++ b/src/Regressors/Ridge.php @@ -94,7 +94,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Regressors/SVR.php b/src/Regressors/SVR.php index b0654a1e2..2948f67dd 100644 --- a/src/Regressors/SVR.php +++ b/src/Regressors/SVR.php @@ -154,7 +154,7 @@ public function type() : EstimatorType * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Specifications/SpecificationChain.php b/src/Specifications/SpecificationChain.php index 873cf6c6e..37ada01ea 100644 --- a/src/Specifications/SpecificationChain.php +++ b/src/Specifications/SpecificationChain.php @@ -10,14 +10,14 @@ class SpecificationChain extends Specification /** * A list of specifications to check in order. * - * @var iterable<\Rubix\ML\Specifications\Specification> + * @var iterable */ protected iterable $specifications; /** * Build a specification object with the given arguments. * - * @param iterable<\Rubix\ML\Specifications\Specification> $specifications + * @param iterable $specifications * @return self */ public static function with(iterable $specifications) : self @@ -26,8 +26,7 @@ public static function with(iterable $specifications) : self } /** - * @param iterable<\Rubix\ML\Specifications\Specification> $specifications - * @throws \Rubix\ML\Exceptions\InvalidArgumentException + * @param iterable $specifications */ public function __construct(iterable $specifications) { diff --git a/src/Specifications/SwooleExtensionIsLoaded.php b/src/Specifications/SwooleExtensionIsLoaded.php index d15342649..97d373645 100644 --- a/src/Specifications/SwooleExtensionIsLoaded.php +++ b/src/Specifications/SwooleExtensionIsLoaded.php @@ -19,10 +19,7 @@ public static function create() : self */ public function check() : void { - if ( - ExtensionIsLoaded::with('swoole')->passes() - || ExtensionIsLoaded::with('openswoole')->passes() - ) { + if (ExtensionIsLoaded::with('swoole')->passes()) { return; } diff --git a/src/Transformers/BM25Transformer.php b/src/Transformers/BM25Transformer.php index fa552b013..fd8172e58 100644 --- a/src/Transformers/BM25Transformer.php +++ b/src/Transformers/BM25Transformer.php @@ -109,7 +109,7 @@ public function __construct(float $dampening = 1.2, float $normalization = 0.75) /** * Return the data types that this transformer is compatible with. * - * @return \Rubix\ML\DataType[] + * @return DataType[] */ public function compatibility() : array { diff --git a/src/Transformers/BooleanConverter.php b/src/Transformers/BooleanConverter.php index fca521522..95d6d2158 100644 --- a/src/Transformers/BooleanConverter.php +++ b/src/Transformers/BooleanConverter.php @@ -60,7 +60,7 @@ public function __construct(string|int $trueValue = 'true', string|int $falseVal * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/GaussianRandomProjector.php b/src/Transformers/GaussianRandomProjector.php index 30b3a1133..a61ae19d8 100644 --- a/src/Transformers/GaussianRandomProjector.php +++ b/src/Transformers/GaussianRandomProjector.php @@ -88,7 +88,7 @@ public function __construct(int $dimensions) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/HotDeckImputer.php b/src/Transformers/HotDeckImputer.php index fcaaafdd2..1e0a06c6f 100644 --- a/src/Transformers/HotDeckImputer.php +++ b/src/Transformers/HotDeckImputer.php @@ -117,7 +117,7 @@ public function __construct( * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/ImageResizer.php b/src/Transformers/ImageResizer.php index b9bd48e3e..af6de78f2 100644 --- a/src/Transformers/ImageResizer.php +++ b/src/Transformers/ImageResizer.php @@ -65,7 +65,7 @@ public function __construct(int $width = 32, int $height = 32) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/ImageRotator.php b/src/Transformers/ImageRotator.php index ff261d186..20afaaa8f 100644 --- a/src/Transformers/ImageRotator.php +++ b/src/Transformers/ImageRotator.php @@ -72,7 +72,7 @@ public function __construct(float $offset, float $jitter = 0.0) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/ImageVectorizer.php b/src/Transformers/ImageVectorizer.php index 564bbb296..c45f3101b 100644 --- a/src/Transformers/ImageVectorizer.php +++ b/src/Transformers/ImageVectorizer.php @@ -55,7 +55,7 @@ public function __construct(bool $grayscale = false) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/IntervalDiscretizer.php b/src/Transformers/IntervalDiscretizer.php index 917494e13..edce1bf12 100644 --- a/src/Transformers/IntervalDiscretizer.php +++ b/src/Transformers/IntervalDiscretizer.php @@ -97,7 +97,7 @@ public function __construct(int $bins = 5, bool $equiWidth = false) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/KNNImputer.php b/src/Transformers/KNNImputer.php index 971ba7d3e..c3e0c2009 100644 --- a/src/Transformers/KNNImputer.php +++ b/src/Transformers/KNNImputer.php @@ -78,7 +78,7 @@ class KNNImputer implements Transformer, Stateful, Persistable /** * The data types of the fitted feature columns. * - * @var \Rubix\ML\DataType[]|null + * @var DataType[]|null */ protected ?array $types = null; @@ -124,7 +124,7 @@ public function __construct( * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/L1Normalizer.php b/src/Transformers/L1Normalizer.php index cd90757a5..1c2c8cdb5 100644 --- a/src/Transformers/L1Normalizer.php +++ b/src/Transformers/L1Normalizer.php @@ -26,7 +26,7 @@ class L1Normalizer implements Transformer * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/L2Normalizer.php b/src/Transformers/L2Normalizer.php index fcdc501c5..3aa0790d3 100644 --- a/src/Transformers/L2Normalizer.php +++ b/src/Transformers/L2Normalizer.php @@ -25,7 +25,7 @@ class L2Normalizer implements Transformer * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/LambdaFunction.php b/src/Transformers/LambdaFunction.php index 30a24dfc7..fa1dd140e 100644 --- a/src/Transformers/LambdaFunction.php +++ b/src/Transformers/LambdaFunction.php @@ -45,7 +45,7 @@ public function __construct(callable $callback, mixed $context = null) /** * Return the data types that this transformer is compatible with. * - * @return \Rubix\ML\DataType[] + * @return DataType[] */ public function compatibility() : array { diff --git a/src/Transformers/LinearDiscriminantAnalysis.php b/src/Transformers/LinearDiscriminantAnalysis.php index 0eb56dc85..7e648ed3a 100644 --- a/src/Transformers/LinearDiscriminantAnalysis.php +++ b/src/Transformers/LinearDiscriminantAnalysis.php @@ -82,7 +82,7 @@ public function __construct(int $dimensions) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/MaxAbsoluteScaler.php b/src/Transformers/MaxAbsoluteScaler.php index 6adc6746a..bdf84b9db 100644 --- a/src/Transformers/MaxAbsoluteScaler.php +++ b/src/Transformers/MaxAbsoluteScaler.php @@ -37,7 +37,7 @@ class MaxAbsoluteScaler implements Transformer, Stateful, Elastic, Reversible, P * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/MinMaxNormalizer.php b/src/Transformers/MinMaxNormalizer.php index 38c17c3f6..b498f7eb9 100644 --- a/src/Transformers/MinMaxNormalizer.php +++ b/src/Transformers/MinMaxNormalizer.php @@ -85,7 +85,7 @@ public function __construct(float $min = 0.0, float $max = 1.0) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/MissingDataImputer.php b/src/Transformers/MissingDataImputer.php index 415ac90d1..614938d6d 100644 --- a/src/Transformers/MissingDataImputer.php +++ b/src/Transformers/MissingDataImputer.php @@ -53,14 +53,14 @@ class MissingDataImputer implements Transformer, Stateful, Persistable /** * The fitted guessing strategy for each feature column. * - * @var list<\Rubix\ML\Strategies\Strategy>|null + * @var list|null */ protected ?array $strategies = null; /** * The data types of the fitted feature columns. * - * @var list<\Rubix\ML\DataType>|null + * @var list|null */ protected ?array $types = null; @@ -95,7 +95,7 @@ public function __construct( * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/MultibyteTextNormalizer.php b/src/Transformers/MultibyteTextNormalizer.php index ec3bad052..f391bbb1d 100644 --- a/src/Transformers/MultibyteTextNormalizer.php +++ b/src/Transformers/MultibyteTextNormalizer.php @@ -43,7 +43,7 @@ public function __construct(bool $uppercase = false) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/NumericStringConverter.php b/src/Transformers/NumericStringConverter.php index f253977af..d2189bc53 100644 --- a/src/Transformers/NumericStringConverter.php +++ b/src/Transformers/NumericStringConverter.php @@ -25,7 +25,7 @@ class NumericStringConverter implements Transformer, Reversible * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/OneHotEncoder.php b/src/Transformers/OneHotEncoder.php index 99373c935..04aea40a4 100644 --- a/src/Transformers/OneHotEncoder.php +++ b/src/Transformers/OneHotEncoder.php @@ -46,7 +46,7 @@ class OneHotEncoder implements Transformer, Stateful, Persistable * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/PolynomialExpander.php b/src/Transformers/PolynomialExpander.php index c0ccb056c..646337a60 100644 --- a/src/Transformers/PolynomialExpander.php +++ b/src/Transformers/PolynomialExpander.php @@ -44,7 +44,7 @@ public function __construct(int $degree = 2) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/PrincipalComponentAnalysis.php b/src/Transformers/PrincipalComponentAnalysis.php index ac9b99f57..13e2379f1 100644 --- a/src/Transformers/PrincipalComponentAnalysis.php +++ b/src/Transformers/PrincipalComponentAnalysis.php @@ -93,7 +93,7 @@ public function __construct(int $dimensions) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/RegexFilter.php b/src/Transformers/RegexFilter.php index 99122d014..cbcfdf451 100644 --- a/src/Transformers/RegexFilter.php +++ b/src/Transformers/RegexFilter.php @@ -124,7 +124,7 @@ public function __construct(array $patterns) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/RobustStandardizer.php b/src/Transformers/RobustStandardizer.php index b535f3c16..cada404d5 100644 --- a/src/Transformers/RobustStandardizer.php +++ b/src/Transformers/RobustStandardizer.php @@ -65,7 +65,7 @@ public function __construct(bool $center = true) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/TSNE.php b/src/Transformers/TSNE.php index dcf99e15b..d6b81b16d 100644 --- a/src/Transformers/TSNE.php +++ b/src/Transformers/TSNE.php @@ -286,7 +286,7 @@ public function compatibility() : array /** * Return an iterable progress table with the steps from the last training session. * - * @return \Generator + * @return Generator */ public function steps() : Generator { diff --git a/src/Transformers/TextNormalizer.php b/src/Transformers/TextNormalizer.php index 6c3f8ac30..c659e6096 100644 --- a/src/Transformers/TextNormalizer.php +++ b/src/Transformers/TextNormalizer.php @@ -39,7 +39,7 @@ public function __construct(bool $uppercase = false) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/TfIdfTransformer.php b/src/Transformers/TfIdfTransformer.php index 9b606705b..82dc360c9 100644 --- a/src/Transformers/TfIdfTransformer.php +++ b/src/Transformers/TfIdfTransformer.php @@ -95,7 +95,7 @@ public function __construct(float $smoothing = 1.0, bool $sublinear = false) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/TokenHashingVectorizer.php b/src/Transformers/TokenHashingVectorizer.php index 3c994bc24..f3a2584d6 100644 --- a/src/Transformers/TokenHashingVectorizer.php +++ b/src/Transformers/TokenHashingVectorizer.php @@ -123,7 +123,7 @@ public function __construct(int $dimensions, ?Tokenizer $tokenizer = null, ?call /** * Return the data types that this transformer is compatible with. * - * @return \Rubix\ML\DataType[] + * @return DataType[] */ public function compatibility() : array { diff --git a/src/Transformers/TruncatedSVD.php b/src/Transformers/TruncatedSVD.php index 345679213..076e1c016 100644 --- a/src/Transformers/TruncatedSVD.php +++ b/src/Transformers/TruncatedSVD.php @@ -82,7 +82,7 @@ public function __construct(int $dimensions) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/WordCountVectorizer.php b/src/Transformers/WordCountVectorizer.php index 74b335b3b..b6329cfff 100644 --- a/src/Transformers/WordCountVectorizer.php +++ b/src/Transformers/WordCountVectorizer.php @@ -109,7 +109,7 @@ public function __construct( * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/src/Transformers/ZScaleStandardizer.php b/src/Transformers/ZScaleStandardizer.php index 5425bb7b2..39886a8be 100644 --- a/src/Transformers/ZScaleStandardizer.php +++ b/src/Transformers/ZScaleStandardizer.php @@ -77,7 +77,7 @@ public function __construct(bool $center = true) * * @internal * - * @return list<\Rubix\ML\DataType> + * @return list */ public function compatibility() : array { diff --git a/tests/AnomalyDetectors/GaussianMLETest.php b/tests/AnomalyDetectors/GaussianMLETest.php index 366e4adb1..57e922a4d 100644 --- a/tests/AnomalyDetectors/GaussianMLETest.php +++ b/tests/AnomalyDetectors/GaussianMLETest.php @@ -1,15 +1,14 @@ generator = new Agglomerate([ - 0 => new Blob([0.0, 0.0], 2.0), - 1 => new Circle(0.0, 0.0, 8.0, 1.0), - ], [0.9, 0.1]); - - $this->estimator = new GaussianMLE(0.1, 1e-8); + $this->generator = new Agglomerate( + generators: [ + new Blob( + center: [0.0, 0.0], + stdDev: 2.0 + ), + new Circle( + x: 0.0, + y: 0.0, + scale: 8.0, + noise: 1.0 + ), + ], + weights: [0.9, 0.1] + ); + + $this->estimator = new GaussianMLE( + contamination: 0.1, + smoothing: 1e-8 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GaussianMLE::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Scoring::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::anomalyDetector(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -123,10 +95,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'contamination' => 0.1, @@ -136,10 +105,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -154,37 +120,34 @@ public function trainPartialPredict() : void $means = $this->estimator->means(); - $this->assertIsArray($means); $this->assertCount(2, $means); - $this->assertContainsOnly('float', $means); + $this->assertContainsOnlyFloat($means); $variances = $this->estimator->variances(); - $this->assertIsArray($variances); $this->assertCount(2, $variances); - $this->assertContainsOnly('float', $variances); + $this->assertContainsOnlyFloat($variances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Unlabeled::quick([['bad']])); + $this->estimator->train(Unlabeled::quick(samples: [['bad']])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/AnomalyDetectors/IsolationForestTest.php b/tests/AnomalyDetectors/IsolationForestTest.php index 1cb0468c9..6f4a588a1 100644 --- a/tests/AnomalyDetectors/IsolationForestTest.php +++ b/tests/AnomalyDetectors/IsolationForestTest.php @@ -1,14 +1,14 @@ generator = new Agglomerate([ - 0 => new Blob([0.0, 0.0], 2.0), - 1 => new Circle(0.0, 0.0, 8.0, 1.0), - ], [0.9, 0.1]); - - $this->estimator = new IsolationForest(300, 0.2, 0.1); + $this->generator = new Agglomerate( + generators: [ + new Blob( + center: [0.0, 0.0], + stdDev: 2.0 + ), + new Circle( + x: 0.0, + y: 0.0, + scale: 8.0, + noise: 1.0 + ), + ], + weights: [0.9, 0.1] + ); + + $this->estimator = new IsolationForest( + estimators: 300, + ratio: 0.2, + contamination: 0.1 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(IsolationForest::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Scoring::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badNumEstimators() : void + public function testBadNumEstimators() : void { $this->expectException(InvalidArgumentException::class); - new IsolationForest(-100); + new IsolationForest(estimators: -100); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::anomalyDetector(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -132,10 +104,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'estimators' => 300, @@ -146,10 +115,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -160,15 +126,17 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/AnomalyDetectors/LocalOutlierFactorTest.php b/tests/AnomalyDetectors/LocalOutlierFactorTest.php index 2a4e0a7a7..7b9b2a1e5 100644 --- a/tests/AnomalyDetectors/LocalOutlierFactorTest.php +++ b/tests/AnomalyDetectors/LocalOutlierFactorTest.php @@ -1,15 +1,15 @@ generator = new Agglomerate([ - 0 => new Blob([0.0, 0.0], 2.0), - 1 => new Circle(0.0, 0.0, 8.0, 1.0), - ], [0.9, 0.1]); - - $this->estimator = new LocalOutlierFactor(60, 0.1, new KDTree()); + $this->generator = new Agglomerate( + generators: [ + new Blob( + center: [0.0, 0.0], + stdDev: 2.0 + ), + new Circle( + x: 0.0, + y: 0.0, + scale: 8.0, + noise: 1.0 + ), + ], + weights: [0.9, 0.1] + ); + + $this->estimator = new LocalOutlierFactor( + k: 60, + contamination: 0.1, + tree: new KDTree() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LocalOutlierFactor::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Scoring::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badK() : void + public function testBadK() : void { $this->expectException(InvalidArgumentException::class); - new LocalOutlierFactor(0); + new LocalOutlierFactor(k: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::anomalyDetector(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -132,10 +104,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'k' => 60, @@ -147,10 +116,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -161,15 +127,17 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/AnomalyDetectors/LodaTest.php b/tests/AnomalyDetectors/LodaTest.php index 56e61da2f..41d4081ea 100644 --- a/tests/AnomalyDetectors/LodaTest.php +++ b/tests/AnomalyDetectors/LodaTest.php @@ -1,16 +1,15 @@ generator = new Agglomerate([ - 0 => new Blob([0.0, 0.0], 2.0), - 1 => new Circle(0.0, 0.0, 8.0, 1.0), - ], [0.9, 0.1]); - - $this->estimator = new Loda(0.1, 100, null); + $this->generator = new Agglomerate( + generators: [ + new Blob( + center: [0.0, 0.0], + stdDev: 2.0 + ), + new Circle( + x: 0.0, + y: 0.0, + scale: 8.0, + noise: 1.0 + ), + ], + weights: [0.9, 0.1] + ); + + $this->estimator = new Loda( + contamination: 0.1, + estimators: 100, + bins: null + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void + public function testBadContamination() : void { - $this->assertInstanceOf(Loda::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Scoring::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); + $this->expectException(InvalidArgumentException::class); + + new Loda(contamination: -1); } - /** - * @test - */ - public function badNumEstimators() : void + public function testBadEstimators() : void { $this->expectException(InvalidArgumentException::class); - new Loda(-100); + new Loda(contamination: 0.2, estimators: 0); } - /** - * @test - */ - public function badNumBins() : void + public function testBadBins() : void { $this->expectException(InvalidArgumentException::class); - new Loda(100, 0); + new Loda(contamination: 0.2, estimators: 2, bins: 1); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::anomalyDetector(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -143,10 +117,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'estimators' => 100, @@ -157,10 +128,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -175,24 +143,23 @@ public function trainPartialPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); $this->estimator->train(Unlabeled::quick([['bad']])); } - /** - * @test - */ public function predictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/AnomalyDetectors/OneClassSVMTest.php b/tests/AnomalyDetectors/OneClassSVMTest.php index 41110954c..f99fcf782 100644 --- a/tests/AnomalyDetectors/OneClassSVMTest.php +++ b/tests/AnomalyDetectors/OneClassSVMTest.php @@ -1,10 +1,13 @@ generator = new Agglomerate([ - 0 => new Blob([0.0, 0.0], 2.0), - 1 => new Circle(0.0, 0.0, 8.0, 1.0), - ], [0.9, 0.1]); - - $this->estimator = new OneClassSVM(0.01, new Polynomial(4, 1e-3), true, 1e-4); + $this->generator = new Agglomerate( + generators: [ + new Blob( + center: [0.0, 0.0], + stdDev: 2.0 + ), + new Circle( + x: 0.0, + y: 0.0, + scale: 8.0, + noise: 1.0 + ), + ], + weights: [0.9, 0.1] + ); + + $this->estimator = new OneClassSVM( + nu: 0.01, + kernel: new Polynomial(degree: 4, gamma: 1e-3), + shrinking: true, + tolerance: 1e-4 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(OneClassSVM::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::anomalyDetector(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -119,10 +100,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'nu' => 0.01, @@ -135,10 +113,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -149,25 +124,24 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); $this->estimator->train(Unlabeled::quick([['bad']])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/AnomalyDetectors/RobustZScoreTest.php b/tests/AnomalyDetectors/RobustZScoreTest.php index b20ca1731..cfc614b37 100644 --- a/tests/AnomalyDetectors/RobustZScoreTest.php +++ b/tests/AnomalyDetectors/RobustZScoreTest.php @@ -1,14 +1,14 @@ generator = new Agglomerate([ - 0 => new Blob([0.0, 0.0], 2.0), - 1 => new Circle(0.0, 0.0, 8.0, 1.0), - ], [0.9, 0.1]); - - $this->estimator = new RobustZScore(2.0, 0.5, 1e-9); + $this->generator = new Agglomerate( + generators: [ + new Blob( + center: [0.0, 0.0], + stdDev: 2.0 + ), + new Circle( + x: 0.0, + y: 0.0, + scale: 8.0, + noise: 1.0 + ) + ], + weights: [0.9, 0.1] + ); + + $this->estimator = new RobustZScore( + threshold: 2.0, + beta: 0.5, + smoothing: 1e-9 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void + public function testBadThreshold() : void { - $this->assertInstanceOf(RobustZScore::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Scoring::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); + $this->expectException(InvalidArgumentException::class); + + new RobustZScore(threshold: -3.5); } - /** - * @test - */ - public function badThreshold() : void + public function testBadBeta() : void { $this->expectException(InvalidArgumentException::class); - new RobustZScore(-3.5); + new RobustZScore(threshold: 3.5, beta: 1.5); } - /** - * @test - */ - public function badAlpha() : void + public function testBadSmoothing() : void { $this->expectException(InvalidArgumentException::class); - new RobustZScore(3.5, 1.5); + new RobustZScore(threshold: 3.5, beta: 0.5, smoothing: -1); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::anomalyDetector(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -141,10 +117,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'threshold' => 2.0, @@ -155,10 +128,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -171,35 +141,34 @@ public function trainPredict() : void $this->assertIsArray($medians); $this->assertCount(2, $medians); - $this->assertContainsOnly('float', $medians); + $this->assertContainsOnlyFloat($medians); $mads = $this->estimator->mads(); $this->assertIsArray($mads); $this->assertCount(2, $mads); - $this->assertContainsOnly('float', $mads); + $this->assertContainsOnlyFloat($mads); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); $this->estimator->train(Unlabeled::quick([['bad']])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Backends/AmpTest.php b/tests/Backends/AmpTest.php index d2bbda9b5..536f3485b 100644 --- a/tests/Backends/AmpTest.php +++ b/tests/Backends/AmpTest.php @@ -1,22 +1,20 @@ backend = new Amp(4); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Amp::class, $this->backend); - $this->assertInstanceOf(Backend::class, $this->backend); - } - - /** - * @test - */ - public function workers() : void + public function testWorkers() : void { $this->assertEquals(4, $this->backend->workers()); } - /** - * @test - */ - public function enqueueProcess() : void + public function testEnqueueProcess() : void { for ($i = 0; $i < 10; ++$i) { - $this->backend->enqueue(new Task([self::class, 'foo'], [$i])); + $this->backend->enqueue( + task: new Task(fn: [self::class, 'foo'], args: [$i]) + ); } $results = $this->backend->process(); diff --git a/tests/Backends/SerialTest.php b/tests/Backends/SerialTest.php index 56e3b2cbd..8605516e4 100644 --- a/tests/Backends/SerialTest.php +++ b/tests/Backends/SerialTest.php @@ -1,22 +1,20 @@ backend = new Serial(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Serial::class, $this->backend); - $this->assertInstanceOf(Backend::class, $this->backend); - } - - /** - * @test - */ - public function enqueueProcess() : void + public function testEnqueueProcess() : void { for ($i = 0; $i < 10; ++$i) { - $this->backend->enqueue(new Task([self::class, 'foo'], [$i])); + $this->backend->enqueue( + task: new Task( + fn: [self::class, 'foo'], + args: [$i] + ) + ); } $results = $this->backend->process(); diff --git a/tests/Backends/SwooleTest.php b/tests/Backends/SwooleTest.php index ab6ac6cb1..d23e2339d 100644 --- a/tests/Backends/SwooleTest.php +++ b/tests/Backends/SwooleTest.php @@ -1,73 +1,52 @@ passes()) { - $this->markTestSkipped( - 'Swoole/OpenSwoole extension is not available.' - ); + $this->markTestSkipped('Swoole extension is not available.'); } $this->backend = new SwooleBackend(); } - /** - * @after - */ protected function tearDown() : void { Event::wait(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SwooleBackend::class, $this->backend); - $this->assertInstanceOf(Backend::class, $this->backend); - } - - /** - * @test - */ - public function enqueueProcess() : void + public function testEnqueueProcess() : void { for ($i = 0; $i < 10; ++$i) { - $this->backend->enqueue(new Task([self::class, 'foo'], [$i])); + $this->backend->enqueue( + task: new Task( + fn: [self::class, 'foo'], + args: [$i] + ) + ); } $results = $this->backend->process(); diff --git a/tests/Backends/Tasks/PredictTest.php b/tests/Backends/Tasks/PredictTest.php index cb10387c4..568c04008 100644 --- a/tests/Backends/Tasks/PredictTest.php +++ b/tests/Backends/Tasks/PredictTest.php @@ -1,30 +1,38 @@ new Blob([69.2, 195.7, 40.0], [1.0, 3.0, 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.0], + stdDev: [1.0, 3.0, 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $training = $generator->generate(50); @@ -32,7 +40,7 @@ public function compute() : void $testing = $generator->generate(15); - $task = new Predict($estimator, $testing); + $task = new Predict(estimator: $estimator, dataset: $testing); $result = $task->compute(); diff --git a/tests/Backends/Tasks/ProbaTest.php b/tests/Backends/Tasks/ProbaTest.php index 9f532dc45..cdac715ba 100644 --- a/tests/Backends/Tasks/ProbaTest.php +++ b/tests/Backends/Tasks/ProbaTest.php @@ -1,30 +1,38 @@ new Blob([69.2, 195.7, 40.0], [1.0, 3.0, 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.0], + stdDev: [1.0, 3.0, 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $training = $generator->generate(50); @@ -32,7 +40,7 @@ public function compute() : void $testing = $generator->generate(15); - $task = new Proba($estimator, $testing); + $task = new Proba(estimator: $estimator, dataset: $testing); $result = $task->compute(); diff --git a/tests/Backends/Tasks/TrainAndValidateTest.php b/tests/Backends/Tasks/TrainAndValidateTest.php index c96a7635c..dc0fc7742 100644 --- a/tests/Backends/Tasks/TrainAndValidateTest.php +++ b/tests/Backends/Tasks/TrainAndValidateTest.php @@ -1,7 +1,11 @@ new Blob([69.2, 195.7, 40.0], [1.0, 3.0, 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.0], + stdDev: [1.0, 3.0, 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $metric = new Accuracy(); $training = $generator->generate(50); $testing = $generator->generate(15); - $task = new TrainAndValidate($estimator, $training, $testing, $metric); + $task = new TrainAndValidate( + estimator: $estimator, + training: $training, + testing: $testing, + metric: $metric + ); $result = $task->compute(); diff --git a/tests/Backends/Tasks/TrainLearnerTest.php b/tests/Backends/Tasks/TrainLearnerTest.php index f82a0f848..3a1492b78 100644 --- a/tests/Backends/Tasks/TrainLearnerTest.php +++ b/tests/Backends/Tasks/TrainLearnerTest.php @@ -1,34 +1,42 @@ new Blob([69.2, 195.7, 40.0], [1.0, 3.0, 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.0], + stdDev: [1.0, 3.0, 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $dataset = $generator->generate(50); - $task = new TrainLearner($estimator, $dataset); + $task = new TrainLearner(estimator: $estimator, dataset: $dataset); $result = $task->compute(); diff --git a/tests/BootstrapAggregatorTest.php b/tests/Base/BootstrapAggregatorTest.php similarity index 55% rename from tests/BootstrapAggregatorTest.php rename to tests/Base/BootstrapAggregatorTest.php index 7d14108a8..af4219227 100644 --- a/tests/BootstrapAggregatorTest.php +++ b/tests/Base/BootstrapAggregatorTest.php @@ -1,11 +1,13 @@ generator = new SwissRoll(4.0, -7.0, 0.0, 1.0, 0.3); + $this->generator = new SwissRoll(x: 4.0, y: -7.0, z: 0.0, scale: 1.0, depth: 0.3); - $this->estimator = new BootstrapAggregator(new RegressionTree(10), 30, 0.5); + $this->estimator = new BootstrapAggregator( + new RegressionTree(maxHeight: 10), + estimators: 30, + ratio: 0.5 + ); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(BootstrapAggregator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -99,13 +77,10 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ - 'base' => new RegressionTree(10), + 'base' => new RegressionTree(maxHeight: 10), 'estimators' => 30, 'ratio' => 0.5, ]; @@ -114,10 +89,9 @@ public function params() : void } /** - * @dataProvider provideBackends - * @test * @param Backend $backend */ + #[DataProvider('provideBackends')] public function trainPredict(Backend $backend) : void { $this->estimator->setBackend($backend); @@ -131,15 +105,17 @@ public function trainPredict(Backend $backend) : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/CommitteeMachineTest.php b/tests/Base/CommitteeMachineTest.php similarity index 50% rename from tests/CommitteeMachineTest.php rename to tests/Base/CommitteeMachineTest.php index 471505dd8..105f77bfa 100644 --- a/tests/CommitteeMachineTest.php +++ b/tests/Base/CommitteeMachineTest.php @@ -1,12 +1,13 @@ generator = new Agglomerate([ - 'inner' => new Circle(0.0, 0.0, 1.0, 0.01), - 'middle' => new Circle(0.0, 0.0, 5.0, 0.05), - 'outer' => new Circle(0.0, 0.0, 10.0, 0.15), - ], [3, 3, 4]); - - $this->estimator = new CommitteeMachine([ - new ClassificationTree(10, 3, 2), - new KNearestNeighbors(3), - new GaussianNB(), - ], [3, 4, 5]); + $this->generator = new Agglomerate( + generators: [ + 'inner' => new Circle(x: 0.0, y: 0.0, scale: 1.0, noise: 0.01), + 'middle' => new Circle(x: 0.0, y: 0.0, scale: 5.0, noise: 0.05), + 'outer' => new Circle(x: 0.0, y: 0.0, scale: 10.0, noise: 0.15), + ], + weights: [3, 3, 4] + ); + + $this->estimator = new CommitteeMachine( + experts: [ + new ClassificationTree(maxHeight: 10, maxLeafSize: 3, minPurityIncrease: 2), + new KNearestNeighbors(k: 3), + new GaussianNB(), + ], + influences: [3, 4, 5] + ); $this->metric = new Accuracy(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(CommitteeMachine::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Parallel::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -112,15 +87,12 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'experts' => [ - new ClassificationTree(10, 3, 2), - new KNearestNeighbors(3), + new ClassificationTree(maxHeight: 10, maxLeafSize: 3, minPurityIncrease: 2), + new KNearestNeighbors(k: 3), new GaussianNB(), ], 'influences' => [ @@ -134,11 +106,10 @@ public function params() : void } /** - * @dataProvider provideBackends - * @test * @param Backend $backend */ - public function trainPredict(Backend $backend) : void + #[DataProvider('provideBackends')] + public function testTrainPredict(Backend $backend) : void { $this->estimator->setBackend($backend); @@ -149,27 +120,27 @@ public function trainPredict(Backend $backend) : void $this->assertTrue($this->estimator->trained()); + /** @var list $predictions */ $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Unlabeled::quick([['bad']])); + $this->estimator->train(Unlabeled::quick(samples: [['bad']])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/DataTypeTest.php b/tests/Base/DataTypeTest.php similarity index 64% rename from tests/DataTypeTest.php rename to tests/Base/DataTypeTest.php index 88c397a79..3b1f118de 100644 --- a/tests/DataTypeTest.php +++ b/tests/Base/DataTypeTest.php @@ -1,33 +1,22 @@ assertEquals($expected, DataType::detect($value)); - } - - /** - * @return \Generator - */ - public function determineProvider() : Generator + public static function determineProvider() : Generator { yield ['string', DataType::categorical()]; @@ -46,11 +35,29 @@ public function determineProvider() : Generator yield [(object) [], DataType::other()]; } + public static function codeProvider() : Generator + { + yield [DataType::categorical(), DataType::CATEGORICAL]; + + yield [DataType::continuous(), DataType::CONTINUOUS]; + + yield [DataType::image(), DataType::IMAGE]; + + yield [DataType::other(), DataType::OTHER]; + } + /** - * @test - * @requires extension gd + * @param mixed $value + * @param DataType $expected */ - public function determineImage() : void + #[DataProvider('determineProvider')] + public function testDetermine(mixed $value, DataType $expected) : void + { + $this->assertEquals($expected, DataType::detect($value)); + } + + #[RequiresPhpExtension('gd')] + public function testDetermineImage() : void { $value = imagecreatefrompng('tests/test.png'); @@ -58,66 +65,35 @@ public function determineImage() : void } /** - * @test - * @dataProvider codeProvider - * * @param DataType $type * @param int $expected */ - public function code(DataType $type, int $expected) : void + #[DataProvider('codeProvider')] + public function testCode(DataType $type, int $expected) : void { $this->assertSame($expected, $type->code()); } - /** - * @return \Generator - */ - public function codeProvider() : Generator - { - yield [DataType::categorical(), DataType::CATEGORICAL]; - - yield [DataType::continuous(), DataType::CONTINUOUS]; - - yield [DataType::image(), DataType::IMAGE]; - - yield [DataType::other(), DataType::OTHER]; - } - - /** - * @test - */ - public function isCategorical() : void + public function testIsCategorical() : void { $this->assertFalse(DataType::continuous()->isCategorical()); } - /** - * @test - */ - public function isContinuous() : void + public function testIsContinuous() : void { $this->assertTrue(DataType::continuous()->isContinuous()); } - /** - * @test - */ - public function isImage() : void + public function testIsImage() : void { $this->assertFalse(DataType::continuous()->isImage()); } - /** - * @test - */ - public function isOther() : void + public function testIsOther() : void { $this->assertFalse(DataType::continuous()->isOther()); } - /** - * @test - */ public function testToString() : void { $this->assertEquals('continuous', (string) DataType::continuous()); diff --git a/tests/Base/DeferredTest.php b/tests/Base/DeferredTest.php new file mode 100644 index 000000000..3efdc76c9 --- /dev/null +++ b/tests/Base/DeferredTest.php @@ -0,0 +1,32 @@ +deferred = new Deferred( + fn: function ($a, $b) { + return $a + $b; + }, + args: [1, 2] + ); + } + + public function testCompute() : void + { + $this->assertEquals(3, $this->deferred->compute()); + } +} diff --git a/tests/EncodingTest.php b/tests/Base/EncodingTest.php similarity index 58% rename from tests/EncodingTest.php rename to tests/Base/EncodingTest.php index 98dc69321..bf9ec9e7a 100644 --- a/tests/EncodingTest.php +++ b/tests/Base/EncodingTest.php @@ -1,57 +1,39 @@ 'pancakes', 'lunch' => 'croque monsieur', 'dinner' => 'new york strip steak', ]; - /** - * @var Encoding - */ - protected $encoding; + protected Encoding $encoding; - /** - * @before - */ protected function setUp() : void { $this->encoding = new Encoding(json_encode(self::TEST_DATA) ?: ''); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Encoding::class, $this->encoding); - } - - /** - * @test - */ - public function data() : void + public function testData() : void { $expected = '{"breakfast":"pancakes","lunch":"croque monsieur","dinner":"new york strip steak"}'; $this->assertEquals($expected, $this->encoding->data()); } - /** - * @test - */ - public function bytes() : void + public function tstBytes() : void { $this->assertSame(82, $this->encoding->bytes()); } diff --git a/tests/EstimatorTypeTest.php b/tests/Base/EstimatorTypeTest.php similarity index 58% rename from tests/EstimatorTypeTest.php rename to tests/Base/EstimatorTypeTest.php index 86ae793a5..34704e1e8 100644 --- a/tests/EstimatorTypeTest.php +++ b/tests/Base/EstimatorTypeTest.php @@ -1,72 +1,50 @@ type = new EstimatorType(EstimatorType::CLUSTERER); } - /** - * @test - */ - public function code() : void + public function testCode() : void { $this->assertSame(EstimatorType::CLUSTERER, $this->type->code()); } - /** - * @test - */ - public function isClassifier() : void + public function testIsClassifier() : void { $this->assertFalse($this->type->isClassifier()); } - /** - * @test - */ - public function isRegressor() : void + public function testIsRegressor() : void { $this->assertFalse($this->type->isRegressor()); } - /** - * @test - */ - public function isClusterer() : void + public function testIsClusterer() : void { $this->assertTrue($this->type->isClusterer()); } - /** - * @test - */ - public function isAnomalyDetector() : void + public function testIsAnomalyDetector() : void { $this->assertFalse($this->type->isAnomalyDetector()); } - /** - * @test - */ public function testToString() : void { $this->assertEquals('clusterer', (string) $this->type); diff --git a/tests/FunctionsTest.php b/tests/Base/FunctionsTest.php similarity index 68% rename from tests/FunctionsTest.php rename to tests/Base/FunctionsTest.php index 265da86d3..6ec257d23 100644 --- a/tests/FunctionsTest.php +++ b/tests/Base/FunctionsTest.php @@ -1,7 +1,12 @@ 0.8, 'no' => 0.2, 'maybe' => 0.0]); + protected const int RANDOM_SEED = 0; - $this->assertEquals('maybe', $value); - } - - /** - * @test - * @dataProvider argmaxProvider - * - * @param float[] $input - * @param string|int $expected - */ - public function argmax(array $input, $expected) : void - { - $this->assertEquals($expected, argmax($input)); - } - - /** - * @return \Generator - */ - public function argmaxProvider() : Generator + public static function argmaxProvider() : Generator { yield [ ['yes' => 0.8, 'no' => 0.2, 'maybe' => 0.0], @@ -86,42 +61,7 @@ public function argmaxProvider() : Generator ]; } - /** - * @test - */ - public function argmaxUndefined() : void - { - $this->expectException(RuntimeException::class); - - argmax([NAN, NAN, NAN]); - } - - /** - * @test - */ - public function logsumexp() : void - { - $value = logsumexp([0.5, 0.4, 0.9, 1.0, 0.2, 0.9, 0.1, 0.5, 0.7]); - - $this->assertEquals(2.8194175400311074, $value); - } - - /** - * @test - * @dataProvider sigmoidProvider - * - * @param float $value - * @param float $expected - */ - public function sigmoid(float $value, float $expected) : void - { - $this->assertEquals($expected, sigmoid($value)); - } - - /** - * @return \Generator - */ - public function sigmoidProvider() : Generator + public static function sigmoidProvider() : Generator { yield [2.0, 0.8807970779778823]; @@ -132,23 +72,7 @@ public function sigmoidProvider() : Generator yield [10.0, 0.9999546021312976]; } - /** - * @test - * @dataProvider combProvider - * - * @param int $n - * @param int $k - * @param int $expected - */ - public function comb(int $n, int $k, int $expected) : void - { - $this->assertEquals($expected, comb($n, $k)); - } - - /** - * @return \Generator - */ - public function combProvider() : Generator + public static function combProvider() : Generator { yield [1, 1, 1]; @@ -159,24 +83,7 @@ public function combProvider() : Generator yield [10, 6, 210]; } - /** - * @test - * @dataProvider linspaceProvider - * - * @param float $min - * @param float $max - * @param int $n - * @param list $expected - */ - public function linspace(float $min, float $max, int $n, array $expected) : void - { - $this->assertEquals($expected, linspace($min, $max, $n)); - } - - /** - * @return \Generator - */ - public function linspaceProvider() : Generator + public static function linspaceProvider() : Generator { yield [0.0, 1.0, 5, [ 0.0, 0.25, 0.5, 0.75, 1.0, @@ -188,22 +95,7 @@ public function linspaceProvider() : Generator ]]; } - /** - * @test - * @dataProvider arrayTransposeProvider - * - * @param list> $table - * @param list> $expected - */ - public function arrayTranspose(array $table, array $expected) : void - { - $this->assertEquals($expected, array_transpose($table)); - } - - /** - * @return \Generator - */ - public function arrayTransposeProvider() : Generator + public static function arrayTransposeProvider() : Generator { yield [ [ @@ -235,20 +127,120 @@ public function arrayTransposeProvider() : Generator ]; } + public static function iteratorContainsNanProvider() : Generator + { + yield [ + [0.0, NAN, -5], + true, + ]; + + yield [ + [0.0, 0.0, 0.0], + false, + ]; + + yield [ + [1.0, INF, NAN], + true, + ]; + + yield [ + [ + [1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], + [7.0, 8.0, NAN], + ], + true, + ]; + + yield [ + ['NaN', 'NAN'], + false, + ]; + } + + public function testArgmin() : void + { + $value = argmin(['yes' => 0.8, 'no' => 0.2, 'maybe' => 0.0]); + + $this->assertEquals('maybe', $value); + } + /** - * @test + * @param float[] $input + * @param string|int $expected */ - public function iteratorFirst() : void + #[DataProvider('argmaxProvider')] + public function testArgmax(array $input, mixed $expected) : void { - $element = iterator_first(['first', 'last']); + $this->assertEquals($expected, argmax($input)); + } - $this->assertEquals('first', $element); + public function testArgmaxUndefined() : void + { + $this->expectException(RuntimeException::class); + + argmax([NAN, NAN, NAN]); + } + + public function testLogsumexp() : void + { + $value = logsumexp([0.5, 0.4, 0.9, 1.0, 0.2, 0.9, 0.1, 0.5, 0.7]); + + $this->assertEquals(2.8194175400311074, $value); + } + + /** + * @param float $value + * @param float $expected + */ + #[DataProvider('sigmoidProvider')] + public function sigmoid(float $value, float $expected) : void + { + $this->assertEquals($expected, sigmoid($value)); } /** - * @test + * @param int $n + * @param int $k + * @param int $expected */ - public function iteratorMap() : void + #[DataProvider('combProvider')] + public function comb(int $n, int $k, int $expected) : void + { + $this->assertEquals($expected, comb($n, $k)); + } + + /** + * @param float $min + * @param float $max + * @param int $n + * @param list $expected + */ + #[DataProvider('linspaceProvider')] + public function linspace(float $min, float $max, int $n, array $expected) : void + { + $this->assertEquals($expected, linspace($min, $max, $n)); + } + + /** + * @param list> $table + * @param list> $expected + */ + #[DataProvider('arrayTransposeProvider')] + public function arrayTranspose(array $table, array $expected) : void + { + $this->assertEquals($expected, array_transpose($table)); + } + + public function testIteratorFirst() : void + { + $element = iterator_first(['first', 'last']); + + $this->assertEquals('first', $element); + } + + public function testIteratorMap() : void { $doubleIt = function ($value) { return $value * 2; @@ -261,10 +253,7 @@ public function iteratorMap() : void $this->assertEquals($expected, iterator_to_array($values)); } - /** - * @test - */ - public function iteratorFilter() : void + public function testIteratorFilter() : void { $isPositive = function ($value) { return $value >= 0; @@ -278,61 +267,12 @@ public function iteratorFilter() : void } /** - * @test - * @dataProvider iteratorContainsNanProvider - * - * @param mixed[] $values + * @param array|bool> $values * @param bool $expected */ + #[DataProvider('iteratorContainsNanProvider')] public function iteratorContainsNan(array $values, bool $expected) : void { $this->assertEquals($expected, iterator_contains_nan($values)); } - - /** - * @return \Generator - */ - public function iteratorContainsNanProvider() : Generator - { - yield [ - [0.0, NAN, -5], - true, - ]; - - yield [ - [0.0, 0.0, 0.0], - false, - ]; - - yield [ - [1.0, INF, NAN], - true, - ]; - - yield [ - [ - [1.0, 2.0, 3.0], - [4.0, 5.0, 6.0], - [7.0, 8.0, NAN], - ], - true, - ]; - - yield [ - ['NaN', 'NAN'], - false, - ]; - } - - // Until PHP Unit bug is fixed, this needs to be commented out. - // - // /** - // * @test - // */ - // public function warnDeprecated() : void - // { - // $this->expectDeprecation(); - - // warn_deprecated('full control'); - // } } diff --git a/tests/GridSearchTest.php b/tests/Base/GridSearchTest.php similarity index 54% rename from tests/GridSearchTest.php rename to tests/Base/GridSearchTest.php index 9c69f479d..22d2a05be 100644 --- a/tests/GridSearchTest.php +++ b/tests/Base/GridSearchTest.php @@ -1,13 +1,14 @@ generator = new Agglomerate([ - 'inner' => new Circle(0.0, 0.0, 1.0, 0.5), - 'middle' => new Circle(0.0, 0.0, 5.0, 1.0), - 'outer' => new Circle(0.0, 0.0, 10.0, 2.0), - ]); - - $this->estimator = new GridSearch(KNearestNeighbors::class, [ - [1, 5, 10], [true], [new Euclidean(), new Manhattan()], - ], new FBeta(), new HoldOut(0.2)); + $this->generator = new Agglomerate( + generators: [ + 'inner' => new Circle(x: 0.0, y: 0.0, scale: 1.0, noise: 0.5), + 'middle' => new Circle(x: 0.0, y: 0.0, scale: 5.0, noise: 1.0), + 'outer' => new Circle(x: 0.0, y: 0.0, scale: 10.0, noise: 2.0), + ] + ); + + $this->estimator = new GridSearch( + class: KNearestNeighbors::class, + params: [ + [1, 5, 10], + [true], + [ + new Euclidean(), + new Manhattan() + ], + ], + metric: new FBeta(), + validator: new HoldOut(0.2) + ); $this->metric = new Accuracy(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GridSearch::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $this->assertEquals(DataType::all(), $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'class' => KNearestNeighbors::class, @@ -124,11 +102,10 @@ public function params() : void } /** - * @dataProvider provideBackends - * @test * @param Backend $backend */ - public function trainPredictBest(Backend $backend) : void + #[DataProvider('provideBackends')] + public function testTrainPredictBest(Backend $backend) : void { $this->estimator->setLogger(new BlackHole()); $this->estimator->setBackend($backend); @@ -140,9 +117,16 @@ public function trainPredictBest(Backend $backend) : void $this->assertTrue($this->estimator->trained()); + /** @var list $predictions */ $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); diff --git a/tests/Base/PersistentModelTest.php b/tests/Base/PersistentModelTest.php new file mode 100644 index 000000000..3dad28c72 --- /dev/null +++ b/tests/Base/PersistentModelTest.php @@ -0,0 +1,52 @@ +estimator = new PersistentModel( + base: new GaussianNB(), + persister: new Filesystem('test.model'), + serializer: new RBX() + ); + } + + public function testType() : void + { + $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); + } + + public function testCompatibility() : void + { + $this->assertEquals([DataType::continuous()], $this->estimator->compatibility()); + } + + public function testParams() : void + { + $expected = [ + 'base' => new GaussianNB(), + 'persister' => new Filesystem('test.model'), + 'serializer' => new RBX(), + ]; + + $this->assertEquals($expected, $this->estimator->params()); + } +} diff --git a/tests/PipelineTest.php b/tests/Base/PipelineTest.php similarity index 50% rename from tests/PipelineTest.php rename to tests/Base/PipelineTest.php index a8fa5ebc3..21042adf2 100644 --- a/tests/PipelineTest.php +++ b/tests/Base/PipelineTest.php @@ -1,16 +1,15 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); - $this->estimator = new Pipeline([ - new PolynomialExpander(2), - new ZScaleStandardizer(), - ], new SoftmaxClassifier(), true); + $this->estimator = new Pipeline( + transformers: [ + new PolynomialExpander(2), + new ZScaleStandardizer(), + ], + base: new SoftmaxClassifier(), + elastic: true + ); $this->metric = new Accuracy(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void - { - $this->assertFalse($this->estimator->trained()); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Pipeline::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Scoring::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -108,10 +85,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'transformers' => [ @@ -125,10 +99,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -141,20 +112,29 @@ public function trainPartialPredict() : void $this->assertTrue($this->estimator->trained()); + /** @var list $predictions */ $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); $this->estimator->predict(Unlabeled::quick()); } + + protected function testAssertPreConditions() : void + { + $this->assertFalse($this->estimator->trained()); + } } diff --git a/tests/ReportTest.php b/tests/Base/ReportTest.php similarity index 54% rename from tests/ReportTest.php rename to tests/Base/ReportTest.php index bb67d79a2..e6db27697 100644 --- a/tests/ReportTest.php +++ b/tests/Base/ReportTest.php @@ -1,29 +1,21 @@ results = new Report([ @@ -33,22 +25,7 @@ protected function setUp() : void ]); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Report::class, $this->results); - $this->assertInstanceOf(ArrayAccess::class, $this->results); - $this->assertInstanceOf(JsonSerializable::class, $this->results); - $this->assertInstanceOf(IteratorAggregate::class, $this->results); - $this->assertInstanceOf(Stringable::class, $this->results); - } - - /** - * @test - */ - public function toArray() : void + public function testToArray() : void { $expected = [ 'accuracy' => 0.9, @@ -59,10 +36,7 @@ public function toArray() : void $this->assertEquals($expected, $this->results->toArray()); } - /** - * @test - */ - public function toJSON() : void + public function testToJSON() : void { $expected = '{"accuracy":0.9,"f1_score":0.75,"cardinality":5}'; @@ -72,10 +46,7 @@ public function toJSON() : void $this->assertEquals($expected, (string) $encoding); } - /** - * @test - */ - public function arrayAccess() : void + public function testArrayAccess() : void { $this->assertEquals(0.9, $this->results['accuracy']); $this->assertEquals(0.75, $this->results['f1_score']); diff --git a/tests/Classifiers/AdaBoostTest.php b/tests/Classifiers/AdaBoostTest.php index 7a038fa7d..1a9dd2ad9 100644 --- a/tests/Classifiers/AdaBoostTest.php +++ b/tests/Classifiers/AdaBoostTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new AdaBoost(new ClassificationTree(1), 1.0, 0.5, 100, 1e-4, 5); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new AdaBoost( + base: new ClassificationTree(1), + rate: 1.0, + ratio: 0.5, + epochs: 100, + minChange: 1e-4, + window: 5 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(AdaBoost::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badLearningRate() : void + public function testBadLearningRate() : void { $this->expectException(InvalidArgumentException::class); - new AdaBoost(null, -1e-3); + new AdaBoost(base: null, rate: -1e-3); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -136,10 +110,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'base' => new ClassificationTree(1), @@ -153,10 +124,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -170,19 +138,19 @@ public function trainPredict() : void $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/ClassificationTreeTest.php b/tests/Classifiers/ClassificationTreeTest.php index b0507d869..35ba6e5d4 100644 --- a/tests/Classifiers/ClassificationTreeTest.php +++ b/tests/Classifiers/ClassificationTreeTest.php @@ -1,18 +1,15 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new ClassificationTree(10, 32, 1e-7, 3); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new ClassificationTree( + maxHeight: 10, + maxLeafSize: 32, + minPurityIncrease: 1e-7, + maxFeatures: 3 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ClassificationTree::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badMaxDepth() : void + public function testBadMaxHeight() : void { $this->expectException(InvalidArgumentException::class); - new ClassificationTree(0); + new ClassificationTree(maxHeight: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -138,10 +108,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'max height' => 10, @@ -154,10 +121,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredictImportancesExportGraphvizContinuous() : void + public function testTrainPredictImportancesExportGraphvizContinuous() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -170,7 +134,7 @@ public function trainPredictImportancesExportGraphvizContinuous() : void $this->assertIsArray($importances); $this->assertCount(3, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $dot = $this->estimator->exportGraphviz([ 'r', 'g', 'b', @@ -179,22 +143,23 @@ public function trainPredictImportancesExportGraphvizContinuous() : void // Graphviz::dotToImage($dot)->saveTo(new Filesystem('test.png')); $this->assertInstanceOf(Encoding::class, $dot); - $this->assertStringStartsWith('digraph Tree {', $dot); + $this->assertStringStartsWith('digraph Tree {', (string) $dot); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainPredictCategoricalExportGraphviz() : void + public function testTrainPredictCategoricalExportGraphviz() : void { - $training = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE) - ->apply(new IntervalDiscretizer(3)); + $training = $this->generator + ->generate(self::TRAIN_SIZE + self::TEST_SIZE) + ->apply(new IntervalDiscretizer(bins: 3)); $testing = $training->randomize()->take(self::TEST_SIZE); @@ -209,19 +174,19 @@ public function trainPredictCategoricalExportGraphviz() : void // Graphviz::dotToImage($dot)->saveTo(new Filesystem('test.png')); $this->assertInstanceOf(Encoding::class, $dot); - $this->assertStringStartsWith('digraph Tree {', $dot); + $this->assertStringStartsWith('digraph Tree {', (string) $dot); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/ExtraTreeClassifierTest.php b/tests/Classifiers/ExtraTreeClassifierTest.php index ed7b86473..9db2f1c5f 100644 --- a/tests/Classifiers/ExtraTreeClassifierTest.php +++ b/tests/Classifiers/ExtraTreeClassifierTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new ExtraTreeClassifier(30, 16, 1e-7, 3); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new ExtraTreeClassifier( + maxHeight: 30, + maxLeafSize: 16, + minPurityIncrease: 1e-7, + maxFeatures: 3 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ExtraTreeClassifier::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badMaxDepth() : void + public function testBadMaxHeight() : void { $this->expectException(InvalidArgumentException::class); - new ExtraTreeClassifier(0); + new ExtraTreeClassifier(maxHeight: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -135,10 +107,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'max height' => 30, @@ -150,10 +119,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredictImportancesContinuous() : void + public function testTrainPredictImportancesContinuous() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -166,21 +132,22 @@ public function trainPredictImportancesContinuous() : void $this->assertIsArray($importances); $this->assertCount(3, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainPredictCategorical() : void + public function testTrainPredictCategorical() : void { - $training = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE) + $training = $this->generator + ->generate(self::TRAIN_SIZE + self::TEST_SIZE) ->apply(new IntervalDiscretizer(3)); $testing = $training->randomize()->take(self::TEST_SIZE); @@ -191,15 +158,15 @@ public function trainPredictCategorical() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/GaussianNBTest.php b/tests/Classifiers/GaussianNBTest.php index ad93acc10..1f40a81d2 100644 --- a/tests/Classifiers/GaussianNBTest.php +++ b/tests/Classifiers/GaussianNBTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new GaussianNB(null, 1e-8); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new GaussianNB(priors: null, smoothing: 1e-8); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GaussianNB::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -124,10 +94,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'priors' => null, @@ -137,10 +104,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -157,41 +121,38 @@ public function trainPartialPredict() : void $this->assertIsArray($priors); $this->assertCount(3, $priors); - $this->assertContainsOnly('float', $priors); + $this->assertContainsOnlyFloat($priors); $means = $this->estimator->means(); $this->assertIsArray($means); $this->assertCount(3, $means); - $this->assertContainsOnly('array', $means); + $this->assertContainsOnlyArray($means); $variances = $this->estimator->variances(); $this->assertIsArray($variances); $this->assertCount(3, $variances); - $this->assertContainsOnly('array', $variances); + $this->assertContainsOnlyArray($variances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], ['green'])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/KDNeighborsTest.php b/tests/Classifiers/KDNeighborsTest.php index 5464038f4..69c7492a7 100644 --- a/tests/Classifiers/KDNeighborsTest.php +++ b/tests/Classifiers/KDNeighborsTest.php @@ -1,12 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new KDNeighbors(5, true, new KDTree()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new KDNeighbors( + k: 5, + weighted: true, + tree: new KDTree() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KDNeighbors::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badK() : void + public function testBadK() : void { $this->expectException(InvalidArgumentException::class); new KDNeighbors(0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -133,10 +106,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'k' => 5, @@ -147,10 +117,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -161,25 +128,22 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], ['green'])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/KNearestNeighborsTest.php b/tests/Classifiers/KNearestNeighborsTest.php index c002f3b06..b9f87c508 100644 --- a/tests/Classifiers/KNearestNeighborsTest.php +++ b/tests/Classifiers/KNearestNeighborsTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new KNearestNeighbors(3, true, new Euclidean()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new KNearestNeighbors( + k: 3, + weighted: true, + kernel: new Euclidean() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KNearestNeighbors::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badK() : void + public function testBadK() : void { $this->expectException(InvalidArgumentException::class); - new KNearestNeighbors(0); + new KNearestNeighbors(k: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -135,10 +106,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'k' => 3, @@ -149,10 +117,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -167,25 +132,22 @@ public function trainPartialPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], ['green'])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/LogisticRegressionTest.php b/tests/Classifiers/LogisticRegressionTest.php index 39ee60d87..da403b79d 100644 --- a/tests/Classifiers/LogisticRegressionTest.php +++ b/tests/Classifiers/LogisticRegressionTest.php @@ -1,15 +1,12 @@ generator = new Agglomerate([ - 'male' => new Blob([69.2, 195.7, 40.0], [2.0, 6.0, 0.6]), - 'female' => new Blob([63.7, 168.5, 38.1], [1.6, 5.0, 0.8]), - ], [0.45, 0.55]); - - $this->estimator = new LogisticRegression(100, new Adam(0.01), 1e-4, 300, 1e-4, 5, new CrossEntropy()); + $this->generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.0], + stdDev: [2.0, 6.0, 0.6] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [1.6, 5.0, 0.8] + ), + ], + weights: [0.45, 0.55] + ); + + $this->estimator = new LogisticRegression( + batchSize: 100, + optimizer: new Adam(rate: 0.01), + l2Penalty: 1e-4, + epochs: 300, + minChange: 1e-4, + window: 5, + costFn: new CrossEntropy() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LogisticRegression::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badBatchSize() : void + public function testBadBatchSize() : void { $this->expectException(InvalidArgumentException::class); - new LogisticRegression(-100); + new LogisticRegression(batchSize: -100); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -141,10 +109,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'batch size' => 100, @@ -159,10 +124,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -183,37 +145,34 @@ public function trainPartialPredict() : void $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $importances = $this->estimator->featureImportances(); $this->assertIsArray($importances); $this->assertCount(3, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); $this->assertEquals('8d9ffcb3', $this->estimator->revision()); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], ['green'])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/LogitBoostTest.php b/tests/Classifiers/LogitBoostTest.php index b9289f195..7327c50ce 100644 --- a/tests/Classifiers/LogitBoostTest.php +++ b/tests/Classifiers/LogitBoostTest.php @@ -1,14 +1,12 @@ generator = new Agglomerate([ - 'inner' => new Circle(0.0, 0.0, 5.0, 0.05), - 'outer' => new Circle(0.0, 0.0, 10.0, 0.1), - ], [0.4, 0.6]); - - $this->estimator = new LogitBoost(new RegressionTree(3), 0.1, 0.5, 1000, 1e-4, 3, 5, 0.1, new FBeta()); + $this->generator = new Agglomerate( + generators: [ + 'inner' => new Circle( + x: 0.0, + y: 0.0, + scale: 5.0, + noise: 0.05 + ), + 'outer' => new Circle( + x: 0.0, + y: 0.0, + scale: 10.0, + noise: 0.1 + ), + ], + weights: [0.4, 0.6] + ); + + $this->estimator = new LogitBoost( + booster: new RegressionTree(3), + rate: 0.1, + ratio: 0.5, + epochs: 1000, + minChange: 1e-4, + evalInterval: 3, + window: 5, + holdOut: 0.1, + metric: new FBeta() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LogitBoost::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -126,10 +105,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'booster' => new RegressionTree(3), @@ -146,10 +122,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -163,30 +136,30 @@ public function trainPredict() : void $scores = $this->estimator->losses(); $this->assertIsArray($scores); - $this->assertContainsOnly('float', $scores); + $this->assertContainsOnlyFloat($scores); $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $importances = $this->estimator->featureImportances(); $this->assertIsArray($importances); $this->assertCount(2, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/MultilayerPerceptronTest.php b/tests/Classifiers/MultilayerPerceptronTest.php index 7cc9e5fe2..5a1e5bdd8 100644 --- a/tests/Classifiers/MultilayerPerceptronTest.php +++ b/tests/Classifiers/MultilayerPerceptronTest.php @@ -1,21 +1,17 @@ generator = new Agglomerate([ - 'inner' => new Circle(0.0, 0.0, 1.0, 0.01), - 'middle' => new Circle(0.0, 0.0, 5.0, 0.05), - 'outer' => new Circle(0.0, 0.0, 10.0, 0.1), - ], [3, 3, 4]); - - $this->estimator = new MultilayerPerceptron([ - new Dense(32), - new Activation(new LeakyReLU(0.1)), - new Dropout(0.1), - new Dense(16), - new Activation(new LeakyReLU(0.1)), - new Noise(1e-5), - new Dense(8), - new Activation(new LeakyReLU(0.1)), - ], 32, new Adam(0.001), 100, 1e-3, 3, 5, 0.1, new CrossEntropy(), new FBeta()); + $this->generator = new Agglomerate( + generators: [ + 'inner' => new Circle( + x: 0.0, + y: 0.0, + scale: 1.0, + noise: 0.01 + ), + 'middle' => new Circle( + x: 0.0, + y: 0.0, + scale: 5.0, + noise: 0.05 + ), + 'outer' => new Circle( + x: 0.0, + y: 0.0, + scale: 10.0, + noise: 0.1 + ), + ], + weights: [3, 3, 4] + ); + + $this->estimator = new MultilayerPerceptron( + hiddenLayers: [ + new Dense(32), + new Activation(new LeakyReLU(0.1)), + new Dropout(0.1), + new Dense(16), + new Activation(new LeakyReLU(0.1)), + new Noise(1e-5), + new Dense(8), + new Activation(new LeakyReLU(0.1)), + ], + batchSize: 32, + optimizer: new Adam(rate: 0.001), + epochs: 100, + minChange: 1e-3, + evalInterval: 3, + window: 5, + holdOut: 0.1, + costFn: new CrossEntropy(), + metric: new FBeta() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MultilayerPerceptron::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badBatchSize() : void + public function testBadBatchSize() : void { $this->expectException(InvalidArgumentException::class); - new MultilayerPerceptron([], -100); + new MultilayerPerceptron(hiddenLayers: [], batchSize: -100); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -157,10 +137,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'hidden layers' => [ @@ -187,10 +164,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -213,39 +187,36 @@ public function trainPartialPredict() : void // Graphviz::dotToImage($dot)->saveTo(new Filesystem('test.png')); $this->assertInstanceOf(Encoding::class, $dot); - $this->assertStringStartsWith('digraph Tree {', $dot); + $this->assertStringStartsWith('digraph Tree {', (string) $dot); $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $scores = $this->estimator->scores(); $this->assertIsArray($scores); - $this->assertContainsOnly('float', $scores); + $this->assertContainsOnlyFloat($scores); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], ['green'])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/NaiveBayesTest.php b/tests/Classifiers/NaiveBayesTest.php index aa036c540..be0d4ad28 100644 --- a/tests/Classifiers/NaiveBayesTest.php +++ b/tests/Classifiers/NaiveBayesTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new NaiveBayes(null, 1.0); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new NaiveBayes(priors: null, smoothing: 1.0); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(NaiveBayes::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badAlpha() : void + public function testBadAlpha() : void { $this->expectException(InvalidArgumentException::class); - new NaiveBayes(null, -1.0); + new NaiveBayes(priors: null, smoothing: -1.0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -135,10 +102,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'priors' => null, @@ -148,10 +112,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $dataset = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE); @@ -172,25 +133,22 @@ public function trainPartialPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([[1.0]], ['green'])); + $this->estimator->train(Labeled::quick(samples: [[1.0]], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/OneVsRestTest.php b/tests/Classifiers/OneVsRestTest.php index efceb881a..92fa825d0 100644 --- a/tests/Classifiers/OneVsRestTest.php +++ b/tests/Classifiers/OneVsRestTest.php @@ -1,13 +1,13 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); $this->estimator = new OneVsRest(new GaussianNB()); @@ -89,36 +79,17 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(OneVsRest::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Parallel::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -127,10 +98,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'base' => new GaussianNB(), @@ -139,12 +107,8 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @dataProvider provideBackends - * @test - * @param Backend $backend - */ - public function trainPredictProba(Backend $backend) : void + #[DataProvider('provideBackends')] + public function testTrainPredictProba(Backend $backend) : void { $this->estimator->setBackend($backend); @@ -157,15 +121,15 @@ public function trainPredictProba(Backend $backend) : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/RadiusNeighborsTest.php b/tests/Classifiers/RadiusNeighborsTest.php index 5a2878bcb..1b38ca6f8 100644 --- a/tests/Classifiers/RadiusNeighborsTest.php +++ b/tests/Classifiers/RadiusNeighborsTest.php @@ -1,12 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new RadiusNeighbors(60.0, true, '?', new VantageTree()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new RadiusNeighbors( + radius: 60.0, + weighted: true, + outlierClass: '?', + tree: new VantageTree() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RadiusNeighbors::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badRadius() : void + public function testBadRadius() : void { $this->expectException(InvalidArgumentException::class); - new RadiusNeighbors(0.0); + new RadiusNeighbors(radius: 0.0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -133,10 +107,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'radius' => 60.0, @@ -148,10 +119,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -162,25 +130,22 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], ['green'])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/RandomForestTest.php b/tests/Classifiers/RandomForestTest.php index fc5a309d9..11687ae4a 100644 --- a/tests/Classifiers/RandomForestTest.php +++ b/tests/Classifiers/RandomForestTest.php @@ -1,13 +1,13 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new RandomForest(new ClassificationTree(3), 50, 0.2, true); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new RandomForest( + base: new ClassificationTree(maxHeight: 3), + estimators: 50, + ratio: 0.2, + balanced: true + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RandomForest::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badNumEstimators() : void + public function testBadNumEstimators() : void { $this->expectException(InvalidArgumentException::class); - new RandomForest(null, -100); + new RandomForest(base: null, estimators: -100); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -139,10 +112,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'base' => new ClassificationTree(3), @@ -154,12 +124,8 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @dataProvider provideBackends - * @test - * @param Backend $backend - */ - public function trainPredictImportances(Backend $backend) : void + #[DataProvider('provideBackends')] + public function testTrainPredictImportances(Backend $backend) : void { $this->estimator->setBackend($backend); @@ -174,19 +140,19 @@ public function trainPredictImportances(Backend $backend) : void $this->assertIsArray($importances); $this->assertCount(3, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Classifiers/SVCTest.php b/tests/Classifiers/SVCTest.php index 91184a35a..68ef23d62 100644 --- a/tests/Classifiers/SVCTest.php +++ b/tests/Classifiers/SVCTest.php @@ -1,10 +1,14 @@ generator = new Agglomerate([ - 'male' => new Blob([69.2, 195.7, 40.0], [2.0, 6.0, 0.6]), - 'female' => new Blob([63.7, 168.5, 38.1], [1.6, 5.0, 0.8]), - ], [0.45, 0.55]); - - $this->estimator = new SVC(1.0, new RBF(), true, 1e-3); + $this->generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.0], + stdDev: [2.0, 6.0, 0.6] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [1.6, 5.0, 0.8] + ), + ], + weights: [0.45, 0.55] + ); + + $this->estimator = new SVC( + c: 1.0, + kernel: new RBF(), + shrinking: true, + tolerance: 1e-3 + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void - { - $this->assertFalse($this->estimator->trained()); - } - - /** - * @after - */ + #[After] protected function tearDown() : void { if (file_exists('svc.model')) { @@ -100,28 +89,17 @@ protected function tearDown() : void } } - /** - * @test - */ - public function build() : void + public function testAssertPreConditions() : void { - $this->assertInstanceOf(SVC::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); + $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -130,10 +108,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'c' => 1.0, @@ -146,10 +121,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainSaveLoadPredict() : void + public function testTrainSaveLoadPredict() : void { $dataset = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE); @@ -167,28 +139,25 @@ public function trainSaveLoadPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']])); + $this->estimator->train(Labeled::quick(samples: [['bad']])); } - /** - * @test - */ public function predictUntrained() : void { $this->expectException(RuntimeException::class); - $this->estimator->predict(Unlabeled::quick([[1.5]])); + $this->estimator->predict(Unlabeled::quick(samples: [[1.5]])); } } diff --git a/tests/Classifiers/SoftmaxClassifierTest.php b/tests/Classifiers/SoftmaxClassifierTest.php index 3aef22c85..172a0b6b7 100644 --- a/tests/Classifiers/SoftmaxClassifierTest.php +++ b/tests/Classifiers/SoftmaxClassifierTest.php @@ -1,14 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new SoftmaxClassifier(10, new Adam(0.01), 1e-4, 300, 1e-4, 5, new CrossEntropy()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new SoftmaxClassifier( + batchSize: 10, + optimizer: new Adam(rate: 0.01), + l2Penalty: 1e-4, + epochs: 300, + minChange: 1e-4, + window: 5, + costFn: new CrossEntropy() + ); $this->metric = new FBeta(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SoftmaxClassifier::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badBatchSize() : void + public function testBadBatchSize() : void { $this->expectException(InvalidArgumentException::class); - new SoftmaxClassifier(-100); + new SoftmaxClassifier(batchSize: -100); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -140,10 +113,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'batch size' => 10, @@ -158,10 +128,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -182,29 +149,26 @@ public function trainPartialPredict() : void $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], ['green'])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: ['green'])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Clusterers/DBSCANTest.php b/tests/Clusterers/DBSCANTest.php index 3a4394eb0..6a7ec86a7 100644 --- a/tests/Clusterers/DBSCANTest.php +++ b/tests/Clusterers/DBSCANTest.php @@ -1,9 +1,12 @@ generator = new Agglomerate([ - 'inner' => new Circle(0.0, 0.0, 1.0, 0.01), - 'middle' => new Circle(0.0, 0.0, 5.0, 0.05), - 'outer' => new Circle(0.0, 0.0, 10.0, 0.1), - ]); + generators: $this->generator = new Agglomerate( + [ + 'inner' => new Circle(x: 0.0, y: 0.0, scale: 1.0, noise: 0.01), + 'middle' => new Circle(x: 0.0, y: 0.0, scale: 5.0, noise: 0.05), + 'outer' => new Circle(x: 0.0, y: 0.0, scale: 10.0, noise: 0.1), + ] + ); - $this->estimator = new DBSCAN(1.2, 20, new BallTree()); + $this->estimator = new DBSCAN(radius: 1.2, minDensity: 20, tree: new BallTree()); $this->metric = new VMeasure(); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(DBSCAN::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badRadius() : void + public function testBadRadius() : void { $this->expectException(InvalidArgumentException::class); - new DBSCAN(0.0); + new DBSCAN(radius: 0.0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::clusterer(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -113,10 +80,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'radius' => 1.2, @@ -127,27 +91,24 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function predict() : void + public function testPredict() : void { $testing = $this->generator->generate(self::TEST_SIZE); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ public function predictIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->predict(Unlabeled::quick([['bad']])); + $this->estimator->predict(Unlabeled::quick(samples: [['bad']])); } } diff --git a/tests/Clusterers/FuzzyCMeansTest.php b/tests/Clusterers/FuzzyCMeansTest.php index 635e6ac78..3832e78ac 100644 --- a/tests/Clusterers/FuzzyCMeansTest.php +++ b/tests/Clusterers/FuzzyCMeansTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new FuzzyCMeans(3, 2.0, 300, 1e-4, new Euclidean(), new Random()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new FuzzyCMeans( + c: 3, + fuzz: 2.0, + epochs: 300, + minChange: 1e-4, + kernel: new Euclidean(), + seeder: new Random() + ); $this->metric = new VMeasure(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(FuzzyCMeans::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badC() : void + public function testBadC() : void { $this->expectException(InvalidArgumentException::class); - new FuzzyCMeans(0); + new FuzzyCMeans(c: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::clusterer(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -136,10 +110,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'c' => 3, @@ -153,10 +124,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -171,33 +139,30 @@ public function trainPredict() : void $this->assertIsArray($centroids); $this->assertCount(3, $centroids); - $this->assertContainsOnly('array', $centroids); + $this->assertContainsOnlyArray($centroids); $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ public function trainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Unlabeled::quick([['bad']])); + $this->estimator->train(Unlabeled::quick(samples: [['bad']])); } - /** - * @test - */ public function predictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Clusterers/GaussianMixtureTest.php b/tests/Clusterers/GaussianMixtureTest.php index 8f6c5d278..e2318cf62 100644 --- a/tests/Clusterers/GaussianMixtureTest.php +++ b/tests/Clusterers/GaussianMixtureTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new GaussianMixture(3, 1e-9, 100, 1e-3, new KMC2(50)); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new GaussianMixture( + k: 3, + smoothing: 1e-9, + epochs: 100, + minChange: 1e-3, + seeder: new KMC2(m: 50) + ); $this->metric = new VMeasure(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GaussianMixture::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badK() : void + public function testBadK() : void { $this->expectException(InvalidArgumentException::class); - new GaussianMixture(0); + new GaussianMixture(k: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::clusterer(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -135,10 +108,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'k' => 3, @@ -151,10 +121,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -169,45 +136,42 @@ public function trainPredict() : void $this->assertIsArray($priors); $this->assertCount(3, $priors); - $this->assertContainsOnly('float', $priors); + $this->assertContainsOnlyFloat($priors); $means = $this->estimator->means(); $this->assertIsArray($means); $this->assertCount(3, $means); - $this->assertContainsOnly('array', $means); + $this->assertContainsOnlyArray($means); $variances = $this->estimator->variances(); $this->assertIsArray($variances); $this->assertCount(3, $variances); - $this->assertContainsOnly('array', $variances); + $this->assertContainsOnlyArray($variances); $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ public function trainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Unlabeled::quick([['bad']])); + $this->estimator->train(Unlabeled::quick(samples: [['bad']])); } - /** - * @test - */ public function predictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Clusterers/KMeansTest.php b/tests/Clusterers/KMeansTest.php index f55343037..a91bd8731 100644 --- a/tests/Clusterers/KMeansTest.php +++ b/tests/Clusterers/KMeansTest.php @@ -1,14 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new KMeans(3, 128, 300, 1e-4, 5, new Euclidean(), new PlusPlus()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new KMeans( + k:3, + batchSize: 128, + epochs: 300, + minChange: 1e-4, + window: 5, + kernel: new Euclidean(), + seeder: new PlusPlus() + ); $this->metric = new VMeasure(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KMeans::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badK() : void + public function testBadK() : void { $this->expectException(InvalidArgumentException::class); - new KMeans(0); + new KMeans(k: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::clusterer(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -138,10 +111,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'k' => 3, @@ -156,10 +126,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -178,43 +145,40 @@ public function trainPartialPredict() : void $this->assertIsArray($centroids); $this->assertCount(3, $centroids); - $this->assertContainsOnly('array', $centroids); + $this->assertContainsOnlyArray($centroids); $sizes = $this->estimator->sizes(); $this->assertIsArray($sizes); $this->assertCount(3, $sizes); - $this->assertContainsOnly('int', $sizes); + $this->assertContainsOnlyInt($sizes); $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Unlabeled::quick([['bad']])); + $this->estimator->train(Unlabeled::quick(samples: [['bad']])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); - $this->estimator->predict(Unlabeled::quick([[1.0]])); + $this->estimator->predict(Unlabeled::quick(samples: [[1.0]])); } } diff --git a/tests/Clusterers/MeanShiftTest.php b/tests/Clusterers/MeanShiftTest.php index 1079898cb..853121e40 100644 --- a/tests/Clusterers/MeanShiftTest.php +++ b/tests/Clusterers/MeanShiftTest.php @@ -1,13 +1,12 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 50.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 30.0), - ], [0.5, 0.2, 0.3]); - - $this->estimator = new MeanShift(66, 0.1, 100, 1e-4, new BallTree(), new Random()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 32, 0], + stdDev: 50.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 32, 255], + stdDev: 30.0 + ), + ], + weights: [0.5, 0.2, 0.3] + ); + + $this->estimator = new MeanShift( + radius: 66, + ratio: 0.1, + epochs: 100, + minShift: 1e-4, + tree: new BallTree(), + seeder: new Random() + ); $this->metric = new VMeasure(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MeanShift::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badRadius() : void + public function testBadRadius() : void { $this->expectException(InvalidArgumentException::class); - new MeanShift(0.0); + new MeanShift(radius: 0.0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::clusterer(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -136,10 +110,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'radius' => 66.0, @@ -153,22 +124,16 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function estimateRadius() : void + public function testEstimateRadius() : void { $subset = $this->generator->generate(intdiv(self::TRAIN_SIZE, 4)); - $radius = MeanShift::estimateRadius($subset, 30.0); + $radius = MeanShift::estimateRadius(dataset: $subset); $this->assertIsFloat($radius); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $this->estimator->setLogger(new BlackHole()); @@ -182,34 +147,31 @@ public function trainPredict() : void $centroids = $this->estimator->centroids(); $this->assertIsArray($centroids); - $this->assertContainsOnly('array', $centroids); + $this->assertContainsOnlyArray($centroids); $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + $score = $this->metric->score( + predictions: $predictions, + labels: $testing->labels() + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Unlabeled::quick([['bad']])); + $this->estimator->train(Unlabeled::quick(samples: [['bad']])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Clusterers/Seeders/KMC2Test.php b/tests/Clusterers/Seeders/KMC2Test.php index 704486366..cc4157255 100644 --- a/tests/Clusterers/Seeders/KMC2Test.php +++ b/tests/Clusterers/Seeders/KMC2Test.php @@ -1,61 +1,53 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 0, 0], 30.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 0, 255], 20.0), - ], [3, 3, 4]); + protected Agglomerate $generator; - $this->seeder = new KMC2(50, new Euclidean()); - } + protected KMC2 $seeder; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(KMC2::class, $this->seeder); - $this->assertInstanceOf(Seeder::class, $this->seeder); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 0, 0], + stdDev: 30.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 0, 255], + stdDev: 20.0 + ), + ], + weights: [3, 3, 4] + ); + + $this->seeder = new KMC2(m: 50, kernel: new Euclidean()); } - /** - * @test - */ - public function seed() : void + public function testSeed() : void { $dataset = $this->generator->generate(100); - $seeds = $this->seeder->seed($dataset, 3); + $seeds = $this->seeder->seed(dataset: $dataset, k: 3); $this->assertCount(3, $seeds); } diff --git a/tests/Clusterers/Seeders/PlusPlusTest.php b/tests/Clusterers/Seeders/PlusPlusTest.php index 41a146a08..2ffb2633f 100644 --- a/tests/Clusterers/Seeders/PlusPlusTest.php +++ b/tests/Clusterers/Seeders/PlusPlusTest.php @@ -1,61 +1,53 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 0, 0], 30.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 0, 255], 20.0), - ], [3, 3, 4]); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 0, 0], + stdDev: 30.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 0, 255], + stdDev: 20.0 + ), + ], + weights: [3, 3, 4] + ); $this->seeder = new PlusPlus(new Euclidean()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(PlusPlus::class, $this->seeder); - $this->assertInstanceOf(Seeder::class, $this->seeder); - } - - /** - * @test - */ - public function seed() : void + public function testSeed() : void { $dataset = $this->generator->generate(100); - $seeds = $this->seeder->seed($dataset, 3); + $seeds = $this->seeder->seed(dataset: $dataset, k: 3); $this->assertCount(3, $seeds); } diff --git a/tests/Clusterers/Seeders/PresetTest.php b/tests/Clusterers/Seeders/PresetTest.php index 06f9ac5ed..86c67cf4c 100644 --- a/tests/Clusterers/Seeders/PresetTest.php +++ b/tests/Clusterers/Seeders/PresetTest.php @@ -1,26 +1,21 @@ seeder = new Preset([ @@ -30,19 +25,7 @@ protected function setUp() : void ]); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Preset::class, $this->seeder); - $this->assertInstanceOf(Seeder::class, $this->seeder); - } - - /** - * @test - */ - public function seed() : void + public function testSeed() : void { $expected = [ ['foo', 14, 0.72], @@ -50,7 +33,7 @@ public function seed() : void ['beer', 21, 1.26], ]; - $seeds = $this->seeder->seed(Unlabeled::quick([['beef', 4, 13.0]]), 3); + $seeds = $this->seeder->seed(Unlabeled::quick(samples: [['beef', 4, 13.0]]), k: 3); $this->assertCount(3, $seeds); diff --git a/tests/Clusterers/Seeders/RandomTest.php b/tests/Clusterers/Seeders/RandomTest.php index 088e71688..6e1c35e6a 100644 --- a/tests/Clusterers/Seeders/RandomTest.php +++ b/tests/Clusterers/Seeders/RandomTest.php @@ -1,60 +1,52 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 0, 0], 30.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 0, 255], 20.0), - ], [3, 3, 4]); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob( + center: [255, 0, 0], + stdDev: 30.0 + ), + 'green' => new Blob( + center: [0, 128, 0], + stdDev: 10.0 + ), + 'blue' => new Blob( + center: [0, 0, 255], + stdDev: 20.0 + ), + ], + weights: [3, 3, 4] + ); $this->seeder = new Random(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Random::class, $this->seeder); - $this->assertInstanceOf(Seeder::class, $this->seeder); - } - - /** - * @test - */ - public function seed() : void + public function testSeed() : void { $dataset = $this->generator->generate(100); - $seeds = $this->seeder->seed($dataset, 3); + $seeds = $this->seeder->seed(dataset: $dataset, k: 3); $this->assertCount(3, $seeds); } diff --git a/tests/CrossValidation/HoldOutTest.php b/tests/CrossValidation/HoldOutTest.php index 5a797424e..3d048aba6 100644 --- a/tests/CrossValidation/HoldOutTest.php +++ b/tests/CrossValidation/HoldOutTest.php @@ -1,52 +1,47 @@ generator = new Agglomerate([ - 'male' => new Blob([69.2, 195.7, 40.], [1., 3., 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $this->generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.], + stdDev: [1., 3., 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $this->estimator = new GaussianNB(); @@ -55,25 +50,17 @@ protected function setUp() : void $this->metric = new Accuracy(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(HoldOut::class, $this->validator); - $this->assertInstanceOf(Validator::class, $this->validator); - } - - /** - * @test - */ - public function test() : void + public function testTestEstimator() : void { [$min, $max] = $this->metric->range()->list(); $dataset = $this->generator->generate(self::DATASET_SIZE); - $score = $this->validator->test($this->estimator, $dataset, $this->metric); + $score = $this->validator->test( + estimator: $this->estimator, + dataset: $dataset, + metric: $this->metric + ); $this->assertThat( $score, diff --git a/tests/CrossValidation/KFoldTest.php b/tests/CrossValidation/KFoldTest.php index 8a5fc54a8..0a328573a 100644 --- a/tests/CrossValidation/KFoldTest.php +++ b/tests/CrossValidation/KFoldTest.php @@ -1,11 +1,14 @@ generator = new Agglomerate([ - 'male' => new Blob([69.2, 195.7, 40.], [1., 3., 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $this->generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.], + stdDev: [1., 3., 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $this->estimator = new GaussianNB(); @@ -60,22 +55,8 @@ protected function setUp() : void $this->metric = new Accuracy(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KFold::class, $this->validator); - $this->assertInstanceOf(Validator::class, $this->validator); - $this->assertInstanceOf(Parallel::class, $this->validator); - } - - /** - * @dataProvider provideBackends - * @test - * @param Backend $backend - */ - public function test(Backend $backend) : void + #[DataProvider('provideBackends')] + public function testTestEstimator(Backend $backend) : void { $this->validator->setBackend($backend); @@ -83,7 +64,11 @@ public function test(Backend $backend) : void $dataset = $this->generator->generate(self::DATASET_SIZE); - $score = $this->validator->test($this->estimator, $dataset, $this->metric); + $score = $this->validator->test( + estimator: $this->estimator, + dataset: $dataset, + metric: $this->metric + ); $this->assertThat( $score, diff --git a/tests/CrossValidation/LeavePOutTest.php b/tests/CrossValidation/LeavePOutTest.php index aa2a8c995..9a44c3e4a 100644 --- a/tests/CrossValidation/LeavePOutTest.php +++ b/tests/CrossValidation/LeavePOutTest.php @@ -1,11 +1,14 @@ generator = new Agglomerate([ - 'male' => new Blob([69.2, 195.7, 40.], [1., 3., 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $this->generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.], + stdDev: [1., 3., 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $this->estimator = new GaussianNB(); @@ -60,22 +55,8 @@ protected function setUp() : void $this->metric = new Accuracy(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LeavePOut::class, $this->validator); - $this->assertInstanceOf(Validator::class, $this->validator); - $this->assertInstanceOf(Parallel::class, $this->validator); - } - - /** - * @dataProvider provideBackends - * @test - * @param Backend $backend - */ - public function test(Backend $backend) : void + #[DataProvider('provideBackends')] + public function testTestEstimator(Backend $backend) : void { $this->validator->setBackend($backend); @@ -83,7 +64,11 @@ public function test(Backend $backend) : void $dataset = $this->generator->generate(self::DATASET_SIZE); - $score = $this->validator->test($this->estimator, $dataset, $this->metric); + $score = $this->validator->test( + estimator: $this->estimator, + dataset: $dataset, + metric: $this->metric + ); $this->assertThat( $score, diff --git a/tests/CrossValidation/Metrics/AccuracyTest.php b/tests/CrossValidation/Metrics/AccuracyTest.php index b9cc508b1..f63c74031 100644 --- a/tests/CrossValidation/Metrics/AccuracyTest.php +++ b/tests/CrossValidation/Metrics/AccuracyTest.php @@ -1,46 +1,74 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new Accuracy(); + yield [ + ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.6, + ]; + + yield [ + ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.0, + ]; + + yield [ + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 0, 1, 0], + [0, 0, 0, 1, 0], + 0.8, + ]; + + yield [ + [0, 0, 0, 1, 0], + [0, 0, 0, 1, 0], + 1.0, + ]; + + yield [ + [1, 1, 1, 0, 1], + [0, 0, 0, 1, 0], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + #[Before] + protected function setUp() : void { - $this->assertInstanceOf(Accuracy::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new Accuracy(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +77,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::classifier(), @@ -63,18 +88,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -86,46 +112,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.6, - ]; - - yield [ - ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.0, - ]; - - yield [ - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 0, 1, 0], - [0, 0, 0, 1, 0], - 0.8, - ]; - - yield [ - [0, 0, 0, 1, 0], - [0, 0, 0, 1, 0], - 1.0, - ]; - - yield [ - [1, 1, 1, 0, 1], - [0, 0, 0, 1, 0], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/BrierScoreTest.php b/tests/CrossValidation/Metrics/BrierScoreTest.php index 701f38ba7..9962b8542 100644 --- a/tests/CrossValidation/Metrics/BrierScoreTest.php +++ b/tests/CrossValidation/Metrics/BrierScoreTest.php @@ -1,82 +1,27 @@ metric = new BrierScore(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ProbabilisticMetric::class, $this->metric); - $this->assertInstanceOf(BrierScore::class, $this->metric); - } - - /** - * @test - */ - public function range() : void - { - $tuple = $this->metric->range(); - - $this->assertInstanceOf(Tuple::class, $tuple); - $this->assertCount(2, $tuple); - $this->assertGreaterThan($tuple[0], $tuple[1]); - } + protected BrierScore $metric; /** - * @test - * @dataProvider scoreProvider - * - * @param list> $probabilities - * @param list $labels - * @param float $expected + * @return Generator */ - public function score(array $probabilities, array $labels, float $expected) : void - { - [$min, $max] = $this->metric->range()->list(); - - $score = $this->metric->score($probabilities, $labels); - - $this->assertThat( - $score, - $this->logicalAnd( - $this->greaterThanOrEqual($min), - $this->lessThanOrEqual($max) - ) - ); - - $this->assertEqualsWithDelta($expected, $score, 1e-8); - } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator + public static function scoreProvider() : Generator { yield [ [ @@ -138,4 +83,44 @@ public function scoreProvider() : Generator -0.5, ]; } + + protected function setUp() : void + { + $this->metric = new BrierScore(); + } + + public function testRange() : void + { + $tuple = $this->metric->range(); + + $this->assertInstanceOf(Tuple::class, $tuple); + $this->assertCount(2, $tuple); + $this->assertGreaterThan($tuple[0], $tuple[1]); + } + + /** + * @param list> $probabilities + * @param list $labels + * @param float $expected + */ + #[DataProvider('scoreProvider')] + public function testScore(array $probabilities, array $labels, float $expected) : void + { + [$min, $max] = $this->metric->range()->list(); + + $score = $this->metric->score( + probabilities: $probabilities, + labels: $labels + ); + + $this->assertThat( + $score, + $this->logicalAnd( + $this->greaterThanOrEqual($min), + $this->lessThanOrEqual($max) + ) + ); + + $this->assertEqualsWithDelta($expected, $score, 1e-8); + } } diff --git a/tests/CrossValidation/Metrics/CompletenessTest.php b/tests/CrossValidation/Metrics/CompletenessTest.php index 873b943f9..9c3bad24a 100644 --- a/tests/CrossValidation/Metrics/CompletenessTest.php +++ b/tests/CrossValidation/Metrics/CompletenessTest.php @@ -1,46 +1,66 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new Completeness(); + yield [ + [0, 1, 1, 0, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.5833333333333333, + ]; + + yield [ + [0, 0, 1, 1, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [1, 1, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 2, 3, 4], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.41666666666666663, + ]; + + yield [ + [0, 0, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(Completeness::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new Completeness(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +69,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::clusterer(), @@ -62,18 +79,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,40 +103,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [0, 1, 1, 0, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.5833333333333333, - ]; - - yield [ - [0, 0, 1, 1, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [1, 1, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 2, 3, 4], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.41666666666666663, - ]; - - yield [ - [0, 0, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/FBetaTest.php b/tests/CrossValidation/Metrics/FBetaTest.php index 57dd2fca5..acb4bf5ac 100644 --- a/tests/CrossValidation/Metrics/FBetaTest.php +++ b/tests/CrossValidation/Metrics/FBetaTest.php @@ -1,46 +1,72 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new FBeta(1.0); + yield [ + ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.5833333333333333, + ]; + + yield [ + ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.0, + ]; + + yield [ + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 0, 1, 0], + [0, 0, 0, 1, 0], + 0.8076923076923077, + ]; + + yield [ + [0, 0, 0, 1, 0], + [0, 0, 0, 1, 0], + 1.0, + ]; + + yield [ + [1, 1, 1, 0, 1], + [0, 0, 0, 1, 0], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(FBeta::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new FBeta(1.0); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +75,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::classifier(), @@ -63,18 +86,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -86,46 +110,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.5833333333333333, - ]; - - yield [ - ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.0, - ]; - - yield [ - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 0, 1, 0], - [0, 0, 0, 1, 0], - 0.8076923076923077, - ]; - - yield [ - [0, 0, 0, 1, 0], - [0, 0, 0, 1, 0], - 1.0, - ]; - - yield [ - [1, 1, 1, 0, 1], - [0, 0, 0, 1, 0], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/HomogeneityTest.php b/tests/CrossValidation/Metrics/HomogeneityTest.php index 47b05d595..b3b8a3760 100644 --- a/tests/CrossValidation/Metrics/HomogeneityTest.php +++ b/tests/CrossValidation/Metrics/HomogeneityTest.php @@ -1,46 +1,66 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new Homogeneity(); + yield [ + [0, 1, 1, 0, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.5833333333333333, + ]; + + yield [ + [0, 0, 1, 1, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [1, 1, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 2, 3, 4], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 0, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.6, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(Homogeneity::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new Homogeneity(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +69,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::clusterer(), @@ -62,18 +79,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,40 +103,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [0, 1, 1, 0, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.5833333333333333, - ]; - - yield [ - [0, 0, 1, 1, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [1, 1, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 2, 3, 4], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 0, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.6, - ]; - } } diff --git a/tests/CrossValidation/Metrics/InformednessTest.php b/tests/CrossValidation/Metrics/InformednessTest.php index aa1f276b6..f894aff90 100644 --- a/tests/CrossValidation/Metrics/InformednessTest.php +++ b/tests/CrossValidation/Metrics/InformednessTest.php @@ -1,46 +1,72 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new Informedness(); + yield [ + ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.16666666666666652, + ]; + + yield [ + ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + -1.0, + ]; + + yield [ + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 0, 1, 0], + [0, 0, 0, 1, 0], + 0.75, + ]; + + yield [ + [0, 0, 0, 1, 0], + [0, 0, 0, 1, 0], + 1.0, + ]; + + yield [ + [1, 1, 1, 0, 1], + [0, 0, 0, 1, 0], + -1.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(Informedness::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new Informedness(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +75,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::classifier(), @@ -63,18 +86,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -86,46 +110,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.16666666666666652, - ]; - - yield [ - ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - -1.0, - ]; - - yield [ - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 0, 1, 0], - [0, 0, 0, 1, 0], - 0.75, - ]; - - yield [ - [0, 0, 0, 1, 0], - [0, 0, 0, 1, 0], - 1.0, - ]; - - yield [ - [1, 1, 1, 0, 1], - [0, 0, 0, 1, 0], - -1.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/MCCTest.php b/tests/CrossValidation/Metrics/MCCTest.php index 22325cc5f..2b9e8332f 100644 --- a/tests/CrossValidation/Metrics/MCCTest.php +++ b/tests/CrossValidation/Metrics/MCCTest.php @@ -1,46 +1,72 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new MCC(); + yield [ + ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.16666666666666666, + ]; + + yield [ + ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + -1.0, + ]; + + yield [ + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 0, 1, 0], + [0, 0, 0, 1, 0], + 0.6123724356957946, + ]; + + yield [ + [0, 0, 0, 1, 0], + [0, 0, 0, 1, 0], + 1.0, + ]; + + yield [ + [1, 1, 1, 0, 1], + [0, 0, 0, 1, 0], + -1.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(MCC::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new MCC(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +75,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::classifier(), @@ -63,18 +86,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -86,46 +110,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.16666666666666666, - ]; - - yield [ - ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - -1.0, - ]; - - yield [ - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 0, 1, 0], - [0, 0, 0, 1, 0], - 0.6123724356957946, - ]; - - yield [ - [0, 0, 0, 1, 0], - [0, 0, 0, 1, 0], - 1.0, - ]; - - yield [ - [1, 1, 1, 0, 1], - [0, 0, 0, 1, 0], - -1.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php b/tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php index fd30236a8..4ab897f10 100644 --- a/tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php +++ b/tests/CrossValidation/Metrics/MeanAbsoluteErrorTest.php @@ -1,46 +1,54 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new MeanAbsoluteError(); + yield [ + [7, 9.5, -20, -500, .079], + [10, 10.0, 6, -1400, .08], + -185.90019999999998, + ]; + + yield [ + [0, 0, 0, 0, 0], + [10, 10.0, 6, -1400, .08], + -285.216, + ]; + + yield [ + [10, 10.0, 6, -1400, .08], + [10, 10.0, 6, -1400, .08], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(MeanAbsoluteError::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new MeanAbsoluteError(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +57,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::regressor(), @@ -62,18 +67,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (int|float)[] $predictions * @param (int|float)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,28 +91,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [7, 9.5, -20, -500, .079], - [10, 10.0, 6, -1400, .08], - -185.90019999999998, - ]; - - yield [ - [0, 0, 0, 0, 0], - [10, 10.0, 6, -1400, .08], - -285.216, - ]; - - yield [ - [10, 10.0, 6, -1400, .08], - [10, 10.0, 6, -1400, .08], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/MeanSquaredErrorTest.php b/tests/CrossValidation/Metrics/MeanSquaredErrorTest.php index e0008cd58..e4385f59c 100644 --- a/tests/CrossValidation/Metrics/MeanSquaredErrorTest.php +++ b/tests/CrossValidation/Metrics/MeanSquaredErrorTest.php @@ -1,46 +1,54 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new MeanSquaredError(); + yield [ + [7, 9.5, -20, -500, .079], + [10, 10.0, 6, -1400, .08], + -162137.0500002, + ]; + + yield [ + [0, 0, 0, 0, 0], + [10, 10.0, 6, -1400, .08], + -392047.20128000004, + ]; + + yield [ + [10, 10.0, 6, -1400, .08], + [10, 10.0, 6, -1400, .08], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(MeanSquaredError::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new MeanSquaredError(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +57,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::regressor(), @@ -62,18 +67,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (int|float)[] $predictions * @param (int|float)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,28 +91,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [7, 9.5, -20, -500, .079], - [10, 10.0, 6, -1400, .08], - -162137.0500002, - ]; - - yield [ - [0, 0, 0, 0, 0], - [10, 10.0, 6, -1400, .08], - -392047.20128000004, - ]; - - yield [ - [10, 10.0, 6, -1400, .08], - [10, 10.0, 6, -1400, .08], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php b/tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php index 212f5ca83..0386a1391 100644 --- a/tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php +++ b/tests/CrossValidation/Metrics/MedianAbsoluteErrorTest.php @@ -1,46 +1,54 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new MedianAbsoluteError(); + yield [ + [7, 9.5, -20, -500, .079], + [10, 10.0, 6, -1400, .08], + -3.0, + ]; + + yield [ + [0, 0, 0, 0, 0], + [10, 10.0, 6, -1400, .08], + -10.0, + ]; + + yield [ + [10, 10.0, 6, -1400, .08], + [10, 10.0, 6, -1400, .08], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(MedianAbsoluteError::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new MedianAbsoluteError(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +57,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::regressor(), @@ -62,18 +67,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (int|float)[] $predictions * @param (int|float)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,28 +91,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [7, 9.5, -20, -500, .079], - [10, 10.0, 6, -1400, .08], - -3.0, - ]; - - yield [ - [0, 0, 0, 0, 0], - [10, 10.0, 6, -1400, .08], - -10.0, - ]; - - yield [ - [10, 10.0, 6, -1400, .08], - [10, 10.0, 6, -1400, .08], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/ProbabilisticAccuracyTest.php b/tests/CrossValidation/Metrics/ProbabilisticAccuracyTest.php index 7d77c19d5..d7a7854a1 100644 --- a/tests/CrossValidation/Metrics/ProbabilisticAccuracyTest.php +++ b/tests/CrossValidation/Metrics/ProbabilisticAccuracyTest.php @@ -1,82 +1,27 @@ metric = new ProbabilisticAccuracy(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ProbabilisticMetric::class, $this->metric); - $this->assertInstanceOf(ProbabilisticAccuracy::class, $this->metric); - } - - /** - * @test - */ - public function range() : void - { - $tuple = $this->metric->range(); - - $this->assertInstanceOf(Tuple::class, $tuple); - $this->assertCount(2, $tuple); - $this->assertGreaterThan($tuple[0], $tuple[1]); - } + protected ProbabilisticAccuracy $metric; /** - * @test - * @dataProvider scoreProvider - * - * @param list> $probabilities - * @param list $labels - * @param float $expected + * @return Generator */ - public function score(array $probabilities, array $labels, float $expected) : void - { - [$min, $max] = $this->metric->range()->list(); - - $score = $this->metric->score($probabilities, $labels); - - $this->assertThat( - $score, - $this->logicalAnd( - $this->greaterThanOrEqual($min), - $this->lessThanOrEqual($max) - ) - ); - - $this->assertEqualsWithDelta($expected, $score, 1e-8); - } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator + public static function scoreProvider() : Generator { yield [ [ @@ -138,4 +83,44 @@ public function scoreProvider() : Generator 0.5, ]; } + + protected function setUp() : void + { + $this->metric = new ProbabilisticAccuracy(); + } + + public function testRange() : void + { + $tuple = $this->metric->range(); + + $this->assertInstanceOf(Tuple::class, $tuple); + $this->assertCount(2, $tuple); + $this->assertGreaterThan($tuple[0], $tuple[1]); + } + + /** + * @param list> $probabilities + * @param list $labels + * @param float $expected + */ + #[DataProvider('scoreProvider')] + public function testScore(array $probabilities, array $labels, float $expected) : void + { + [$min, $max] = $this->metric->range()->list(); + + $score = $this->metric->score( + probabilities: $probabilities, + labels: $labels + ); + + $this->assertThat( + $score, + $this->logicalAnd( + $this->greaterThanOrEqual($min), + $this->lessThanOrEqual($max) + ) + ); + + $this->assertEqualsWithDelta($expected, $score, 1e-8); + } } diff --git a/tests/CrossValidation/Metrics/RMSETest.php b/tests/CrossValidation/Metrics/RMSETest.php index b240d7328..d0716f2a1 100644 --- a/tests/CrossValidation/Metrics/RMSETest.php +++ b/tests/CrossValidation/Metrics/RMSETest.php @@ -1,46 +1,54 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new RMSE(); + yield [ + [7, 9.5, -20, -500, .079], + [10, 10.0, 6, -1400, .08], + -402.6624516890046, + ]; + + yield [ + [0, 0, 0, 0, 0], + [10, 10.0, 6, -1400, .08], + -626.1367273048276, + ]; + + yield [ + [10, 10.0, 6, -1400, .08], + [10, 10.0, 6, -1400, .08], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(RMSE::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new RMSE(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +57,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::regressor(), @@ -62,18 +67,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (int|float)[] $predictions * @param (int|float)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,28 +91,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [7, 9.5, -20, -500, .079], - [10, 10.0, 6, -1400, .08], - -402.6624516890046, - ]; - - yield [ - [0, 0, 0, 0, 0], - [10, 10.0, 6, -1400, .08], - -626.1367273048276, - ]; - - yield [ - [10, 10.0, 6, -1400, .08], - [10, 10.0, 6, -1400, .08], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/RSquaredTest.php b/tests/CrossValidation/Metrics/RSquaredTest.php index ed7fbf62f..b4739beff 100644 --- a/tests/CrossValidation/Metrics/RSquaredTest.php +++ b/tests/CrossValidation/Metrics/RSquaredTest.php @@ -1,46 +1,54 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new RSquared(); + yield [ + [7, 9.5, -20, -500, .079], + [10, 10.0, 6, -1400, .08], + 0.48778492125041795, + ]; + + yield [ + [0, 0, 0, 0, 0], + [10, 10.0, 6, -1400, .08], + -0.23853547401374797, + ]; + + yield [ + [10, 10.0, 6, -1400, .08], + [10, 10.0, 6, -1400, .08], + 1.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(RSquared::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new RSquared(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +57,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::regressor(), @@ -62,18 +67,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (int|float)[] $predictions * @param (int|float)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,28 +91,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [7, 9.5, -20, -500, .079], - [10, 10.0, 6, -1400, .08], - 0.48778492125041795, - ]; - - yield [ - [0, 0, 0, 0, 0], - [10, 10.0, 6, -1400, .08], - -0.23853547401374797, - ]; - - yield [ - [10, 10.0, 6, -1400, .08], - [10, 10.0, 6, -1400, .08], - 1.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/RandIndexTest.php b/tests/CrossValidation/Metrics/RandIndexTest.php index 1f5dce31e..c5957e470 100644 --- a/tests/CrossValidation/Metrics/RandIndexTest.php +++ b/tests/CrossValidation/Metrics/RandIndexTest.php @@ -1,46 +1,66 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new RandIndex(); + yield [ + [0, 1, 1, 0, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + -0.25000000000000006, + ]; + + yield [ + [0, 0, 1, 1, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [1, 1, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 2, 3, 4], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.0, + ]; + + yield [ + [0, 0, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(RandIndex::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new RandIndex(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +69,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::clusterer(), @@ -62,18 +79,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (int|string)[] $predictions * @param (int|string)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,40 +103,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [0, 1, 1, 0, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - -0.25000000000000006, - ]; - - yield [ - [0, 0, 1, 1, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [1, 1, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 2, 3, 4], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.0, - ]; - - yield [ - [0, 0, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/SMAPETest.php b/tests/CrossValidation/Metrics/SMAPETest.php index 9e22c30c2..4c3910941 100644 --- a/tests/CrossValidation/Metrics/SMAPETest.php +++ b/tests/CrossValidation/Metrics/SMAPETest.php @@ -1,46 +1,54 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new SMAPE(); + yield [ + [7, 9.5, -20, -500, .079], + [10, 10.0, 6, -1400, .08], + -33.641702651574725, + ]; + + yield [ + [0, 0, 0, 0, 0], + [10, 10.0, 6, -1400, .08], + -100.0, + ]; + + yield [ + [10, 10.0, 6, -1400, .08], + [10, 10.0, 6, -1400, .08], + 0.0, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(SMAPE::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new SMAPE(); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +57,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::regressor(), @@ -61,19 +66,20 @@ public function compatibility() : void $this->assertEquals($expected, $this->metric->compatibility()); } - /** - * @test - * @dataProvider scoreProvider - * + /*] * @param (int|float)[] $predictions * @param (int|float)[] $labels * @param float $expected */ - public function score(array $predictions, array $labels, float $expected) : void + #[DataProvider('scoreProvider')] + public function testScore(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,28 +91,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [7, 9.5, -20, -500, .079], - [10, 10.0, 6, -1400, .08], - -33.641702651574725, - ]; - - yield [ - [0, 0, 0, 0, 0], - [10, 10.0, 6, -1400, .08], - -100.0, - ]; - - yield [ - [10, 10.0, 6, -1400, .08], - [10, 10.0, 6, -1400, .08], - 0.0, - ]; - } } diff --git a/tests/CrossValidation/Metrics/TopKAccuracyTest.php b/tests/CrossValidation/Metrics/TopKAccuracyTest.php index 416765f29..0a5908176 100644 --- a/tests/CrossValidation/Metrics/TopKAccuracyTest.php +++ b/tests/CrossValidation/Metrics/TopKAccuracyTest.php @@ -1,82 +1,27 @@ metric = new TopKAccuracy(2); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ProbabilisticMetric::class, $this->metric); - $this->assertInstanceOf(TopKAccuracy::class, $this->metric); - } - - /** - * @test - */ - public function range() : void - { - $tuple = $this->metric->range(); - - $this->assertInstanceOf(Tuple::class, $tuple); - $this->assertCount(2, $tuple); - $this->assertGreaterThan($tuple[0], $tuple[1]); - } - - /** - * @test - * @dataProvider scoreProvider - * - * @param list> $probabilities - * @param list $labels - * @param float $expected - */ - public function score(array $probabilities, array $labels, float $expected) : void - { - [$min, $max] = $this->metric->range()->list(); - - $score = $this->metric->score($probabilities, $labels); - - $this->assertThat( - $score, - $this->logicalAnd( - $this->greaterThanOrEqual($min), - $this->lessThanOrEqual($max) - ) - ); - - $this->assertEqualsWithDelta($expected, $score, 1e-8); - } + protected TopKAccuracy $metric; /** - * @return \Generator + * @return Generator */ - public function scoreProvider() : Generator + public static function scoreProvider() : Generator { yield [ [ @@ -110,4 +55,44 @@ public function scoreProvider() : Generator 0.3333333333333, ]; } + + protected function setUp() : void + { + $this->metric = new TopKAccuracy(2); + } + + public function testRange() : void + { + $tuple = $this->metric->range(); + + $this->assertInstanceOf(Tuple::class, $tuple); + $this->assertCount(2, $tuple); + $this->assertGreaterThan($tuple[0], $tuple[1]); + } + + /*\ + * @param list> $probabilities + * @param list $labels + * @param float $expected + */ + #[DataProvider('scoreProvider')] + public function score(array $probabilities, array $labels, float $expected) : void + { + [$min, $max] = $this->metric->range()->list(); + + $score = $this->metric->score( + probabilities: $probabilities, + labels: $labels + ); + + $this->assertThat( + $score, + $this->logicalAnd( + $this->greaterThanOrEqual($min), + $this->lessThanOrEqual($max) + ) + ); + + $this->assertEqualsWithDelta($expected, $score, 1e-8); + } } diff --git a/tests/CrossValidation/Metrics/VMeasureTest.php b/tests/CrossValidation/Metrics/VMeasureTest.php index 10d0a09fe..fe92a5064 100644 --- a/tests/CrossValidation/Metrics/VMeasureTest.php +++ b/tests/CrossValidation/Metrics/VMeasureTest.php @@ -1,46 +1,66 @@ */ - protected function setUp() : void + public static function scoreProvider() : Generator { - $this->metric = new VMeasure(1.0); + yield [ + [0, 1, 1, 0, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.5833333333333333, + ]; + + yield [ + [0, 0, 1, 1, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [1, 1, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 1.0, + ]; + + yield [ + [0, 1, 2, 3, 4], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.5882352941176471, + ]; + + yield [ + [0, 0, 0, 0, 0], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + 0.7499999999999999, + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(VMeasure::class, $this->metric); - $this->assertInstanceOf(Metric::class, $this->metric); + $this->metric = new VMeasure(1.0); } - /** - * @test - */ - public function range() : void + public function testRange() : void { $tuple = $this->metric->range(); @@ -49,10 +69,7 @@ public function range() : void $this->assertGreaterThan($tuple[0], $tuple[1]); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::clusterer(), @@ -62,18 +79,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider scoreProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ + #[DataProvider('scoreProvider')] public function score(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); - $score = $this->metric->score($predictions, $labels); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertThat( $score, @@ -85,40 +103,4 @@ public function score(array $predictions, array $labels, float $expected) : void $this->assertEquals($expected, $score); } - - /** - * @return \Generator - */ - public function scoreProvider() : Generator - { - yield [ - [0, 1, 1, 0, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.5833333333333333, - ]; - - yield [ - [0, 0, 1, 1, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [1, 1, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 1.0, - ]; - - yield [ - [0, 1, 2, 3, 4], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.5882352941176471, - ]; - - yield [ - [0, 0, 0, 0, 0], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - 0.7499999999999999, - ]; - } } diff --git a/tests/CrossValidation/MonteCarloTest.php b/tests/CrossValidation/MonteCarloTest.php index c0c044644..f1c7e5d00 100644 --- a/tests/CrossValidation/MonteCarloTest.php +++ b/tests/CrossValidation/MonteCarloTest.php @@ -1,10 +1,13 @@ generator = new Agglomerate([ - 'male' => new Blob([69.2, 195.7, 40.], [1., 3., 0.3]), - 'female' => new Blob([63.7, 168.5, 38.1], [0.8, 2.5, 0.4]), - ], [0.45, 0.55]); + $this->generator = new Agglomerate( + generators: [ + 'male' => new Blob( + center: [69.2, 195.7, 40.], + stdDev: [1., 3., 0.3] + ), + 'female' => new Blob( + center: [63.7, 168.5, 38.1], + stdDev: [0.8, 2.5, 0.4] + ), + ], + weights: [0.45, 0.55] + ); $this->estimator = new GaussianNB(); - $this->validator = new MonteCarlo(3, 0.2); + $this->validator = new MonteCarlo(simulations: 3, ratio: 0.2); $this->metric = new Accuracy(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MonteCarlo::class, $this->validator); - $this->assertInstanceOf(Validator::class, $this->validator); - $this->assertInstanceOf(Parallel::class, $this->validator); - } - - /** - * @dataProvider provideBackends - * @test - * @param Backend $backend - */ - public function test(Backend $backend) : void + #[DataProvider('provideBackends')] + public function testTestEstimator(Backend $backend) : void { $this->validator->setBackend($backend); @@ -83,7 +64,11 @@ public function test(Backend $backend) : void $dataset = $this->generator->generate(self::DATASET_SIZE); - $score = $this->validator->test($this->estimator, $dataset, $this->metric); + $score = $this->validator->test( + estimator: $this->estimator, + dataset: $dataset, + metric: $this->metric + ); $this->assertThat( $score, diff --git a/tests/CrossValidation/Reports/AggregateReportTest.php b/tests/CrossValidation/Reports/AggregateReportTest.php index 17319e329..2e08b6a76 100644 --- a/tests/CrossValidation/Reports/AggregateReportTest.php +++ b/tests/CrossValidation/Reports/AggregateReportTest.php @@ -1,29 +1,24 @@ report = new AggregateReport([ @@ -32,19 +27,7 @@ protected function setUp() : void ]); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(AggregateReport::class, $this->report); - $this->assertInstanceOf(ReportGenerator::class, $this->report); - } - - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::classifier(), @@ -54,16 +37,16 @@ public function compatibility() : void $this->assertEquals($expected, $this->report->compatibility()); } - /** - * @test - */ - public function generate() : void + public function testGenerate() : void { $predictions = ['wolf', 'lamb', 'wolf', 'lamb', 'wolf']; $labels = ['lamb', 'lamb', 'wolf', 'wolf', 'wolf']; - $result = $this->report->generate($predictions, $labels); + $result = $this->report->generate( + predictions: $predictions, + labels: $labels + ); $this->assertInstanceOf(Report::class, $result); $this->assertCount(2, $result->toArray()); diff --git a/tests/CrossValidation/Reports/ConfusionMatrixTest.php b/tests/CrossValidation/Reports/ConfusionMatrixTest.php index 05c10452e..5829b4469 100644 --- a/tests/CrossValidation/Reports/ConfusionMatrixTest.php +++ b/tests/CrossValidation/Reports/ConfusionMatrixTest.php @@ -1,46 +1,51 @@ */ - protected function setUp() : void + public static function generateProvider() : Generator { - $this->report = new ConfusionMatrix(); + yield [ + ['wolf', 'lamb', 'wolf', 'lamb', 'wolf', 'lamb', 'lamb'], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf', 'lamb', 'wolf'], + [ + 'wolf' => [ + 'wolf' => 2, + 'lamb' => 1, + ], + 'lamb' => [ + 'wolf' => 2, + 'lamb' => 2, + ], + ], + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(ConfusionMatrix::class, $this->report); - $this->assertInstanceOf(ReportGenerator::class, $this->report); + $this->report = new ConfusionMatrix(); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::classifier(), @@ -51,39 +56,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider generateProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels - * @param mixed[] $expected + * @param array $expected */ - public function generate(array $predictions, array $labels, array $expected) : void + #[DataProvider('generateProvider')] + public function testGenerate(array $predictions, array $labels, array $expected) : void { - $result = $this->report->generate($predictions, $labels); + $result = $this->report->generate( + predictions: $predictions, + labels: $labels + ); $this->assertInstanceOf(Report::class, $result); $this->assertEquals($expected, $result->toArray()); } - - /** - * @return \Generator - */ - public function generateProvider() : Generator - { - yield [ - ['wolf', 'lamb', 'wolf', 'lamb', 'wolf', 'lamb', 'lamb'], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf', 'lamb', 'wolf'], - [ - 'wolf' => [ - 'wolf' => 2, - 'lamb' => 1, - ], - 'lamb' => [ - 'wolf' => 2, - 'lamb' => 2, - ], - ], - ]; - } } diff --git a/tests/CrossValidation/Reports/ContingencyTableTest.php b/tests/CrossValidation/Reports/ContingencyTableTest.php index 95c61bd21..2386fe480 100644 --- a/tests/CrossValidation/Reports/ContingencyTableTest.php +++ b/tests/CrossValidation/Reports/ContingencyTableTest.php @@ -1,46 +1,51 @@ */ - protected function setUp() : void + public static function generateProvider() : Generator { - $this->report = new ContingencyTable(); + yield [ + [0, 1, 1, 0, 1], + ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], + [ + 0 => [ + 'wolf' => 1, + 'lamb' => 1, + ], + 1 => [ + 'wolf' => 2, + 'lamb' => 1, + ], + ], + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(ContingencyTable::class, $this->report); - $this->assertInstanceOf(ReportGenerator::class, $this->report); + $this->report = new ContingencyTable(); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ EstimatorType::clusterer(), @@ -50,39 +55,19 @@ public function compatibility() : void } /** - * @test - * @dataProvider generateProvider - * * @param (string|int)[] $predictions * @param (string|int)[] $labels - * @param mixed[] $expected + * @param array $expected */ - public function generate(array $predictions, array $labels, array $expected) : void + #[DataProvider('generateProvider')] + public function testGenerate(array $predictions, array $labels, array $expected) : void { - $result = $this->report->generate($predictions, $labels); + $result = $this->report->generate( + predictions: $predictions, + labels: $labels + ); $this->assertInstanceOf(Report::class, $result); $this->assertEquals($expected, $result->toArray()); } - - /** - * @return \Generator - */ - public function generateProvider() : Generator - { - yield [ - [0, 1, 1, 0, 1], - ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], - [ - 0 => [ - 'wolf' => 1, - 'lamb' => 1, - ], - 1 => [ - 'wolf' => 2, - 'lamb' => 1, - ], - ], - ]; - } } diff --git a/tests/CrossValidation/Reports/ErrorAnalysisTest.php b/tests/CrossValidation/Reports/ErrorAnalysisTest.php index ae91b0b06..8e67a0cb7 100644 --- a/tests/CrossValidation/Reports/ErrorAnalysisTest.php +++ b/tests/CrossValidation/Reports/ErrorAnalysisTest.php @@ -1,74 +1,28 @@ report = new ErrorAnalysis(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ErrorAnalysis::class, $this->report); - $this->assertInstanceOf(ReportGenerator::class, $this->report); - } - - /** - * @test - */ - public function compatibility() : void - { - $expected = [ - EstimatorType::regressor(), - ]; - - $this->assertEquals($expected, $this->report->compatibility()); - } - - /** - * @test - * @dataProvider generateProvider - * - * @param (int|float)[] $predictions - * @param (int|float)[] $labels - * @param (int|float)[] $expected - */ - public function generate(array $predictions, array $labels, array $expected) : void - { - $results = $this->report->generate($predictions, $labels); - - $this->assertInstanceOf(Report::class, $results); - $this->assertEquals($expected, $results->toArray()); - } + protected ErrorAnalysis $report; /** - * @return \Generator + * @return Generator */ - public function generateProvider() : Generator + public static function generateProvider() : Generator { yield [ [10, 12, 15, 42, 56, 12, 17, 9, 1, 7], @@ -118,4 +72,35 @@ public function generateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->report = new ErrorAnalysis(); + } + + public function testCompatibility() : void + { + $expected = [ + EstimatorType::regressor(), + ]; + + $this->assertEquals($expected, $this->report->compatibility()); + } + + /** + * @param (int|float)[] $predictions + * @param (int|float)[] $labels + * @param (int|float)[] $expected + */ + #[DataProvider('generateProvider')] + public function testGenerate(array $predictions, array $labels, array $expected) : void + { + $results = $this->report->generate( + predictions: $predictions, + labels: $labels + ); + + $this->assertInstanceOf(Report::class, $results); + $this->assertEquals($expected, $results->toArray()); + } } diff --git a/tests/CrossValidation/Reports/MulticlassBreakdownTest.php b/tests/CrossValidation/Reports/MulticlassBreakdownTest.php index 85608b04f..31542acbf 100644 --- a/tests/CrossValidation/Reports/MulticlassBreakdownTest.php +++ b/tests/CrossValidation/Reports/MulticlassBreakdownTest.php @@ -1,75 +1,28 @@ report = new MulticlassBreakdown(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MulticlassBreakdown::class, $this->report); - $this->assertInstanceOf(ReportGenerator::class, $this->report); - } - - /** - * @test - */ - public function compatibility() : void - { - $expected = [ - EstimatorType::classifier(), - EstimatorType::anomalyDetector(), - ]; - - $this->assertEquals($expected, $this->report->compatibility()); - } - - /** - * @test - * @dataProvider generateProvider - * - * @param (string|int)[] $predictions - * @param (string|int)[] $labels - * @param mixed[] $expected - */ - public function generate(array $predictions, array $labels, array $expected) : void - { - $results = $this->report->generate($predictions, $labels); - - $this->assertInstanceOf(Report::class, $results); - $this->assertEquals($expected, $results->toArray()); - } + protected MulticlassBreakdown $report; /** - * @return \Generator + * @return Generator */ - public function generateProvider() : Generator + public static function generateProvider() : Generator { yield [ ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], @@ -219,4 +172,36 @@ public function generateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->report = new MulticlassBreakdown(); + } + + public function testCompatibility() : void + { + $expected = [ + EstimatorType::classifier(), + EstimatorType::anomalyDetector(), + ]; + + $this->assertEquals($expected, $this->report->compatibility()); + } + + /** + * @param (string|int)[] $predictions + * @param (string|int)[] $labels + * @param array $expected + */ + #[DataProvider('generateProvider')] + public function testGenerate(array $predictions, array $labels, array $expected) : void + { + $results = $this->report->generate( + predictions: $predictions, + labels: $labels + ); + + $this->assertInstanceOf(Report::class, $results); + $this->assertEquals($expected, $results->toArray()); + } } diff --git a/tests/DataProvider/BackendProviderTrait.php b/tests/DataProvider/BackendProviderTrait.php index 08851742f..4066e9855 100644 --- a/tests/DataProvider/BackendProviderTrait.php +++ b/tests/DataProvider/BackendProviderTrait.php @@ -1,11 +1,12 @@ $serialBackend, ]; - // $ampBackend = new Amp(); - - // yield (string) $ampBackend => [ - // 'backend' => $ampBackend, - // ]; - if ( SwooleExtensionIsLoaded::create()->passes() && ExtensionIsLoaded::with('igbinary')->passes() diff --git a/tests/Datasets/Generators/AgglomerateTest.php b/tests/Datasets/Generators/AgglomerateTest.php index 590d769ac..8f3f8efcd 100644 --- a/tests/Datasets/Generators/AgglomerateTest.php +++ b/tests/Datasets/Generators/AgglomerateTest.php @@ -1,59 +1,48 @@ generator = new Agglomerate([ - 'one' => new Blob([-5.0, 3.0], 0.2), - 'two' => new Blob([5.0, -3.0], 0.2), - ], [1, 0.5]); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Agglomerate::class, $this->generator); - $this->assertInstanceOf(Generator::class, $this->generator); + $this->generator = new Agglomerate( + generators: [ + 'one' => new Blob( + center: [-5.0, 3.0], + stdDev: 0.2 + ), + 'two' => new Blob( + center: [5.0, -3.0], + stdDev: 0.2 + ), + ], + weights: [1, 0.5] + ); } - /** - * @test - */ - public function dimensions() : void + public function testDimensions() : void { $this->assertEquals(2, $this->generator->dimensions()); } - /** - * @test - */ - public function generate() : void + public function testGenerate() : void { $dataset = $this->generator->generate(self::DATASET_SIZE); diff --git a/tests/Datasets/Generators/BlobTest.php b/tests/Datasets/Generators/BlobTest.php index 130d54143..70c9d623a 100644 --- a/tests/Datasets/Generators/BlobTest.php +++ b/tests/Datasets/Generators/BlobTest.php @@ -1,38 +1,31 @@ generator = new Blob([0, 0, 0], 1.0); + $this->generator = new Blob(center: [0, 0, 0], stdDev: 1.0); } - /** - * @test - */ - public function simulate() : void + public function testSimulate() : void { $dataset = $this->generator->generate(100); @@ -42,35 +35,17 @@ public function simulate() : void $this->assertInstanceOf(Generator::class, $generator); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Blob::class, $this->generator); - $this->assertInstanceOf(Generator::class, $this->generator); - } - - /** - * @test - */ - public function center() : void + public function testCenter() : void { $this->assertEquals([0, 0, 0], $this->generator->center()); } - /** - * @test - */ - public function dimensions() : void + public function testDimensions() : void { $this->assertEquals(3, $this->generator->dimensions()); } - /** - * @test - */ - public function generate() : void + public function testGenerate() : void { $dataset = $this->generator->generate(self::DATASET_SIZE); diff --git a/tests/Datasets/Generators/CircleTest.php b/tests/Datasets/Generators/CircleTest.php index 73f6ea2d2..1d063a874 100644 --- a/tests/Datasets/Generators/CircleTest.php +++ b/tests/Datasets/Generators/CircleTest.php @@ -1,55 +1,35 @@ generator = new Circle(5.0, 5.0, 10.0, 0.1); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Circle::class, $this->generator); - $this->assertInstanceOf(Generator::class, $this->generator); + $this->generator = new Circle(x: 5.0, y: 5.0, scale: 10.0, noise: 0.1); } - /** - * @test - */ - public function dimensions() : void + public function testDimensions() : void { $this->assertEquals(2, $this->generator->dimensions()); } - /** - * @test - */ - public function generate() : void + public function testGenerate() : void { $dataset = $this->generator->generate(self::DATASET_SIZE); diff --git a/tests/Datasets/Generators/HalfMoonTest.php b/tests/Datasets/Generators/HalfMoonTest.php index 648fb1c74..40dd72917 100644 --- a/tests/Datasets/Generators/HalfMoonTest.php +++ b/tests/Datasets/Generators/HalfMoonTest.php @@ -1,55 +1,35 @@ generator = new HalfMoon(5.0, 5.0, 10.0, 45.0, 0.1); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(HalfMoon::class, $this->generator); - $this->assertInstanceOf(Generator::class, $this->generator); + $this->generator = new HalfMoon(x: 5.0, y: 5.0, scale: 10.0, rotation: 45.0, noise: 0.1); } - /** - * @test - */ - public function dimensions() : void + public function testDimensions() : void { $this->assertEquals(2, $this->generator->dimensions()); } - /** - * @test - */ - public function generate() : void + public function testGenerate() : void { $dataset = $this->generator->generate(self::DATASET_SIZE); diff --git a/tests/Datasets/Generators/HyperplaneTest.php b/tests/Datasets/Generators/HyperplaneTest.php index d98c893ab..4ad922704 100644 --- a/tests/Datasets/Generators/HyperplaneTest.php +++ b/tests/Datasets/Generators/HyperplaneTest.php @@ -1,53 +1,33 @@ generator = new Hyperplane([0.001, -4.0, 12], 5.0); - } + protected Hyperplane $generator; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(Hyperplane::class, $this->generator); - $this->assertInstanceOf(Generator::class, $this->generator); + $this->generator = new Hyperplane(coefficients: [0.001, -4.0, 12], intercept: 5.0); } - /** - * @test - */ - public function dimensions() : void + public function testDimensions() : void { $this->assertEquals(3, $this->generator->dimensions()); } - /** - * @test - */ - public function generate() : void + public function testGenerate() : void { $dataset = $this->generator->generate(30); diff --git a/tests/Datasets/Generators/SwissRollTest.php b/tests/Datasets/Generators/SwissRollTest.php index a54b3158d..a388faf9a 100644 --- a/tests/Datasets/Generators/SwissRollTest.php +++ b/tests/Datasets/Generators/SwissRollTest.php @@ -1,55 +1,35 @@ generator = new SwissRoll(0.0, 0.0, 0.0, 1.0, 12.0, 0.3); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SwissRoll::class, $this->generator); - $this->assertInstanceOf(Generator::class, $this->generator); + $this->generator = new SwissRoll(x: 0.0, y: 0.0, z: 0.0, scale: 1.0, depth: 12.0, noise: 0.3); } - /** - * @test - */ - public function dimensions() : void + public function testDimensions() : void { $this->assertEquals(3, $this->generator->dimensions()); } - /** - * @test - */ - public function generate() : void + public function testGenerate() : void { $dataset = $this->generator->generate(self::DATASET_SIZE); diff --git a/tests/Datasets/LabeledTest.php b/tests/Datasets/LabeledTest.php index e00705dcb..8eb49ddc7 100644 --- a/tests/Datasets/LabeledTest.php +++ b/tests/Datasets/LabeledTest.php @@ -1,27 +1,25 @@ dataset = new Labeled(self::SAMPLES, self::LABELS, false); + $this->dataset = new Labeled( + samples: self::SAMPLES, + labels: self::LABELS, + verify: false + ); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Labeled::class, $this->dataset); - $this->assertInstanceOf(Dataset::class, $this->dataset); - $this->assertInstanceOf(Countable::class, $this->dataset); - $this->assertInstanceOf(ArrayAccess::class, $this->dataset); - $this->assertInstanceOf(IteratorAggregate::class, $this->dataset); - } - - /** - * @test - */ - public function fromIterator() : void + public function testFromIterator() : void { $dataset = Labeled::fromIterator(new NDJSON('tests/test.ndjson')); @@ -89,14 +70,11 @@ public function fromIterator() : void $this->assertEquals(self::LABELS, $dataset->labels()); } - /** - * @test - */ - public function stack() : void + public function testStack() : void { - $dataset1 = new Labeled([['sample1']], ['label1']); - $dataset2 = new Labeled([['sample2']], ['label2']); - $dataset3 = new Labeled([['sample3']], ['label3']); + $dataset1 = new Labeled(samples: [['sample1']], labels: ['label1']); + $dataset2 = new Labeled(samples: [['sample2']], labels: ['label2']); + $dataset3 = new Labeled(samples: [['sample3']], labels: ['label3']); $dataset = Labeled::stack([$dataset1, $dataset2, $dataset3]); @@ -106,45 +84,30 @@ public function stack() : void $this->assertEquals(1, $dataset->numFeatures()); } - /** - * @test - */ - public function samples() : void + public function testExamples() : void { $this->assertEquals(self::SAMPLES, $this->dataset->samples()); } - /** - * @test - */ - public function sample() : void + public function testSample() : void { $this->assertEquals(self::SAMPLES[2], $this->dataset->sample(2)); $this->assertEquals(self::SAMPLES[5], $this->dataset->sample(5)); } - /** - * @test - */ - public function numSamples() : void + public function testNumSamples() : void { $this->assertEquals(6, $this->dataset->numSamples()); } - /** - * @test - */ - public function feature() : void + public function testFeature() : void { $expected = array_column(self::SAMPLES, 2); $this->assertEquals($expected, $this->dataset->feature(2)); } - /** - * @test - */ - public function dropFeature() : void + public function testDropFeature() : void { $expected = [ ['nice', 'friendly', 4.0], @@ -160,18 +123,12 @@ public function dropFeature() : void $this->assertEquals($expected, $this->dataset->samples()); } - /** - * @test - */ - public function numFeatures() : void + public function testNumFeatures() : void { $this->assertEquals(4, $this->dataset->numFeatures()); } - /** - * @test - */ - public function featureType() : void + public function testFeatureType() : void { $this->assertEquals(DataType::categorical(), $this->dataset->featureType(0)); $this->assertEquals(DataType::categorical(), $this->dataset->featureType(1)); @@ -179,10 +136,7 @@ public function featureType() : void $this->assertEquals(DataType::continuous(), $this->dataset->featureType(3)); } - /** - * @test - */ - public function featureTypes() : void + public function testFeatureTypes() : void { $expected = [ DataType::categorical(), @@ -194,52 +148,34 @@ public function featureTypes() : void $this->assertEquals($expected, $this->dataset->featureTypes()); } - /** - * @test - */ - public function uniqueTypes() : void + public function testUniqueTypes() : void { $this->assertCount(2, $this->dataset->uniqueTypes()); } - /** - * @test - */ - public function homogeneous() : void + public function testHomogeneous() : void { $this->assertFalse($this->dataset->homogeneous()); } - /** - * @test - */ - public function shape() : void + public function testShape() : void { $this->assertEquals([6, 4], $this->dataset->shape()); } - /** - * @test - */ - public function size() : void + public function testSize() : void { $this->assertEquals(24, $this->dataset->size()); } - /** - * @test - */ - public function features() : void + public function testFeatures() : void { $expected = array_transpose(self::SAMPLES); $this->assertEquals($expected, $this->dataset->features()); } - /** - * @test - */ - public function types() : void + public function testTypes() : void { $expected = [ DataType::categorical(), @@ -252,10 +188,7 @@ public function types() : void $this->assertEquals($expected, $this->dataset->types()); } - /** - * @test - */ - public function featuresByType() : void + public function testFeaturesByType() : void { $expected = array_slice(array_transpose(self::SAMPLES), 0, 3); @@ -264,26 +197,17 @@ public function featuresByType() : void $this->assertEquals($expected, $columns); } - /** - * @test - */ - public function empty() : void + public function testEmpty() : void { $this->assertFalse($this->dataset->empty()); } - /** - * @test - */ - public function labels() : void + public function testLabels() : void { $this->assertEquals(self::LABELS, $this->dataset->labels()); } - /** - * @test - */ - public function transformLabels() : void + public function testTransformLabels() : void { $transformer = function ($label) { return $label === 'not monster' ? 0 : 1; @@ -298,27 +222,18 @@ public function transformLabels() : void $this->assertEquals($expected, $this->dataset->labels()); } - /** - * @test - */ - public function label() : void + public function testLabel() : void { $this->assertEquals('not monster', $this->dataset->label(0)); $this->assertEquals('monster', $this->dataset->label(1)); } - /** - * @test - */ - public function labelType() : void + public function testLabelType() : void { $this->assertEquals(DataType::categorical(), $this->dataset->labelType()); } - /** - * @test - */ - public function possibleOutcomes() : void + public function testPossibleOutcomes() : void { $this->assertEquals( ['not monster', 'monster'], @@ -326,10 +241,7 @@ public function possibleOutcomes() : void ); } - /** - * @test - */ - public function randomize() : void + public function testRandomize() : void { $samples = $this->dataset->samples(); $labels = $this->dataset->labels(); @@ -340,10 +252,7 @@ public function randomize() : void $this->assertNotEquals($labels, $this->dataset->labels()); } - /** - * @test - */ - public function filter() : void + public function testFilter() : void { $isFriendly = function ($record) { return $record[2] === 'friendly'; @@ -364,10 +273,7 @@ public function filter() : void $this->assertEquals($labels, $filtered->labels()); } - /** - * @test - */ - public function head() : void + public function testHead() : void { $subset = $this->dataset->head(3); @@ -375,10 +281,7 @@ public function head() : void $this->assertCount(3, $subset); } - /** - * @test - */ - public function tail() : void + public function testTail() : void { $subset = $this->dataset->tail(3); @@ -386,10 +289,7 @@ public function tail() : void $this->assertCount(3, $subset); } - /** - * @test - */ - public function take() : void + public function testTake() : void { $this->assertCount(6, $this->dataset); @@ -399,10 +299,7 @@ public function take() : void $this->assertCount(3, $this->dataset); } - /** - * @test - */ - public function leave() : void + public function testLeave() : void { $this->assertCount(6, $this->dataset); @@ -412,10 +309,7 @@ public function leave() : void $this->assertCount(1, $this->dataset); } - /** - * @test - */ - public function slice() : void + public function testSlice() : void { $this->assertCount(6, $this->dataset); @@ -426,10 +320,7 @@ public function slice() : void $this->assertCount(6, $this->dataset); } - /** - * @test - */ - public function splice() : void + public function testSplice() : void { $this->assertCount(6, $this->dataset); @@ -440,21 +331,15 @@ public function splice() : void $this->assertCount(4, $this->dataset); } - /** - * @test - */ - public function split() : void + public function testSplit() : void { - [$left, $right] = $this->dataset->split(0.5); + [$left, $right] = $this->dataset->split(); $this->assertCount(3, $left); $this->assertCount(3, $right); } - /** - * @test - */ - public function stratifiedSplit() : void + public function testStratifiedSplit() : void { [$left, $right] = $this->dataset->stratifiedSplit(0.5); @@ -462,10 +347,7 @@ public function stratifiedSplit() : void $this->assertCount(3, $right); } - /** - * @test - */ - public function fold() : void + public function testFold() : void { $folds = $this->dataset->fold(2); @@ -474,10 +356,7 @@ public function fold() : void $this->assertCount(3, $folds[1]); } - /** - * @test - */ - public function stratifiedFold() : void + public function testStratifiedFold() : void { $folds = $this->dataset->stratifiedFold(2); @@ -486,10 +365,7 @@ public function stratifiedFold() : void $this->assertCount(3, $folds[1]); } - /** - * @test - */ - public function stratifyByLabel() : void + public function testStratifyByLabel() : void { $strata = $this->dataset->stratifyByLabel(); @@ -497,10 +373,7 @@ public function stratifyByLabel() : void $this->assertCount(4, $strata['not monster']); } - /** - * @test - */ - public function batch() : void + public function testBatch() : void { $batches = $this->dataset->batch(2); @@ -510,10 +383,7 @@ public function batch() : void $this->assertCount(2, $batches[2]); } - /** - * @test - */ - public function partition() : void + public function testPartition() : void { [$left, $right] = $this->dataset->splitByFeature(1, 'rough'); @@ -524,40 +394,28 @@ public function partition() : void $this->assertCount(3, $right); } - /** - * @test - */ - public function randomSubset() : void + public function testRandomSubset() : void { $subset = $this->dataset->randomSubset(3); $this->assertCount(3, array_unique($subset->samples(), SORT_REGULAR)); } - /** - * @test - */ - public function randomSubsetWithReplacement() : void + public function testRandomSubsetWithReplacement() : void { $subset = $this->dataset->randomSubsetWithReplacement(3); $this->assertCount(3, $subset); } - /** - * @test - */ - public function randomWeightedSubsetWithReplacement() : void + public function testRandomWeightedSubsetWithReplacement() : void { $subset = $this->dataset->randomWeightedSubsetWithReplacement(3, self::WEIGHTS); $this->assertCount(3, $subset); } - /** - * @test - */ - public function merge() : void + public function testMerge() : void { $this->assertCount(count(self::SAMPLES), $this->dataset); @@ -571,10 +429,7 @@ public function merge() : void $this->assertEquals('not monster', $merged->label(6)); } - /** - * @test - */ - public function join() : void + public function testJoin() : void { $this->assertEquals(count(current(self::SAMPLES)), $this->dataset->numFeatures()); @@ -596,10 +451,7 @@ public function join() : void $this->assertEquals(self::LABELS, $joined->labels()); } - /** - * @test - */ - public function sort() : void + public function testSort() : void { $dataset = $this->dataset->sort(function ($recordA, $recordB) { return $recordA[3] > $recordB[3]; @@ -617,10 +469,7 @@ public function sort() : void $this->assertEquals($expected, $dataset->samples()); } - /** - * @test - */ - public function describe() : void + public function testDescribe() : void { $expected = [ [ @@ -682,10 +531,7 @@ public function describe() : void $this->assertEquals($expected, $results->toArray()); } - /** - * @test - */ - public function describeByLabel() : void + public function testDescribeByLabel() : void { $expected = [ 'not monster' => [ @@ -798,39 +644,27 @@ public function describeByLabel() : void $this->assertEquals($expected, $results->toArray()); } - /** - * @test - */ - public function deduplicate() : void + public function testDeduplicate() : void { $dataset = $this->dataset->deduplicate(); $this->assertCount(6, $dataset); } - /** - * @test - */ - public function testCount() : void + public function testTestCount() : void { $this->assertEquals(6, $this->dataset->count()); $this->assertCount(6, $this->dataset); } - /** - * @test - */ - public function arrayAccess() : void + public function testArrayAccess() : void { $expected = ['mean', 'furry', 'loner', -1.5, 'monster']; $this->assertEquals($expected, $this->dataset[1]); } - /** - * @test - */ - public function iterate() : void + public function testIterate() : void { $expected = [ ['nice', 'furry', 'friendly', 4.0, 'not monster'], diff --git a/tests/Datasets/UnlabeledTest.php b/tests/Datasets/UnlabeledTest.php index 76ef06550..725e960e7 100644 --- a/tests/Datasets/UnlabeledTest.php +++ b/tests/Datasets/UnlabeledTest.php @@ -1,26 +1,22 @@ dataset = new Unlabeled(self::SAMPLES, false); + $this->dataset = new Unlabeled(samples: self::SAMPLES, verify: false); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Unlabeled::class, $this->dataset); - $this->assertInstanceOf(Dataset::class, $this->dataset); - $this->assertInstanceOf(Countable::class, $this->dataset); - $this->assertInstanceOf(ArrayAccess::class, $this->dataset); - $this->assertInstanceOf(IteratorAggregate::class, $this->dataset); - } - - /** - * @test - */ - public function fromIterator() : void - { - $dataset = Unlabeled::fromIterator(new NDJSON('tests/test.ndjson')); - - $this->assertInstanceOf(Unlabeled::class, $dataset); - } - - /** - * @test - */ - public function stack() : void + public function testStack() : void { - $dataset1 = new Unlabeled([['sample1']]); - $dataset2 = new Unlabeled([['sample2']]); - $dataset3 = new Unlabeled([['sample3']]); + $dataset1 = new Unlabeled(samples: [['sample1']]); + $dataset2 = new Unlabeled(samples: [['sample2']]); + $dataset3 = new Unlabeled(samples: [['sample3']]); $dataset = Unlabeled::stack([$dataset1, $dataset2, $dataset3]); - $this->assertInstanceOf(Unlabeled::class, $dataset); - - $this->assertEquals(3, $dataset->numSamples()); - $this->assertEquals(1, $dataset->numFeatures()); + $this->assertSame(3, $dataset->numSamples()); + $this->assertSame(1, $dataset->numFeatures()); } - /** - * @test - */ - public function samples() : void + public function testSamples() : void { - $this->assertEquals(self::SAMPLES, $this->dataset->samples()); + $this->assertSame(self::SAMPLES, $this->dataset->samples()); } - /** - * @test - */ - public function sample() : void + public function testSample() : void { - $this->assertEquals(self::SAMPLES[2], $this->dataset->sample(2)); - $this->assertEquals(self::SAMPLES[5], $this->dataset->sample(5)); + $this->assertSame(self::SAMPLES[2], $this->dataset->sample(2)); + $this->assertSame(self::SAMPLES[5], $this->dataset->sample(5)); } - /** - * @test - */ - public function numSamples() : void + public function testNumSamples() : void { - $this->assertEquals(6, $this->dataset->numSamples()); + $this->assertSame(6, $this->dataset->numSamples()); } - /** - * @test - */ - public function feature() : void + public function testFeature() : void { $expected = array_column(self::SAMPLES, 2); - $this->assertEquals($expected, $this->dataset->feature(2)); + $this->assertSame($expected, $this->dataset->feature(2)); } - /** - * @test - */ - public function dropFeature() : void + public function testDropFeature() : void { $expected = [ ['nice', 'friendly', 4.0], @@ -147,21 +95,15 @@ public function dropFeature() : void $this->dataset->dropFeature(1); - $this->assertEquals($expected, $this->dataset->samples()); + $this->assertSame($expected, $this->dataset->samples()); } - /** - * @test - */ - public function numFeatures() : void + public function testNumFeatures() : void { - $this->assertEquals(4, $this->dataset->numFeatures()); + $this->assertSame(4, $this->dataset->numFeatures()); } - /** - * @test - */ - public function featureType() : void + public function testFeatureType() : void { $this->assertEquals(DataType::categorical(), $this->dataset->featureType(0)); $this->assertEquals(DataType::categorical(), $this->dataset->featureType(1)); @@ -169,10 +111,7 @@ public function featureType() : void $this->assertEquals(DataType::continuous(), $this->dataset->featureType(3)); } - /** - * @test - */ - public function featureTypes() : void + public function testFeatureTypes() : void { $expected = [ DataType::categorical(), @@ -184,52 +123,34 @@ public function featureTypes() : void $this->assertEquals($expected, $this->dataset->featureTypes()); } - /** - * @test - */ - public function uniqueTypes() : void + public function testUniqueTypes() : void { $this->assertCount(2, $this->dataset->uniqueTypes()); } - /** - * @test - */ - public function homogeneous() : void + public function testHomogeneous() : void { $this->assertFalse($this->dataset->homogeneous()); } - /** - * @test - */ - public function shape() : void + public function testShape() : void { - $this->assertEquals([6, 4], $this->dataset->shape()); + $this->assertSame([6, 4], $this->dataset->shape()); } - /** - * @test - */ - public function size() : void + public function testSize() : void { - $this->assertEquals(24, $this->dataset->size()); + $this->assertSame(24, $this->dataset->size()); } - /** - * @test - */ - public function features() : void + public function testFeatures() : void { $expected = array_transpose(self::SAMPLES); - $this->assertEquals($expected, $this->dataset->features()); + $this->assertSame($expected, $this->dataset->features()); } - /** - * @test - */ - public function types() : void + public function testTypes() : void { $expected = [ DataType::categorical(), @@ -241,10 +162,7 @@ public function types() : void $this->assertEquals($expected, $this->dataset->types()); } - /** - * @test - */ - public function filter() : void + public function testFilter() : void { $isFriendly = function ($record) { return $record[2] === 'friendly'; @@ -259,13 +177,10 @@ public function filter() : void ['nice', 'rough', 'friendly', 2.9], ]; - $this->assertEquals($expected, $filtered->samples()); + $this->assertSame($expected, $filtered->samples()); } - /** - * @test - */ - public function sort() : void + public function testSort() : void { $dataset = $this->dataset->sort(function ($recordA, $recordB) { return $recordA[3] > $recordB[3]; @@ -280,33 +195,24 @@ public function sort() : void ['nice', 'furry', 'friendly', 4.0], ]; - $this->assertEquals($expected, $dataset->samples()); + $this->assertSame($expected, $dataset->samples()); } - /** - * @test - */ - public function featuresByType() : void + public function testFeaturesByType() : void { $expected = array_slice(array_transpose(self::SAMPLES), 0, 3); $columns = $this->dataset->featuresByType(DataType::categorical()); - $this->assertEquals($expected, $columns); + $this->assertSame($expected, $columns); } - /** - * @test - */ - public function empty() : void + public function testEmpty() : void { $this->assertFalse($this->dataset->empty()); } - /** - * @test - */ - public function randomize() : void + public function testRandomize() : void { $samples = $this->dataset->samples(); @@ -315,99 +221,69 @@ public function randomize() : void $this->assertNotEquals($samples, $this->dataset->samples()); } - /** - * @test - */ - public function head() : void + public function testHead() : void { $subset = $this->dataset->head(3); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(3, $subset); } - /** - * @test - */ - public function tail() : void + public function testTail() : void { $subset = $this->dataset->tail(3); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(3, $subset); } - /** - * @test - */ - public function take() : void + public function testTake() : void { $this->assertCount(6, $this->dataset); $subset = $this->dataset->take(3); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(3, $subset); $this->assertCount(3, $this->dataset); } - /** - * @test - */ - public function leave() : void + public function testLeave() : void { $this->assertCount(6, $this->dataset); - $subset = $this->dataset->leave(1); + $subset = $this->dataset->leave(); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(5, $subset); $this->assertCount(1, $this->dataset); } - /** - * @test - */ - public function slice() : void + public function testSlice() : void { $this->assertCount(6, $this->dataset); $subset = $this->dataset->slice(2, 2); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(2, $subset); $this->assertCount(6, $this->dataset); } - /** - * @test - */ - public function splice() : void + public function testSplice() : void { $this->assertCount(6, $this->dataset); - $subset = $this->dataset->splice(2, 2); + $subset = $this->dataset->splice(offset: 2, n: 2); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(2, $subset); $this->assertCount(4, $this->dataset); } - /** - * @test - */ - public function split() : void + public function testSplit() : void { - [$left, $right] = $this->dataset->split(0.5); + [$left, $right] = $this->dataset->split(); $this->assertCount(3, $left); $this->assertCount(3, $right); } - /** - * @test - */ - public function fold() : void + public function testFold() : void { $folds = $this->dataset->fold(2); @@ -416,10 +292,7 @@ public function fold() : void $this->assertCount(3, $folds[1]); } - /** - * @test - */ - public function batch() : void + public function testBatch() : void { $batches = $this->dataset->batch(2); @@ -429,72 +302,49 @@ public function batch() : void $this->assertCount(2, $batches[2]); } - /** - * @test - */ - public function partition() : void + public function testPartition() : void { - [$left, $right] = $this->dataset->splitByFeature(2, 'loner'); - - $this->assertInstanceOf(Unlabeled::class, $left); - $this->assertInstanceOf(Unlabeled::class, $right); + [$left, $right] = $this->dataset->splitByFeature(column: 2, value: 'loner'); $this->assertCount(2, $left); $this->assertCount(4, $right); } - /** - * @test - */ - public function randomSubset() : void + public function testRandomSubset() : void { $subset = $this->dataset->randomSubset(3); $this->assertCount(3, array_unique($subset->samples(), SORT_REGULAR)); } - /** - * @test - */ - public function randomSubsetWithReplacement() : void + public function testRandomSubsetWithReplacement() : void { $subset = $this->dataset->randomSubsetWithReplacement(3); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(3, $subset); } - /** - * @test - */ - public function randomWeightedSubsetWithReplacement() : void + public function testRandomWeightedSubsetWithReplacement() : void { - $subset = $this->dataset->randomWeightedSubsetWithReplacement(3, self::WEIGHTS); + $subset = $this->dataset->randomWeightedSubsetWithReplacement(n: 3, weights: self::WEIGHTS); - $this->assertInstanceOf(Unlabeled::class, $subset); $this->assertCount(3, $subset); } - /** - * @test - */ - public function merge() : void + public function testMerge() : void { $this->assertCount(count(self::SAMPLES), $this->dataset); - $dataset = new Unlabeled([['nice', 'furry', 'friendly', 4.7]]); + $dataset = new Unlabeled(samples: [['nice', 'furry', 'friendly', 4.7]]); $merged = $this->dataset->merge($dataset); $this->assertCount(count(self::SAMPLES) + 1, $merged); - $this->assertEquals(['nice', 'furry', 'friendly', 4.7], $merged->sample(6)); + $this->assertSame(['nice', 'furry', 'friendly', 4.7], $merged->sample(6)); } - /** - * @test - */ - public function join() : void + public function testJoin() : void { $this->assertEquals(count(current(self::SAMPLES)), $this->dataset->numFeatures()); @@ -509,16 +359,13 @@ public function join() : void $joined = $this->dataset->join($dataset); - $this->assertEquals(count(current(self::SAMPLES)) + 1, $joined->numFeatures()); + $this->assertSame(count(current(self::SAMPLES)) + 1, $joined->numFeatures()); - $this->assertEquals(['mean', 'furry', 'loner', -1.5, 2], $joined->sample(1)); - $this->assertEquals(['nice', 'rough', 'friendly', 2.6, 3], $joined->sample(2)); + $this->assertSame(['mean', 'furry', 'loner', -1.5, 2], $joined->sample(1)); + $this->assertSame(['nice', 'rough', 'friendly', 2.6, 3], $joined->sample(2)); } - /** - * @test - */ - public function describe() : void + public function testDescribe() : void { $results = $this->dataset->describe(); @@ -567,43 +414,30 @@ public function describe() : void ], ]; - $this->assertInstanceOf(Report::class, $results); $this->assertEquals($expected, $results->toArray()); } - /** - * @test - */ - public function deduplicate() : void + public function testDeduplicate() : void { $dataset = $this->dataset->deduplicate(); $this->assertCount(6, $dataset); } - /** - * @test - */ public function testCount() : void { $this->assertEquals(6, $this->dataset->count()); $this->assertCount(6, $this->dataset); } - /** - * @test - */ - public function arrayAccess() : void + public function testArrayAccess() : void { $expected = ['mean', 'furry', 'loner', -1.5]; - $this->assertEquals($expected, $this->dataset[1]); + $this->assertSame($expected, $this->dataset[1]); } - /** - * @test - */ - public function iterate() : void + public function testIterate() : void { $expected = [ ['nice', 'furry', 'friendly', 4.0], @@ -614,6 +448,6 @@ public function iterate() : void ['nice', 'furry', 'loner', -5.0], ]; - $this->assertEquals($expected, iterator_to_array($this->dataset)); + $this->assertSame($expected, iterator_to_array($this->dataset)); } } diff --git a/tests/DeferredTest.php b/tests/DeferredTest.php deleted file mode 100644 index fbed95a68..000000000 --- a/tests/DeferredTest.php +++ /dev/null @@ -1,45 +0,0 @@ -deferred = new Deferred(function ($a, $b) { - return $a + $b; - }, [1, 2]); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Deferred::class, $this->deferred); - $this->assertIsCallable($this->deferred); - } - - /** - * @test - */ - public function compute() : void - { - $this->assertEquals(3, $this->deferred->compute()); - } -} diff --git a/tests/Extractors/CSVTest.php b/tests/Extractors/CSVTest.php index f2010c31c..fdb666a58 100644 --- a/tests/Extractors/CSVTest.php +++ b/tests/Extractors/CSVTest.php @@ -1,49 +1,31 @@ extractor = new CSV('tests/test.csv', true, ',', '"'); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(CSV::class, $this->extractor); - $this->assertInstanceOf(Extractor::class, $this->extractor); - $this->assertInstanceOf(Exporter::class, $this->extractor); - $this->assertInstanceOf(IteratorAggregate::class, $this->extractor); - $this->assertInstanceOf(Traversable::class, $this->extractor); + $this->extractor = new CSV( + path: 'tests/test.csv', + header: true, + delimiter: ',', + enclosure: '"' + ); } - /** - * @test - */ - public function header() : void + public function testHeader() : void { $expected = [ 'attitude', 'texture', 'sociability', 'rating', 'class', @@ -52,10 +34,7 @@ public function header() : void $this->assertEquals($expected, $this->extractor->header()); } - /** - * @test - */ - public function extractExport() : void + public function testExtractExport() : void { $expected = [ ['attitude' => 'nice', 'texture' => 'furry', 'sociability' => 'friendly', 'rating' => '4', 'class' => 'not monster'], @@ -78,7 +57,7 @@ public function extractExport() : void $this->assertEquals($expected, $header); - $this->extractor->export($records, true); + $this->extractor->export(iterator: $records, overwrite: true); $this->assertFileExists('tests/test.csv'); } diff --git a/tests/Extractors/ColumnFilterTest.php b/tests/Extractors/ColumnFilterTest.php index cd0997026..846694933 100644 --- a/tests/Extractors/ColumnFilterTest.php +++ b/tests/Extractors/ColumnFilterTest.php @@ -1,50 +1,32 @@ extractor = new ColumnFilter(new CSV('tests/test.csv', true), [ - 'texture', - ]); - } + protected ColumnFilter $extractor; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(ColumnFilter::class, $this->extractor); - $this->assertInstanceOf(Extractor::class, $this->extractor); - $this->assertInstanceOf(IteratorAggregate::class, $this->extractor); - $this->assertInstanceOf(Traversable::class, $this->extractor); + $this->extractor = new ColumnFilter( + iterator: new CSV(path: 'tests/test.csv', header: true), + columns: [ + 'texture', + ] + ); } - /** - * @test - */ - public function extract() : void + public function testExtract() : void { $expected = [ ['attitude' => 'nice', 'class' => 'not monster', 'rating' => '4', 'sociability' => 'friendly'], diff --git a/tests/Extractors/ColumnPickerTest.php b/tests/Extractors/ColumnPickerTest.php index d2e1e74d7..df7556647 100644 --- a/tests/Extractors/ColumnPickerTest.php +++ b/tests/Extractors/ColumnPickerTest.php @@ -1,50 +1,32 @@ extractor = new ColumnPicker(new CSV('tests/test.csv', true), [ - 'attitude', 'texture', 'class', 'rating', - ]); - } + protected ColumnPicker $extractor; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(ColumnPicker::class, $this->extractor); - $this->assertInstanceOf(Extractor::class, $this->extractor); - $this->assertInstanceOf(IteratorAggregate::class, $this->extractor); - $this->assertInstanceOf(Traversable::class, $this->extractor); + $this->extractor = new ColumnPicker( + iterator: new CSV(path: 'tests/test.csv', header: true), + columns: [ + 'attitude', 'texture', 'class', 'rating', + ] + ); } - /** - * @test - */ - public function extract() : void + public function testExtract() : void { $expected = [ ['attitude' => 'nice', 'texture' => 'furry', 'class' => 'not monster', 'rating' => '4'], diff --git a/tests/Extractors/ConcatenatorTest.php b/tests/Extractors/ConcatenatorTest.php index 4033f7ba9..6b982c4a2 100644 --- a/tests/Extractors/ConcatenatorTest.php +++ b/tests/Extractors/ConcatenatorTest.php @@ -1,51 +1,33 @@ extractor = new Concatenator([ - new CSV('tests/test.csv', true), - new CSV('tests/test.csv', true), + new CSV(path: 'tests/test.csv', header: true), + new CSV(path: 'tests/test.csv', header: true), ]); } /** * @test */ - public function build() : void - { - $this->assertInstanceOf(Concatenator::class, $this->extractor); - $this->assertInstanceOf(Extractor::class, $this->extractor); - $this->assertInstanceOf(IteratorAggregate::class, $this->extractor); - $this->assertInstanceOf(Traversable::class, $this->extractor); - } - - /** - * @test - */ - public function extract() : void + public function testExtract() : void { $expected = [ ['attitude' => 'nice', 'texture' => 'furry', 'sociability' => 'friendly', 'rating' => '4', 'class' => 'not monster'], diff --git a/tests/Extractors/DeduplicatorTest.php b/tests/Extractors/DeduplicatorTest.php index cf684df61..e9e01f60d 100644 --- a/tests/Extractors/DeduplicatorTest.php +++ b/tests/Extractors/DeduplicatorTest.php @@ -1,27 +1,20 @@ 'nice', 'texture' => 'furry', 'sociability' => 'loner', 'rating' => '-5', 'class' => 'not monster'], ]; - $this->extractor = new Deduplicator($iterator); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Deduplicator::class, $this->extractor); - $this->assertInstanceOf(Extractor::class, $this->extractor); - $this->assertInstanceOf(IteratorAggregate::class, $this->extractor); - $this->assertInstanceOf(Traversable::class, $this->extractor); + $this->extractor = new Deduplicator(iterator: $iterator); } - /** - * @test - */ - public function extract() : void + public function testExtract() : void { $expected = [ ['attitude' => 'nice', 'texture' => 'furry', 'sociability' => 'friendly', 'rating' => '4', 'class' => 'not monster'], diff --git a/tests/Extractors/NDJSONTest.php b/tests/Extractors/NDJSONTest.php index 18269f752..6af41c0db 100644 --- a/tests/Extractors/NDJSONTest.php +++ b/tests/Extractors/NDJSONTest.php @@ -1,49 +1,26 @@ extractor = new NDJSON('tests/test.ndjson'); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(NDJSON::class, $this->extractor); - $this->assertInstanceOf(Extractor::class, $this->extractor); - $this->assertInstanceOf(Exporter::class, $this->extractor); - $this->assertInstanceOf(IteratorAggregate::class, $this->extractor); - $this->assertInstanceOf(Traversable::class, $this->extractor); - } - - /** - * @test - */ - public function extractExport() : void + public function testExtractExport() : void { $expected = [ ['attitude' => 'nice', 'texture' => 'furry', 'sociability' => 'friendly', 'rating' => 4, 'class' => 'not monster'], diff --git a/tests/Extractors/SQLTableTest.php b/tests/Extractors/SQLTableTest.php index 38832c8fb..b015745eb 100644 --- a/tests/Extractors/SQLTableTest.php +++ b/tests/Extractors/SQLTableTest.php @@ -1,51 +1,34 @@ extractor = new SQLTable($connection, 'test', 3); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SQLTable::class, $this->extractor); - $this->assertInstanceOf(Extractor::class, $this->extractor); - $this->assertInstanceOf(IteratorAggregate::class, $this->extractor); - $this->assertInstanceOf(Traversable::class, $this->extractor); + $this->extractor = new SQLTable(connection: $connection, table: 'test', batchSize: 3); } /** * @test */ - public function extract() : void + public function testExtract() : void { $expected = [ ['attitude' => 'nice', 'texture' => 'furry', 'sociability' => 'friendly', 'rating' => 4.0, 'class' => 'not monster'], diff --git a/tests/Graph/Nodes/AverageTest.php b/tests/Graph/Nodes/AverageTest.php index e57780a9a..a4091dc82 100644 --- a/tests/Graph/Nodes/AverageTest.php +++ b/tests/Graph/Nodes/AverageTest.php @@ -1,69 +1,46 @@ node = new Average(self::OUTCOME, self::IMPURITY, self::N); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Average::class, $this->node); - $this->assertInstanceOf(Outcome::class, $this->node); - $this->assertInstanceOf(Decision::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Average( + outcome: self::OUTCOME, + impurity: self::IMPURITY, + n: self::N + ); } - /** - * @test - */ - public function outcome() : void + public function testOutcome() : void { $this->assertSame(self::OUTCOME, $this->node->outcome()); } - /** - * @test - */ - public function impurity() : void + public function testImpurity() : void { $this->assertSame(self::IMPURITY, $this->node->impurity()); } - /** - * @test - */ - public function n() : void + public function testN() : void { $this->assertSame(self::N, $this->node->n()); } diff --git a/tests/Graph/Nodes/BallTest.php b/tests/Graph/Nodes/BallTest.php index c5ad8e380..bc314c1ae 100644 --- a/tests/Graph/Nodes/BallTest.php +++ b/tests/Graph/Nodes/BallTest.php @@ -1,112 +1,76 @@ node = new Ball(self::CENTER, self::RADIUS, $subsets); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Ball::class, $this->node); - $this->assertInstanceOf(Hypersphere::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Ball(center: self::CENTER, radius: self::RADIUS, subsets: $subsets); } - /** - * @test - */ - public function split() : void + public function testSplit() : void { - $dataset = Labeled::quick(self::SAMPLES, self::LABELS); + $dataset = Labeled::quick(samples: self::SAMPLES, labels: self::LABELS); - $node = Ball::split($dataset, new Euclidean()); + $node = Ball::split(dataset: $dataset, kernel: new Euclidean()); $this->assertEquals(self::CENTER, $node->center()); $this->assertEquals(self::RADIUS, $node->radius()); } - /** - * @test - */ - public function center() : void + public function testCenter() : void { $this->assertSame(self::CENTER, $this->node->center()); } - /** - * @test - */ - public function radius() : void + public function testRadius() : void { $this->assertSame(self::RADIUS, $this->node->radius()); } - /** - * @test - */ - public function subsets() : void + public function testSubsets() : void { $expected = [ - Labeled::quick([self::SAMPLES[0]], [self::LABELS[0]]), - Labeled::quick([self::SAMPLES[1]], [self::LABELS[1]]), + Labeled::quick(samples: [self::SAMPLES[0]], labels: [self::LABELS[0]]), + Labeled::quick(samples: [self::SAMPLES[1]], labels: [self::LABELS[1]]), ]; $this->assertEquals($expected, $this->node->subsets()); } - /** - * @test - */ - public function cleanup() : void + public function testCleanup() : void { - $subsets = $this->node->subsets(); - - $this->assertIsArray($subsets); - $this->assertCount(2, $subsets); - $this->node->cleanup(); $this->expectException(RuntimeException::class); diff --git a/tests/Graph/Nodes/BestTest.php b/tests/Graph/Nodes/BestTest.php index abe500472..b0e3134a9 100644 --- a/tests/Graph/Nodes/BestTest.php +++ b/tests/Graph/Nodes/BestTest.php @@ -1,82 +1,57 @@ 0.7, 'pencil' => 0.3, ]; - protected const IMPURITY = 14.1; + protected const float IMPURITY = 14.1; - protected const N = 6; + protected const int N = 6; - /** - * @var Best - */ - protected $node; + protected Best $node; - /** - * @before - */ protected function setUp() : void { - $this->node = new Best(self::OUTCOME, self::PROBABILITIES, self::IMPURITY, self::N); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Best::class, $this->node); - $this->assertInstanceOf(Outcome::class, $this->node); - $this->assertInstanceOf(Decision::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Best( + outcome: self::OUTCOME, + probabilities: self::PROBABILITIES, + impurity: self::IMPURITY, + n: self::N + ); } - /** - * @test - */ - public function outcome() : void + public function testOutcome() : void { $this->assertEquals(self::OUTCOME, $this->node->outcome()); } - /** - * @test - */ - public function probabilities() : void + public function testProbabilities() : void { $this->assertEquals(self::PROBABILITIES, $this->node->probabilities()); } - /** - * @test - */ - public function impurity() : void + public function testImpurity() : void { $this->assertEquals(self::IMPURITY, $this->node->impurity()); } - /** - * @test - */ - public function n() : void + public function testN() : void { $this->assertEquals(self::N, $this->node->n()); } diff --git a/tests/Graph/Nodes/BoxTest.php b/tests/Graph/Nodes/BoxTest.php index 7864cc896..06ec55975 100644 --- a/tests/Graph/Nodes/BoxTest.php +++ b/tests/Graph/Nodes/BoxTest.php @@ -1,124 +1,91 @@ node = new Box(self::COLUMN, self::VALUE, $subsets, self::MIN, self::MAX); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Box::class, $this->node); - $this->assertInstanceOf(Hypercube::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Box( + column: self::COLUMN, + value: self::VALUE, + subsets: $subsets, + min: self::MIN, + max: self::MAX + ); } - /** - * @test - */ - public function split() : void + public function testSplit() : void { - $node = Box::split(Labeled::quick(self::SAMPLES, self::LABELS)); + $node = Box::split(Labeled::quick(samples: self::SAMPLES, labels: self::LABELS)); $this->assertEquals(self::BOX, iterator_to_array($node->sides())); } - /** - * @test - */ - public function column() : void + public function testColumn() : void { $this->assertSame(self::COLUMN, $this->node->column()); } - /** - * @test - */ - public function value() : void + public function testValue() : void { $this->assertSame(self::VALUE, $this->node->value()); } - /** - * @test - */ - public function subsets() : void + public function testSubsets() : void { $expected = [ - Labeled::quick([self::SAMPLES[0]], [self::LABELS[0]]), - Labeled::quick([self::SAMPLES[1]], [self::LABELS[1]]), + Labeled::quick(samples: [self::SAMPLES[0]], labels: [self::LABELS[0]]), + Labeled::quick(samples: [self::SAMPLES[1]], labels: [self::LABELS[1]]), ]; $this->assertEquals($expected, $this->node->subsets()); } - /** - * @test - */ - public function sides() : void + public function testSides() : void { $this->assertEquals(self::BOX, iterator_to_array($this->node->sides())); } - /** - * @test - */ - public function cleanup() : void + public function testCleanup() : void { - $subsets = $this->node->subsets(); - - $this->assertIsArray($subsets); - $this->assertCount(2, $subsets); - $this->node->cleanup(); $this->expectException(RuntimeException::class); diff --git a/tests/Graph/Nodes/CliqueTest.php b/tests/Graph/Nodes/CliqueTest.php index b0af79c8f..b73ec3f8b 100644 --- a/tests/Graph/Nodes/CliqueTest.php +++ b/tests/Graph/Nodes/CliqueTest.php @@ -1,93 +1,66 @@ node = new Clique($dataset, self::CENTER, self::RADIUS); - } + $dataset = Labeled::quick(samples: self::SAMPLES, labels: self::LABELS); - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Clique::class, $this->node); - $this->assertInstanceOf(Hypersphere::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Clique( + dataset: $dataset, + center: self::CENTER, + radius: self::RADIUS + ); } - /** - * @test - */ - public function terminate() : void + public function testTerminate() : void { - $dataset = Labeled::quick(self::SAMPLES, self::LABELS); + $dataset = Labeled::quick(samples: self::SAMPLES, labels: self::LABELS); - $node = Clique::terminate($dataset, new Euclidean()); + $node = Clique::terminate(dataset: $dataset, kernel: new Euclidean()); - $this->assertInstanceOf(Clique::class, $node); - $this->assertInstanceOf(Labeled::class, $node->dataset()); $this->assertEquals(self::CENTER, $node->center()); $this->assertEquals(self::RADIUS, $node->radius()); } - /** - * @test - */ - public function dataset() : void + public function testDataset() : void { - $this->assertInstanceOf(Labeled::class, $this->node->dataset()); $this->assertEquals(self::SAMPLES, $this->node->dataset()->samples()); $this->assertEquals(self::LABELS, $this->node->dataset()->labels()); } - /** - * @test - */ - public function center() : void + public function testCenter() : void { $this->assertEquals(self::CENTER, $this->node->center()); } - /** - * @test - */ - public function radius() : void + public function testRadius() : void { $this->assertEquals(self::RADIUS, $this->node->radius()); } diff --git a/tests/Graph/Nodes/DepthTest.php b/tests/Graph/Nodes/DepthTest.php index e1e9991df..31ebd789e 100644 --- a/tests/Graph/Nodes/DepthTest.php +++ b/tests/Graph/Nodes/DepthTest.php @@ -1,54 +1,37 @@ node = new Depth(self::C); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Depth::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); - } - - /** - * @test - */ - public function c() : void + public function testC() : void { $this->assertEquals(3.748880484475505, Depth::c(10)); $this->assertEquals(8.364671030072245, Depth::c(100)); @@ -57,22 +40,16 @@ public function c() : void $this->assertEquals(22.180282259643523, Depth::c(100000)); } - /** - * @test - */ - public function terminate() : void + public function testTerminate() : void { - $dataset = Unlabeled::quick(self::SAMPLES); + $dataset = Unlabeled::quick(samples: self::SAMPLES); - $node = Depth::terminate($dataset, self::DEPTH); + $node = Depth::terminate(dataset: $dataset, depth: self::DEPTH); $this->assertEquals(self::C, $node->depth()); } - /** - * @test - */ - public function depth() : void + public function testDepth() : void { $this->assertEquals(self::C, $this->node->depth()); } diff --git a/tests/Graph/Nodes/IsolatorTest.php b/tests/Graph/Nodes/IsolatorTest.php index a78a2a7d4..a13426f89 100644 --- a/tests/Graph/Nodes/IsolatorTest.php +++ b/tests/Graph/Nodes/IsolatorTest.php @@ -1,93 +1,57 @@ node = new Isolator(self::COLUMN, self::VALUE, $subsets); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Isolator::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Isolator( + column: self::COLUMN, + value: self::VALUE, + subsets: $subsets + ); } - /** - * @test - */ - public function split() : void - { - $dataset = Unlabeled::quick(self::SAMPLES); - - $node = Isolator::split($dataset); - - $this->assertInstanceOf(Isolator::class, $node); - } - - /** - * @test - */ - public function column() : void + public function testColumn() : void { $this->assertSame(self::COLUMN, $this->node->column()); } - /** - * @test - */ - public function value() : void + public function testValue() : void { $this->assertSame(self::VALUE, $this->node->value()); } - /** - * @test - */ - public function cleanup() : void + public function testCleanup() : void { - $subsets = $this->node->subsets(); - - $this->assertIsArray($subsets); - $this->assertCount(2, $subsets); - $this->node->cleanup(); $this->expectException(RuntimeException::class); diff --git a/tests/Graph/Nodes/NeighborhoodTest.php b/tests/Graph/Nodes/NeighborhoodTest.php index 755957c2f..156c47e47 100644 --- a/tests/Graph/Nodes/NeighborhoodTest.php +++ b/tests/Graph/Nodes/NeighborhoodTest.php @@ -1,87 +1,59 @@ node = new Neighborhood($dataset, self::MIN, self::MAX); - } + $dataset = Labeled::quick(samples: self::SAMPLES, labels: self::LABELS); - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Neighborhood::class, $this->node); - $this->assertInstanceOf(Hypercube::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Neighborhood(dataset: $dataset, min: self::MIN, max: self::MAX); } - /** - * @test - */ - public function terminate() : void + public function testTerminate() : void { - $node = Neighborhood::terminate(Labeled::quick(self::SAMPLES, self::LABELS)); + $node = Neighborhood::terminate(Labeled::quick(samples: self::SAMPLES, labels: self::LABELS)); - $this->assertInstanceOf(Neighborhood::class, $node); - $this->assertInstanceOf(Labeled::class, $node->dataset()); $this->assertEquals(self::BOX, iterator_to_array($node->sides())); } - /** - * @test - */ - public function dataset() : void + public function testDataset() : void { - $this->assertInstanceOf(Labeled::class, $this->node->dataset()); $this->assertEquals(self::SAMPLES, $this->node->dataset()->samples()); $this->assertEquals(self::LABELS, $this->node->dataset()->labels()); } - /** - * @test - */ - public function sides() : void + public function testSides() : void { $this->assertEquals(self::BOX, iterator_to_array($this->node->sides())); } diff --git a/tests/Graph/Nodes/SplitTest.php b/tests/Graph/Nodes/SplitTest.php index f53ee12a8..0929ec1d6 100644 --- a/tests/Graph/Nodes/SplitTest.php +++ b/tests/Graph/Nodes/SplitTest.php @@ -1,129 +1,105 @@ node = new Split(self::COLUMN, self::VALUE, $subsets, self::IMPURITY, self::N); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Split::class, $this->node); - $this->assertInstanceOf(Decision::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new Split( + column: self::COLUMN, + value: self::VALUE, + subsets: $subsets, + impurity: self::IMPURITY, + n: self::N + ); } - /** - * @test - */ - public function column() : void + public function testColumn() : void { $this->assertSame(self::COLUMN, $this->node->column()); } - /** - * @test - */ - public function value() : void + public function testValue() : void { $this->assertSame(self::VALUE, $this->node->value()); } - /** - * @test - */ - public function subsets() : void + public function testSubsets() : void { $expected = [ - Labeled::quick(self::SAMPLES, self::LABELS), - Labeled::quick(self::SAMPLES, self::LABELS), + Labeled::quick(samples: self::SAMPLES, labels: self::LABELS), + Labeled::quick(samples: self::SAMPLES, labels: self::LABELS), ]; $this->assertEquals($expected, $this->node->subsets()); } - /** - * @test - */ - public function impurity() : void + public function testImpurity() : void { $this->assertSame(self::IMPURITY, $this->node->impurity()); } - /** - * @test - */ - public function purityIncrease() : void + public function testPurityIncrease() : void { - $this->node->attachLeft(new Split(2, 0.0, [Labeled::quick(), Labeled::quick()], 50.0, 1)); - $this->node->attachRight(new Split(4, -12.0, [Labeled::quick(), Labeled::quick()], 200.0, 3)); + $this->node->attachLeft(new Split( + column: 2, + value: 0.0, + subsets: [Labeled::quick(), Labeled::quick()], + impurity: 50.0, + n: 1 + )); + $this->node->attachRight(new Split( + column: 4, + value: -12.0, + subsets: [Labeled::quick(), Labeled::quick()], + impurity: 200.0, + n: 3 + )); $this->assertSame(237.5, $this->node->purityIncrease()); } - /** - * @test - */ - public function n() : void + public function testN() : void { $this->assertSame(self::N, $this->node->n()); } - /** - * @test - */ - public function cleanup() : void + public function testCleanup() : void { - $subsets = $this->node->subsets(); - - $this->assertIsArray($subsets); - $this->assertCount(2, $subsets); - $this->node->cleanup(); $this->expectException(RuntimeException::class); diff --git a/tests/Graph/Nodes/VantagePointTest.php b/tests/Graph/Nodes/VantagePointTest.php index 64d9a20a2..28ac916d5 100644 --- a/tests/Graph/Nodes/VantagePointTest.php +++ b/tests/Graph/Nodes/VantagePointTest.php @@ -1,98 +1,72 @@ node = new VantagePoint(self::CENTER, self::RADIUS, $groups); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(VantagePoint::class, $this->node); - $this->assertInstanceOf(Hypersphere::class, $this->node); - $this->assertInstanceOf(BinaryNode::class, $this->node); - $this->assertInstanceOf(Node::class, $this->node); + $this->node = new VantagePoint( + center:self::CENTER, + radius: self::RADIUS, + subsets: $groups + ); } - /** - * @test - */ - public function split() : void + public function testSplit() : void { - $dataset = Labeled::quick(self::SAMPLES, self::LABELS); + $dataset = Labeled::quick(samples: self::SAMPLES, labels: self::LABELS); - $node = VantagePoint::split($dataset, new Euclidean()); + $node = VantagePoint::split(dataset: $dataset, kernel: new Euclidean()); $this->assertEquals(self::CENTER, $node->center()); $this->assertEquals(self::RADIUS, $node->radius()); } - /** - * @test - */ - public function center() : void + public function testCenter() : void { $this->assertSame(self::CENTER, $this->node->center()); } - /** - * @test - */ - public function radius() : void + public function testRadius() : void { $this->assertSame(self::RADIUS, $this->node->radius()); } - /** - * @test - */ - public function subsets() : void + public function testSubsets() : void { $expected = [ - Labeled::quick([self::SAMPLES[0]], [self::LABELS[0]]), - Labeled::quick([self::SAMPLES[1]], [self::LABELS[1]]), + Labeled::quick(samples: [self::SAMPLES[0]], labels: [self::LABELS[0]]), + Labeled::quick(samples: [self::SAMPLES[1]], labels: [self::LABELS[1]]), ]; $this->assertEquals($expected, $this->node->subsets()); diff --git a/tests/Graph/Trees/BallTreeTest.php b/tests/Graph/Trees/BallTreeTest.php index e1ac42fda..c192fb0a3 100644 --- a/tests/Graph/Trees/BallTreeTest.php +++ b/tests/Graph/Trees/BallTreeTest.php @@ -1,71 +1,53 @@ generator = new Agglomerate([ - 'east' => new Blob([5, -2, -2]), - 'west' => new Blob([0, 5, -3]), - ], [0.5, 0.5]); - - $this->tree = new BallTree(20, new Euclidean()); + $this->generator = new Agglomerate( + generators: [ + 'east' => new Blob(center: [5, -2, -2]), + 'west' => new Blob(center: [0, 5, -3]), + ], + weights: [0.5, 0.5] + ); + + $this->tree = new BallTree( + 20, + new Euclidean() + ); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertEquals(0, $this->tree->height()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(BallTree::class, $this->tree); - $this->assertInstanceOf(Spatial::class, $this->tree); - $this->assertInstanceOf(BinaryTree::class, $this->tree); - $this->assertInstanceOf(Tree::class, $this->tree); - } - - /** - * @test - */ - public function growNeighborsRange() : void + public function testGrowNeighborsRange() : void { $this->tree->grow($this->generator->generate(self::DATASET_SIZE)); @@ -90,13 +72,10 @@ public function growNeighborsRange() : void $this->assertCount(1, array_unique($labels)); } - /** - * @test - */ - public function growWithSameSamples() : void + public function testGrowWithSameSamples() : void { - $generator = new Agglomerate([ - 'east' => new Blob([5, -2, 10], 0.0), + $generator = new Agglomerate(generators: [ + 'east' => new Blob(center: [5, -2, 10], stdDev: 0.0), ]); $dataset = $generator->generate(self::DATASET_SIZE); diff --git a/tests/Graph/Trees/ITreeTest.php b/tests/Graph/Trees/ITreeTest.php index b1fab9f68..8b55c248d 100644 --- a/tests/Graph/Trees/ITreeTest.php +++ b/tests/Graph/Trees/ITreeTest.php @@ -1,69 +1,50 @@ generator = new Agglomerate([ - 'east' => new Blob([5, -2, -2]), - 'west' => new Blob([0, 5, -3]), - ], [0.5, 0.5]); + $this->generator = new Agglomerate( + generators: [ + 'east' => new Blob(center: [5, -2, -2]), + 'west' => new Blob(center: [0, 5, -3]), + ], + weights: [0.5, 0.5] + ); $this->tree = new ITree(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertEquals(0, $this->tree->height()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ITree::class, $this->tree); - $this->assertInstanceOf(BinaryTree::class, $this->tree); - $this->assertInstanceOf(Tree::class, $this->tree); - } - - /** - * @test - */ - public function growSearch() : void + public function testGrowSearch() : void { $this->tree->grow($this->generator->generate(self::DATASET_SIZE)); @@ -76,13 +57,10 @@ public function growSearch() : void $this->assertInstanceOf(Depth::class, $node); } - /** - * @test - */ - public function growWithSameSamples() : void + public function testGrowWithSameSamples() : void { - $generator = new Agglomerate([ - 'east' => new Blob([5, -2, 10], 0.0), + $generator = new Agglomerate(generators: [ + 'east' => new Blob(center: [5, -2, 10], stdDev: 0.0), ]); $dataset = $generator->generate(self::DATASET_SIZE); diff --git a/tests/Graph/Trees/KDTreeTest.php b/tests/Graph/Trees/KDTreeTest.php index 71918a552..8d18d18b6 100644 --- a/tests/Graph/Trees/KDTreeTest.php +++ b/tests/Graph/Trees/KDTreeTest.php @@ -1,71 +1,53 @@ generator = new Agglomerate([ - 'east' => new Blob([5, -2, -2]), - 'west' => new Blob([0, 5, -3]), - ], [0.5, 0.5]); - - $this->tree = new KDTree(20, new Euclidean()); + $this->generator = new Agglomerate( + generators: [ + 'east' => new Blob(center: [5, -2, -2]), + 'west' => new Blob(center: [0, 5, -3]), + ], + weights: [0.5, 0.5] + ); + + $this->tree = new KDTree( + maxLeafSize: 20, + kernel: new Euclidean() + ); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertEquals(0, $this->tree->height()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KDTree::class, $this->tree); - $this->assertInstanceOf(Spatial::class, $this->tree); - $this->assertInstanceOf(BinaryTree::class, $this->tree); - $this->assertInstanceOf(Tree::class, $this->tree); - } - - /** - * @test - */ - public function growNeighborsRange() : void + public function testGrowNeighborsRange() : void { $this->tree->grow($this->generator->generate(self::DATASET_SIZE)); @@ -73,7 +55,7 @@ public function growNeighborsRange() : void $sample = $this->generator->generate(1)->sample(0); - [$samples, $labels, $distances] = $this->tree->nearest($sample, 5); + [$samples, $labels, $distances] = $this->tree->nearest(sample: $sample, k: 5); $this->assertCount(5, $samples); $this->assertCount(5, $labels); @@ -81,7 +63,7 @@ public function growNeighborsRange() : void $this->assertCount(1, array_unique($labels)); - [$samples, $labels, $distances] = $this->tree->range($sample, 5.0); + [$samples, $labels, $distances] = $this->tree->range(sample: $sample, radius: 5.0); $this->assertCount(50, $samples); $this->assertCount(50, $labels); @@ -90,13 +72,10 @@ public function growNeighborsRange() : void $this->assertCount(1, array_unique($labels)); } - /** - * @test - */ - public function growWithSameSamples() : void + public function testGrowWithSameSamples() : void { - $generator = new Agglomerate([ - 'east' => new Blob([5, -2, 10], 0.0), + $generator = new Agglomerate(generators: [ + 'east' => new Blob(center: [5, -2, 10], stdDev: 0.0), ]); $dataset = $generator->generate(self::DATASET_SIZE); diff --git a/tests/Graph/Trees/VantageTreeTest.php b/tests/Graph/Trees/VantageTreeTest.php index 06c1d75af..26f5c72d0 100644 --- a/tests/Graph/Trees/VantageTreeTest.php +++ b/tests/Graph/Trees/VantageTreeTest.php @@ -1,71 +1,50 @@ generator = new Agglomerate([ - 'east' => new Blob([5, -2, -2]), - 'west' => new Blob([0, 5, -3]), - ], [0.5, 0.5]); + $this->generator = new Agglomerate( + generators: [ + 'east' => new Blob(center: [5, -2, -2]), + 'west' => new Blob(center: [0, 5, -3]), + ], + weights: [0.5, 0.5] + ); - $this->tree = new VantageTree(20, new Euclidean()); + $this->tree = new VantageTree(maxLeafSize: 20, kernel: new Euclidean()); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertEquals(0, $this->tree->height()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(VantageTree::class, $this->tree); - $this->assertInstanceOf(Spatial::class, $this->tree); - $this->assertInstanceOf(BinaryTree::class, $this->tree); - $this->assertInstanceOf(Tree::class, $this->tree); - } - - /** - * @test - */ - public function growNeighborsRange() : void + public function testGrowNeighborsRange() : void { $this->tree->grow($this->generator->generate(self::DATASET_SIZE)); @@ -73,7 +52,7 @@ public function growNeighborsRange() : void $sample = $this->generator->generate(1)->sample(0); - [$samples, $labels, $distances] = $this->tree->nearest($sample, 5); + [$samples, $labels, $distances] = $this->tree->nearest(sample: $sample, k: 5); $this->assertCount(5, $samples); $this->assertCount(5, $labels); @@ -81,7 +60,7 @@ public function growNeighborsRange() : void $this->assertCount(1, array_unique($labels)); - [$samples, $labels, $distances] = $this->tree->range($sample, 4.3); + [$samples, $labels, $distances] = $this->tree->range(sample: $sample, radius: 4.3); $this->assertCount(50, $samples); $this->assertCount(50, $labels); @@ -90,13 +69,10 @@ public function growNeighborsRange() : void $this->assertCount(1, array_unique($labels)); } - /** - * @test - */ - public function growWithSameSamples() : void + public function testGrowWithSameSamples() : void { - $generator = new Agglomerate([ - 'east' => new Blob([5, -2, 10], 0.0), + $generator = new Agglomerate(generators: [ + 'east' => new Blob(center: [5, -2, 10], stdDev: 0.0), ]); $dataset = $generator->generate(self::DATASET_SIZE); diff --git a/tests/Helpers/CPUTest.php b/tests/Helpers/CPUTest.php index 80f261886..c8b828d0d 100644 --- a/tests/Helpers/CPUTest.php +++ b/tests/Helpers/CPUTest.php @@ -1,20 +1,19 @@ 'nice', 'texture' => 'furry', 'sociability' => 'friendly', 'rating' => 4, 'class' => 'not monster', @@ -26,25 +25,19 @@ public function decode() : void $this->assertSame($expected, $actual); } - /** - * @test - */ - public function encode() : void + public function testEncode() : void { - $actual = JSON::encode(['package' => 'rubix/ml']); + $actual = JSON::encode(value: ['package' => 'rubix/ml']); $expected = '{"package":"rubix\/ml"}'; $this->assertSame($expected, $actual); } - /** - * @test - */ - public function decodeBadData() : void + public function testDecodeBadData() : void { $this->expectException(RuntimeException::class); - JSON::decode('[{"package":...}]'); + JSON::decode(data: '[{"package":...}]'); } } diff --git a/tests/Helpers/ParamsTest.php b/tests/Helpers/ParamsTest.php index fac97d7e6..782d0684d 100644 --- a/tests/Helpers/ParamsTest.php +++ b/tests/Helpers/ParamsTest.php @@ -1,34 +1,64 @@ 0.1, + 'alpha' => 1e-4, + 'priors' => null, + ], + ', ', + 'learning_rate: 0.1, alpha: 0.0001, priors: null', + ]; + + yield [ + [ + new KNearestNeighbors(5), + 1.0, + 0.8, + ], + ', ', + '0: K Nearest Neighbors (k: 5, weighted: false, kernel: Euclidean), 1: 1, 2: 0.8', + ]; + + yield [ + [ + 1, + [2, 3, 4], + 5, + ], + ' - ', + '0: 1 - 1: [0: 2, 1: 3, 2: 4] - 2: 5', + ]; + } + protected function setUp() : void { ini_set('precision', '14'); } - /** - * @test - */ - public function ints() : void + public function testInts() : void { - $values = Params::ints(0, 100, 5); + $values = Params::ints(min: 0, max: 100, n: 5); - $this->assertContainsOnly('int', $values); + $this->assertContainsOnlyInt($values); $this->assertEquals(array_unique($values), $values); @@ -40,14 +70,11 @@ public function ints() : void } } - /** - * @test - */ - public function floats() : void + public function testFloats() : void { - $values = Params::floats(0.0, 100.0, 5); + $values = Params::floats(min: 0.0, max: 100.0, n: 5); - $this->assertContainsOnly('float', $values); + $this->assertContainsOnlyFloat($values); foreach ($values as $value) { $this->assertThat( @@ -57,69 +84,25 @@ public function floats() : void } } - /** - * @test - */ - public function grid() : void + public function testGrid() : void { - $values = Params::grid(0, 100, 5); + $values = Params::grid(min: 0, max: 100, n: 5); $this->assertEquals(range(0, 100, 25), $values); } /** - * @test - * @dataProvider stringifyProvider - * - * @param mixed[] $params + * @param array $params * @param string $separator * @param string $expected */ + #[DataProvider('stringifyProvider')] public function stringify(array $params, string $separator, string $expected) : void { - $this->assertEquals($expected, Params::stringify($params, $separator)); - } - - /** - * @return \Generator - */ - public function stringifyProvider() : Generator - { - yield [ - [ - 'learning_rate' => 0.1, - 'alpha' => 1e-4, - 'priors' => null, - ], - ', ', - 'learning_rate: 0.1, alpha: 0.0001, priors: null', - ]; - - yield [ - [ - new KNearestNeighbors(5), - 1.0, - 0.8, - ], - ', ', - '0: K Nearest Neighbors (k: 5, weighted: false, kernel: Euclidean), 1: 1, 2: 0.8', - ]; - - yield [ - [ - 1, - [2, 3, 4], - 5, - ], - ' - ', - '0: 1 - 1: [0: 2, 1: 3, 2: 4] - 2: 5', - ]; + $this->assertEquals($expected, Params::stringify(params: $params, separator: $separator)); } - /** - * @test - */ - public function shortName() : void + public function testSortName() : void { $this->assertEquals('KNearestNeighbors', Params::shortName(KNearestNeighbors::class)); } diff --git a/tests/Helpers/StatsTest.php b/tests/Helpers/StatsTest.php index b42d634f8..275fa26bd 100644 --- a/tests/Helpers/StatsTest.php +++ b/tests/Helpers/StatsTest.php @@ -1,173 +1,135 @@ assertSame($expected, Stats::mean($values)); - } - - /** - * @return \Generator - */ - public function meanProvider() : Generator + public static function meanProvider() : Generator { yield [self::TEST_VALUES, 8.75]; yield [[5.0], 5.0]; } - /** - * @test - * @dataProvider weightedMeanProvider - * - * @param (int|float)[] $values - * @param (int|float)[] $weights - * @param float $expected - */ - public function weightedMean(array $values, array $weights, float $expected) : void - { - $this->assertSame($expected, Stats::weightedMean($values, $weights)); - } - - /** - * @return \Generator - */ - public function weightedMeanProvider() : Generator + public static function weightedMeanProvider() : Generator { yield [self::TEST_VALUES, [3, 2, 5, 1, 2, 4, 4, 2, 3, 5], 9.225806451612904]; yield [self::TEST_VALUES, array_fill(0, count(self::TEST_VALUES), 1), 8.75]; } - /** - * @test - */ - public function variance() : void + public static function quantileProvider() : Generator { - $this->assertSame(21.1125, Stats::variance(self::TEST_VALUES)); + yield [self::TEST_VALUES, 0.5, 9.75]; + + yield [self::TEST_VALUES, 0.99, 14.82]; + + yield [[5.0], 0.5, 5.0]; } - /** - * @test - */ - public function median() : void + public static function centralMomentProvider() : Generator { - $this->assertSame(9.75, Stats::median(self::TEST_VALUES)); + yield [self::TEST_VALUES, 1, 0.0]; + + yield [self::TEST_VALUES, 2, 21.1125]; + + yield [self::TEST_VALUES, 3, -30.9375]; + + yield [self::TEST_VALUES, 4, 747.26015625]; } /** - * @test - * @dataProvider quantileProvider - * * @param (int|float)[] $values - * @param float $q * @param float $expected */ - public function quantile(array $values, float $q, float $expected) : void + #[DataProvider('meanProvider')] + public function testMean(array $values, float $expected) : void { - $this->assertSame($expected, Stats::quantile($values, $q)); + $this->assertSame($expected, Stats::mean(values: $values)); } /** - * @return \Generator + * @param (int|float)[] $values + * @param (int|float)[] $weights + * @param float $expected */ - public function quantileProvider() : Generator + #[DataProvider('weightedMeanProvider')] + public function testWeightedMean(array $values, array $weights, float $expected) : void { - yield [self::TEST_VALUES, 0.5, 9.75]; - - yield [self::TEST_VALUES, 0.99, 14.82]; - - yield [[5.0], 0.5, 5.0]; + $this->assertSame($expected, Stats::weightedMean(values: $values, weights: $weights)); } - /** - * @test - */ - public function mad() : void + public function testVariance() : void { - $this->assertEquals(3.5, Stats::mad(self::TEST_VALUES)); + $this->assertSame(21.1125, Stats::variance(values: self::TEST_VALUES)); } - /** - * @test - */ - public function skewness() : void + public function testMedian() : void { - $this->assertEquals(-0.31891556974589724, Stats::skewness(self::TEST_VALUES)); + $this->assertSame(9.75, Stats::median(values: self::TEST_VALUES)); } /** - * @test - * @dataProvider centralMomentProvider - * * @param (int|float)[] $values - * @param int $moment + * @param float $q * @param float $expected */ - public function centralMoment(array $values, int $moment, float $expected) : void + #[DataProvider('quantileProvider')] + public function testQuantile(array $values, float $q, float $expected) : void { - $this->assertEquals($expected, Stats::centralMoment($values, $moment)); + $this->assertSame($expected, Stats::quantile(values: $values, q: $q)); } - /** - * @return \Generator - */ - public function centralMomentProvider() : Generator + public function testMad() : void { - yield [self::TEST_VALUES, 1, 0.0]; - - yield [self::TEST_VALUES, 2, 21.1125]; - - yield [self::TEST_VALUES, 3, -30.9375]; + $this->assertEquals(3.5, Stats::mad(values: self::TEST_VALUES)); + } - yield [self::TEST_VALUES, 4, 747.26015625]; + public function testSkewness() : void + { + $this->assertEquals(-0.31891556974589724, Stats::skewness(values: self::TEST_VALUES)); } /** - * @test + * @param (int|float)[] $values + * @param int $moment + * @param float $expected */ - public function kurtosis() : void + #[DataProvider('centralMomentProvider')] + public function testCentralMoment(array $values, int $moment, float $expected) : void { - $this->assertEquals(-1.3235426808299866, Stats::kurtosis(self::TEST_VALUES)); + $this->assertEquals($expected, Stats::centralMoment(values: $values, moment: $moment)); } - /** - * @test - */ - public function meanVar() : void + public function testKurtosis() : void + { + $this->assertEquals(-1.3235426808299866, Stats::kurtosis(values: self::TEST_VALUES)); + } + + public function testMeanVar() : void { - [$mean, $variance] = Stats::meanVar(self::TEST_VALUES); + [$mean, $variance] = Stats::meanVar(values: self::TEST_VALUES); $this->assertEquals(8.75, $mean); $this->assertEquals(21.1125, $variance); } - /** - * @test - */ - public function medMad() : void + public function testMedMad() : void { - [$median, $mad] = Stats::medianMad(self::TEST_VALUES); + [$median, $mad] = Stats::medianMad(values: self::TEST_VALUES); $this->assertEquals(9.75, $median); $this->assertEquals(3.5, $mad); diff --git a/tests/Kernels/Distance/CanberraTest.php b/tests/Kernels/Distance/CanberraTest.php index abc0f2b25..36acdd6ff 100644 --- a/tests/Kernels/Distance/CanberraTest.php +++ b/tests/Kernels/Distance/CanberraTest.php @@ -1,60 +1,26 @@ kernel = new Canberra(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Canberra::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); - - $this->assertGreaterThanOrEqual(0.0, $distance); - $this->assertEquals($expected, $distance); - } + protected Canberra $kernel; /** - * @return \Generator + * @return Generator|list>> */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -71,4 +37,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Canberra(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0.0, $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/CosineTest.php b/tests/Kernels/Distance/CosineTest.php index 6f7cc220b..2bc0f4c1f 100644 --- a/tests/Kernels/Distance/CosineTest.php +++ b/tests/Kernels/Distance/CosineTest.php @@ -1,60 +1,23 @@ kernel = new Cosine(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Cosine::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); + protected Cosine $kernel; - $this->assertGreaterThanOrEqual(0.0, $distance); - $this->assertEqualsWithDelta($expected, $distance, 1e-8); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -86,4 +49,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Cosine(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0.0, $distance); + $this->assertEqualsWithDelta($expected, $distance, 1e-8); + } } diff --git a/tests/Kernels/Distance/DiagonalTest.php b/tests/Kernels/Distance/DiagonalTest.php index 9e9e8a248..965bdb75c 100644 --- a/tests/Kernels/Distance/DiagonalTest.php +++ b/tests/Kernels/Distance/DiagonalTest.php @@ -1,60 +1,26 @@ kernel = new Diagonal(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Diagonal::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); - - $this->assertGreaterThanOrEqual(0., $distance); - $this->assertEquals($expected, $distance); - } + protected Diagonal $kernel; /** - * @return \Generator + * @return Generator|list>> */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -71,4 +37,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Diagonal(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0., $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/EuclideanTest.php b/tests/Kernels/Distance/EuclideanTest.php index f383bcb10..882af0d3c 100644 --- a/tests/Kernels/Distance/EuclideanTest.php +++ b/tests/Kernels/Distance/EuclideanTest.php @@ -1,60 +1,26 @@ kernel = new Euclidean(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Euclidean::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); - - $this->assertGreaterThanOrEqual(0., $distance); - $this->assertEquals($expected, $distance); - } + protected Euclidean $kernel; /** - * @return \Generator + * @return Generator|list>> */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -71,4 +37,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Euclidean(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0., $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/GowerTest.php b/tests/Kernels/Distance/GowerTest.php index 788c6fdf7..b3cf47aea 100644 --- a/tests/Kernels/Distance/GowerTest.php +++ b/tests/Kernels/Distance/GowerTest.php @@ -1,67 +1,47 @@ kernel = new Gower(1.0); + yield [['toast', 1.0, 0.5, NAN], ['pretzels', 1.0, 0.2, 0.1], 0.43333333333333335]; + + yield [[0.0, 1.0, 0.5, 'ham'], [0.1, 0.9, 0.4, 'ham'], 0.07499999999999998]; + + yield [[1, NAN, 1], [1, NAN, 1], 0.0]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(Gower::class, $this->kernel); - $this->assertInstanceOf(NaNSafe::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); + $this->kernel = new Gower(1.0); } /** - * @test - * @dataProvider computeProvider - * * @param list $a * @param list $b * @param float $expected */ - public function compute(array $a, array $b, $expected) : void + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void { - $distance = $this->kernel->compute($a, $b); + $distance = $this->kernel->compute(a: $a, b: $b); $this->assertGreaterThanOrEqual(0.0, $distance); $this->assertEquals($expected, $distance); } - - /** - * @return \Generator> - */ - public function computeProvider() : Generator - { - yield [['toast', 1.0, 0.5, NAN], ['pretzels', 1.0, 0.2, 0.1], 0.43333333333333335]; - - yield [[0.0, 1.0, 0.5, 'ham'], [0.1, 0.9, 0.4, 'ham'], 0.07499999999999998]; - - yield [[1, NAN, 1], [1, NAN, 1], 0.0]; - } } diff --git a/tests/Kernels/Distance/HammingTest.php b/tests/Kernels/Distance/HammingTest.php index 862887540..c3d6de33f 100644 --- a/tests/Kernels/Distance/HammingTest.php +++ b/tests/Kernels/Distance/HammingTest.php @@ -1,60 +1,23 @@ kernel = new Hamming(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Hamming::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param string[] $a - * @param string[] $b - * @param float $expected - */ - public function compute(array $a, array $b, $expected) : void - { - $distance = $this->kernel->compute($a, $b); + protected Hamming $kernel; - $this->assertGreaterThanOrEqual(0., $distance); - $this->assertEquals($expected, $distance); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ ['soup', 'turkey', 'broccoli', 'cake'], ['salad', 'turkey', 'broccoli', 'pie'], @@ -71,4 +34,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Hamming(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0., $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/JaccardTest.php b/tests/Kernels/Distance/JaccardTest.php index 2e4d467ff..6a44e5bf3 100644 --- a/tests/Kernels/Distance/JaccardTest.php +++ b/tests/Kernels/Distance/JaccardTest.php @@ -1,60 +1,23 @@ kernel = new Jaccard(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Jaccard::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); + protected Jaccard $kernel; - $this->assertGreaterThanOrEqual(0., $distance); - $this->assertEquals($expected, $distance); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -71,4 +34,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Jaccard(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0., $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/ManhattanTest.php b/tests/Kernels/Distance/ManhattanTest.php index a80825879..af7be7110 100644 --- a/tests/Kernels/Distance/ManhattanTest.php +++ b/tests/Kernels/Distance/ManhattanTest.php @@ -1,60 +1,23 @@ kernel = new Manhattan(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Manhattan::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); + protected Manhattan $kernel; - $this->assertGreaterThanOrEqual(0., $distance); - $this->assertEquals($expected, $distance); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -71,4 +34,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Manhattan(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0., $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/MinkowskiTest.php b/tests/Kernels/Distance/MinkowskiTest.php index 4ea10e7cf..1e6e75f0a 100644 --- a/tests/Kernels/Distance/MinkowskiTest.php +++ b/tests/Kernels/Distance/MinkowskiTest.php @@ -1,60 +1,23 @@ kernel = new Minkowski(3.0); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Minkowski::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); + protected Minkowski $kernel; - $this->assertGreaterThanOrEqual(0., $distance); - $this->assertEquals($expected, $distance); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -71,4 +34,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new Minkowski(3.0); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0., $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/SafeEuclideanTest.php b/tests/Kernels/Distance/SafeEuclideanTest.php index 7faf80a1c..55602bb99 100644 --- a/tests/Kernels/Distance/SafeEuclideanTest.php +++ b/tests/Kernels/Distance/SafeEuclideanTest.php @@ -1,62 +1,23 @@ kernel = new SafeEuclidean(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SafeEuclidean::class, $this->kernel); - $this->assertInstanceOf(NaNSafe::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); + protected SafeEuclidean $kernel; - $this->assertGreaterThanOrEqual(0., $distance); - $this->assertEquals($expected, $distance); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, NAN], [-2, 1, 8, -2], @@ -73,4 +34,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new SafeEuclidean(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0., $distance); + $this->assertEquals($expected, $distance); + } } diff --git a/tests/Kernels/Distance/SparseCosineTest.php b/tests/Kernels/Distance/SparseCosineTest.php index e4dda36b9..03cc0e6c5 100644 --- a/tests/Kernels/Distance/SparseCosineTest.php +++ b/tests/Kernels/Distance/SparseCosineTest.php @@ -1,60 +1,23 @@ kernel = new SparseCosine(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SparseCosine::class, $this->kernel); - $this->assertInstanceOf(Distance::class, $this->kernel); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param (int|float)[] $a - * @param (int|float)[] $b - * @param float $expected - */ - public function compute(array $a, array $b, float $expected) : void - { - $distance = $this->kernel->compute($a, $b); + protected SparseCosine $kernel; - $this->assertGreaterThanOrEqual(0.0, $distance); - $this->assertEqualsWithDelta($expected, $distance, 1e-8); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ [2, 1, 4, 0], [-2, 1, 8, -2], @@ -86,4 +49,23 @@ public function computeProvider() : Generator 0.0, ]; } + + protected function setUp() : void + { + $this->kernel = new SparseCosine(); + } + + /** + * @param list $a + * @param list $b + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(array $a, array $b, float $expected) : void + { + $distance = $this->kernel->compute(a: $a, b: $b); + + $this->assertGreaterThanOrEqual(0.0, $distance); + $this->assertEqualsWithDelta($expected, $distance, 1e-8); + } } diff --git a/tests/Kernels/SVM/LinearTest.php b/tests/Kernels/SVM/LinearTest.php index 4893b07e5..3d1b21a14 100644 --- a/tests/Kernels/SVM/LinearTest.php +++ b/tests/Kernels/SVM/LinearTest.php @@ -1,44 +1,28 @@ kernel = new Linear(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Linear::class, $this->kernel); - $this->assertInstanceOf(Kernel::class, $this->kernel); - } - - /** - * @test - */ - public function options() : void + public function testOptions() : void { $expected = [102 => 0]; diff --git a/tests/Kernels/SVM/PolynomialTest.php b/tests/Kernels/SVM/PolynomialTest.php index b36bb48e7..d2edabae8 100644 --- a/tests/Kernels/SVM/PolynomialTest.php +++ b/tests/Kernels/SVM/PolynomialTest.php @@ -1,44 +1,28 @@ kernel = new Polynomial(3, 1e-3); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Polynomial::class, $this->kernel); - $this->assertInstanceOf(Kernel::class, $this->kernel); + $this->kernel = new Polynomial(degree: 3, gamma: 1e-3); } - /** - * @test - */ - public function options() : void + public function testOptions() : void { $expected = [ 102 => 1, diff --git a/tests/Kernels/SVM/RBFTest.php b/tests/Kernels/SVM/RBFTest.php index 631d05347..af04dddd1 100644 --- a/tests/Kernels/SVM/RBFTest.php +++ b/tests/Kernels/SVM/RBFTest.php @@ -1,44 +1,28 @@ kernel = new RBF(1e-3); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RBF::class, $this->kernel); - $this->assertInstanceOf(Kernel::class, $this->kernel); - } - - /** - * @test - */ - public function options() : void + public function testOptions() : void { $options = [ 102 => 2, diff --git a/tests/Kernels/SVM/SigmoidalTest.php b/tests/Kernels/SVM/SigmoidalTest.php index 17ed6f56c..68c1bf29a 100644 --- a/tests/Kernels/SVM/SigmoidalTest.php +++ b/tests/Kernels/SVM/SigmoidalTest.php @@ -1,44 +1,28 @@ kernel = new Sigmoidal(1e-3); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Sigmoidal::class, $this->kernel); - $this->assertInstanceOf(Kernel::class, $this->kernel); + $this->kernel = new Sigmoidal(gamma: 1e-3); } - /** - * @test - */ - public function options() : void + public function testOptions() : void { $options = [ 102 => 3, diff --git a/tests/Loggers/ScreenTest.php b/tests/Loggers/ScreenTest.php index fdc366445..81c61f236 100644 --- a/tests/Loggers/ScreenTest.php +++ b/tests/Loggers/ScreenTest.php @@ -1,46 +1,30 @@ logger = new Screen('default'); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Screen::class, $this->logger); - $this->assertInstanceOf(Logger::class, $this->logger); - $this->assertInstanceOf(LoggerInterface::class, $this->logger); + $this->logger = new Screen(channel: 'default'); } - /** - * @test - */ - public function log() : void + public function testLog() : void { $this->expectOutputRegex('/\b(default.INFO: test)\b/'); - $this->logger->log(LogLevel::INFO, 'test'); + $this->logger->log(level: LogLevel::INFO, message: 'test'); } } diff --git a/tests/NeuralNet/ActivationFunctions/ELUTest.php b/tests/NeuralNet/ActivationFunctions/ELUTest.php index a1d9f093e..b848701fa 100644 --- a/tests/NeuralNet/ActivationFunctions/ELUTest.php +++ b/tests/NeuralNet/ActivationFunctions/ELUTest.php @@ -1,70 +1,25 @@ activationFn = new ELU(1.0); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ELU::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } - - /** - * @test - */ - public function badAlpha() : void - { - $this->expectException(InvalidArgumentException::class); + protected ELU $activationFn; - new ELU(-346); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -89,25 +44,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -139,4 +76,41 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new ELU(1.0); + } + + public function testBadAlpha() : void + { + $this->expectException(InvalidArgumentException::class); + + new ELU(-346); + } + + /** + * @param Matrix $input + * @param list> $expected $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/ActivationFunctions/GELUTest.php b/tests/NeuralNet/ActivationFunctions/GELUTest.php index 2355d0fd9..ff492b695 100644 --- a/tests/NeuralNet/ActivationFunctions/GELUTest.php +++ b/tests/NeuralNet/ActivationFunctions/GELUTest.php @@ -1,59 +1,24 @@ activationFn = new GELU(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GELU::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } + protected GELU $activationFn; - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param array> $expected - */ - public function compute(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEqualsWithDelta($expected, $activations, 1e-8); - } - - /** - * @return \Generator> - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -76,25 +41,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param array> $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); - } - - /** - * @return \Generator> - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -108,4 +55,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new GELU(); + } + + /** + * @param Matrix $input + * @param array> $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEqualsWithDelta($expected, $activations, 1e-8); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param array> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(z: $input, computed: $activations)->asArray(); + + $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); + } } diff --git a/tests/NeuralNet/ActivationFunctions/HyperbolicTangentTest.php b/tests/NeuralNet/ActivationFunctions/HyperbolicTangentTest.php index c6af6d56a..7863771ab 100644 --- a/tests/NeuralNet/ActivationFunctions/HyperbolicTangentTest.php +++ b/tests/NeuralNet/ActivationFunctions/HyperbolicTangentTest.php @@ -1,59 +1,24 @@ activationFn = new HyperbolicTangent(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(HyperbolicTangent::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEqualsWithDelta($expected, $activations, 1e-8); - } + protected HyperbolicTangent $activationFn; - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new HyperbolicTangent(); + } + + /** + * @param Matrix $input + * @param list> $expected $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEqualsWithDelta($expected, $activations, 1e-8); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); + } } diff --git a/tests/NeuralNet/ActivationFunctions/LeakyReLUTest.php b/tests/NeuralNet/ActivationFunctions/LeakyReLUTest.php index 9a199dff8..84289a671 100644 --- a/tests/NeuralNet/ActivationFunctions/LeakyReLUTest.php +++ b/tests/NeuralNet/ActivationFunctions/LeakyReLUTest.php @@ -1,59 +1,24 @@ activationFn = new LeakyReLU(0.01); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LeakyReLU::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } + protected LeakyReLU $activationFn; - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new LeakyReLU(0.01); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function differentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/ActivationFunctions/ReLUTest.php b/tests/NeuralNet/ActivationFunctions/ReLUTest.php index 44a8b86c9..a8b84d334 100644 --- a/tests/NeuralNet/ActivationFunctions/ReLUTest.php +++ b/tests/NeuralNet/ActivationFunctions/ReLUTest.php @@ -1,59 +1,24 @@ activationFn = new ReLU(); - } + protected ReLU $activationFn; - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ReLU::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new ReLU(); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/ActivationFunctions/SELUTest.php b/tests/NeuralNet/ActivationFunctions/SELUTest.php index 149501dbd..ebe7c94a1 100644 --- a/tests/NeuralNet/ActivationFunctions/SELUTest.php +++ b/tests/NeuralNet/ActivationFunctions/SELUTest.php @@ -1,59 +1,24 @@ activationFn = new SELU(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SELU::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new SELU(); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected $expected + */ + #[DataProvider('differentiateProvider')] + public function differentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/ActivationFunctions/SiLUTest.php b/tests/NeuralNet/ActivationFunctions/SiLUTest.php index db30007fd..172791e33 100644 --- a/tests/NeuralNet/ActivationFunctions/SiLUTest.php +++ b/tests/NeuralNet/ActivationFunctions/SiLUTest.php @@ -1,59 +1,24 @@ activationFn = new SiLU(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SiLU::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } + protected SiLU $activationFn; - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function compute(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEqualsWithDelta($expected, $activations, 1e-8); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new SiLU(); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEqualsWithDelta($expected, $activations, 1e-8); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); + } } diff --git a/tests/NeuralNet/ActivationFunctions/SigmoidTest.php b/tests/NeuralNet/ActivationFunctions/SigmoidTest.php index a8694ede9..3cdb6703a 100644 --- a/tests/NeuralNet/ActivationFunctions/SigmoidTest.php +++ b/tests/NeuralNet/ActivationFunctions/SigmoidTest.php @@ -1,59 +1,24 @@ activationFn = new Sigmoid(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Sigmoid::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } + protected Sigmoid $activationFn; - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new Sigmoid(); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/ActivationFunctions/SoftPlusTest.php b/tests/NeuralNet/ActivationFunctions/SoftPlusTest.php index 6389248af..8255f94ca 100644 --- a/tests/NeuralNet/ActivationFunctions/SoftPlusTest.php +++ b/tests/NeuralNet/ActivationFunctions/SoftPlusTest.php @@ -1,59 +1,24 @@ activationFn = new SoftPlus(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SoftPlus::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } + protected SoftPlus $activationFn; - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new SoftPlus(); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/ActivationFunctions/SoftmaxTest.php b/tests/NeuralNet/ActivationFunctions/SoftmaxTest.php index 0859efea9..83dbeb9e7 100644 --- a/tests/NeuralNet/ActivationFunctions/SoftmaxTest.php +++ b/tests/NeuralNet/ActivationFunctions/SoftmaxTest.php @@ -1,59 +1,24 @@ activationFn = new Softmax(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Softmax::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } + protected Softmax $activationFn; - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEqualsWithDelta($expected, $activations, 1e-8); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -82,25 +47,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -140,4 +87,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new Softmax(); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEqualsWithDelta($expected, $activations, 1e-8); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEqualsWithDelta($expected, $derivatives, 1e-8); + } } diff --git a/tests/NeuralNet/ActivationFunctions/SoftsignTest.php b/tests/NeuralNet/ActivationFunctions/SoftsignTest.php index e4f69ea48..9ffc9f01a 100644 --- a/tests/NeuralNet/ActivationFunctions/SoftsignTest.php +++ b/tests/NeuralNet/ActivationFunctions/SoftsignTest.php @@ -1,59 +1,24 @@ activationFn = new Softsign(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Softsign::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } + protected Softsign $activationFn; - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new Softsign(); + } + + /** + * @param Matrix $input + * @param list> $expected $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/ActivationFunctions/ThresholdedReLUTest.php b/tests/NeuralNet/ActivationFunctions/ThresholdedReLUTest.php index 05dfd7baf..a17be3151 100644 --- a/tests/NeuralNet/ActivationFunctions/ThresholdedReLUTest.php +++ b/tests/NeuralNet/ActivationFunctions/ThresholdedReLUTest.php @@ -1,59 +1,24 @@ activationFn = new ThresholdedReLU(0.1); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ThresholdedReLU::class, $this->activationFn); - $this->assertInstanceOf(ActivationFunction::class, $this->activationFn); - } + protected ThresholdedReLU $activationFn; - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $input - * @param list> $expected $expected - */ - public function activate(Matrix $input, array $expected) : void - { - $activations = $this->activationFn->activate($input)->asArray(); - - $this->assertEquals($expected, $activations); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -78,25 +43,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $input - * @param Matrix $activations - * @param list> $expected $expected - */ - public function differentiate(Matrix $input, Matrix $activations, array $expected) : void - { - $derivatives = $this->activationFn->differentiate($input, $activations)->asArray(); - - $this->assertEquals($expected, $derivatives); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -128,4 +75,34 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->activationFn = new ThresholdedReLU(0.1); + } + + /** + * @param Matrix $input + * @param list> $expected + */ + #[DataProvider('computeProvider')] + public function testActivate(Matrix $input, array $expected) : void + { + $activations = $this->activationFn->activate($input)->asArray(); + + $this->assertEquals($expected, $activations); + } + + /** + * @param Matrix $input + * @param Matrix $activations + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $input, Matrix $activations, array $expected) : void + { + $derivatives = $this->activationFn->differentiate(input: $input, output: $activations)->asArray(); + + $this->assertEquals($expected, $derivatives); + } } diff --git a/tests/NeuralNet/CostFunctions/CrossEntropyTest.php b/tests/NeuralNet/CostFunctions/CrossEntropyTest.php index ffc5b630d..0182ee0d8 100644 --- a/tests/NeuralNet/CostFunctions/CrossEntropyTest.php +++ b/tests/NeuralNet/CostFunctions/CrossEntropyTest.php @@ -1,60 +1,24 @@ costFn = new CrossEntropy(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(CrossEntropy::class, $this->costFn); - $this->assertInstanceOf(CostFunction::class, $this->costFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $output - * @param Matrix $target - * @param float $expected - */ - public function compute(Matrix $output, Matrix $target, float $expected) : void - { - $loss = $this->costFn->compute($output, $target); - - $this->assertEqualsWithDelta($expected, $loss, 1e-8); - } + protected CrossEntropy $costFn; - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -101,25 +65,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $output - * @param Matrix $target - * @param list> $expected - */ - public function differentiate(Matrix $output, Matrix $target, array $expected) : void - { - $gradient = $this->costFn->differentiate($output, $target)->asArray(); - - $this->assertEqualsWithDelta($expected, $gradient, 1e-8); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -175,4 +121,35 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->costFn = new CrossEntropy(); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(Matrix $output, Matrix $target, float $expected) : void + { + $loss = $this->costFn->compute(output: $output, target: $target); + + $this->assertEqualsWithDelta($expected, $loss, 1e-8); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $output, Matrix $target, array $expected) : void + { + $gradient = $this->costFn->differentiate(output: $output, target: $target)->asArray(); + + $this->assertEqualsWithDelta($expected, $gradient, 1e-8); + } } diff --git a/tests/NeuralNet/CostFunctions/HuberLossTest.php b/tests/NeuralNet/CostFunctions/HuberLossTest.php index 104f873eb..13471ad05 100644 --- a/tests/NeuralNet/CostFunctions/HuberLossTest.php +++ b/tests/NeuralNet/CostFunctions/HuberLossTest.php @@ -1,60 +1,24 @@ costFn = new HuberLoss(1.0); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(HuberLoss::class, $this->costFn); - $this->assertInstanceOf(CostFunction::class, $this->costFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $output - * @param Matrix $target - * @param float $expected - */ - public function compute(Matrix $output, Matrix $target, float $expected) : void - { - $loss = $this->costFn->compute($output, $target); - - $this->assertEqualsWithDelta($expected, $loss, 1e-8); - } - - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -95,25 +59,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $output - * @param Matrix $target - * @param list> $expected - */ - public function differentiate(Matrix $output, Matrix $target, array $expected) : void - { - $gradient = $this->costFn->differentiate($output, $target)->asArray(); - - $this->assertEqualsWithDelta($expected, $gradient, 1e-8); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -163,4 +109,35 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->costFn = new HuberLoss(1.0); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(Matrix $output, Matrix $target, float $expected) : void + { + $loss = $this->costFn->compute(output: $output, target: $target); + + $this->assertEqualsWithDelta($expected, $loss, 1e-8); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $output, Matrix $target, array $expected) : void + { + $gradient = $this->costFn->differentiate($output, $target)->asArray(); + + $this->assertEqualsWithDelta($expected, $gradient, 1e-8); + } } diff --git a/tests/NeuralNet/CostFunctions/LeastSquaresTest.php b/tests/NeuralNet/CostFunctions/LeastSquaresTest.php index 3e7a2c3c5..2c2d54a5e 100644 --- a/tests/NeuralNet/CostFunctions/LeastSquaresTest.php +++ b/tests/NeuralNet/CostFunctions/LeastSquaresTest.php @@ -1,60 +1,24 @@ costFn = new LeastSquares(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LeastSquares::class, $this->costFn); - $this->assertInstanceOf(CostFunction::class, $this->costFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $output - * @param Matrix $target - * @param float $expected - */ - public function compute(Matrix $output, Matrix $target, float $expected) : void - { - $loss = $this->costFn->compute($output, $target); - - $this->assertEquals($expected, $loss); - } + protected LeastSquares $costFn; - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -95,25 +59,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $output - * @param Matrix $target - * @param list> $expected - */ - public function differentiate(Matrix $output, Matrix $target, array $expected) : void - { - $gradient = $this->costFn->differentiate($output, $target)->asArray(); - - $this->assertEquals($expected, $gradient); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -163,4 +109,35 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->costFn = new LeastSquares(); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(Matrix $output, Matrix $target, float $expected) : void + { + $loss = $this->costFn->compute(output: $output, target: $target); + + $this->assertEquals($expected, $loss); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $output, Matrix $target, array $expected) : void + { + $gradient = $this->costFn->differentiate(output: $output, target: $target)->asArray(); + + $this->assertEquals($expected, $gradient); + } } diff --git a/tests/NeuralNet/CostFunctions/RelativeEntropyTest.php b/tests/NeuralNet/CostFunctions/RelativeEntropyTest.php index a010ea2ae..d740e9d42 100644 --- a/tests/NeuralNet/CostFunctions/RelativeEntropyTest.php +++ b/tests/NeuralNet/CostFunctions/RelativeEntropyTest.php @@ -1,60 +1,24 @@ costFn = new RelativeEntropy(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RelativeEntropy::class, $this->costFn); - $this->assertInstanceOf(CostFunction::class, $this->costFn); - } - - /** - * @test - * @dataProvider computeProvider - * - * @param Matrix $output - * @param Matrix $target - * @param float $expected - */ - public function compute(Matrix $output, Matrix $target, float $expected) : void - { - $loss = $this->costFn->compute($output, $target); - - $this->assertEqualsWithDelta($expected, $loss, 1e-8); - } + protected RelativeEntropy $costFn; - /** - * @return \Generator - */ - public function computeProvider() : Generator + public static function computeProvider() : Generator { yield [ Matrix::quick([ @@ -101,25 +65,7 @@ public function computeProvider() : Generator ]; } - /** - * @test - * @dataProvider differentiateProvider - * - * @param Matrix $output - * @param Matrix $target - * @param list> $expected - */ - public function differentiate(Matrix $output, Matrix $target, array $expected) : void - { - $gradient = $this->costFn->differentiate($output, $target)->asArray(); - - $this->assertEqualsWithDelta($expected, $gradient, 1e-8); - } - - /** - * @return \Generator - */ - public function differentiateProvider() : Generator + public static function differentiateProvider() : Generator { yield [ Matrix::quick([ @@ -175,4 +121,35 @@ public function differentiateProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->costFn = new RelativeEntropy(); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param float $expected + */ + #[DataProvider('computeProvider')] + public function testCompute(Matrix $output, Matrix $target, float $expected) : void + { + $loss = $this->costFn->compute(output: $output, target: $target); + + $this->assertEqualsWithDelta($expected, $loss, 1e-8); + } + + /** + * @param Matrix $output + * @param Matrix $target + * @param list> $expected + */ + #[DataProvider('differentiateProvider')] + public function testDifferentiate(Matrix $output, Matrix $target, array $expected) : void + { + $gradient = $this->costFn->differentiate(output: $output, target: $target)->asArray(); + + $this->assertEqualsWithDelta($expected, $gradient, 1e-8); + } } diff --git a/tests/NeuralNet/Initializers/ConstantTest.php b/tests/NeuralNet/Initializers/ConstantTest.php index 31082f7a1..ab01ad95d 100644 --- a/tests/NeuralNet/Initializers/ConstantTest.php +++ b/tests/NeuralNet/Initializers/ConstantTest.php @@ -1,46 +1,28 @@ initializer = new Constant(4.8); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Constant::class, $this->initializer); - $this->assertInstanceOf(Initializer::class, $this->initializer); - } - - /** - * @test - */ - public function initialize() : void + public function testInitialize() : void { - $w = $this->initializer->initialize(4, 3); + $w = $this->initializer->initialize(fanIn: 4, fanOut: 3); $expected = [ [4.8, 4.8, 4.8, 4.8], @@ -48,8 +30,7 @@ public function initialize() : void [4.8, 4.8, 4.8, 4.8], ]; - $this->assertInstanceOf(Matrix::class, $w); - $this->assertEquals([3, 4], $w->shape()); - $this->assertEquals($expected, $w->asArray()); + $this->assertSame([3, 4], $w->shape()); + $this->assertSame($expected, $w->asArray()); } } diff --git a/tests/NeuralNet/Initializers/HeTest.php b/tests/NeuralNet/Initializers/HeTest.php index ffbd3a06b..693b97805 100644 --- a/tests/NeuralNet/Initializers/HeTest.php +++ b/tests/NeuralNet/Initializers/HeTest.php @@ -1,48 +1,29 @@ initializer = new He(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(He::class, $this->initializer); - $this->assertInstanceOf(Initializer::class, $this->initializer); - } - - /** - * @test - */ - public function initialize() : void + public function testInitialize() : void { - $w = $this->initializer->initialize(4, 3); + $w = $this->initializer->initialize(fanIn: 4, fanOut: 3); - $this->assertInstanceOf(Matrix::class, $w); - $this->assertEquals([3, 4], $w->shape()); + $this->assertSame([3, 4], $w->shape()); } } diff --git a/tests/NeuralNet/Initializers/LeCunTest.php b/tests/NeuralNet/Initializers/LeCunTest.php index 5a7b50ab5..21d978386 100644 --- a/tests/NeuralNet/Initializers/LeCunTest.php +++ b/tests/NeuralNet/Initializers/LeCunTest.php @@ -1,48 +1,29 @@ initializer = new LeCun(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LeCun::class, $this->initializer); - $this->assertInstanceOf(Initializer::class, $this->initializer); - } - - /** - * @test - */ - public function initialize() : void + public function testInitialize() : void { - $w = $this->initializer->initialize(4, 3); + $w = $this->initializer->initialize(fanIn: 4, fanOut: 3); - $this->assertInstanceOf(Matrix::class, $w); - $this->assertEquals([3, 4], $w->shape()); + $this->assertSame([3, 4], $w->shape()); } } diff --git a/tests/NeuralNet/Initializers/NormalTest.php b/tests/NeuralNet/Initializers/NormalTest.php index 60f20237c..fc168d255 100644 --- a/tests/NeuralNet/Initializers/NormalTest.php +++ b/tests/NeuralNet/Initializers/NormalTest.php @@ -1,26 +1,20 @@ initializer = new Normal(0.05); @@ -29,20 +23,10 @@ protected function setUp() : void /** * @test */ - public function build() : void - { - $this->assertInstanceOf(Normal::class, $this->initializer); - $this->assertInstanceOf(Initializer::class, $this->initializer); - } - - /** - * @test - */ - public function initialize() : void + public function testInitialize() : void { - $w = $this->initializer->initialize(4, 3); + $w = $this->initializer->initialize(fanIn: 4, fanOut: 3); - $this->assertInstanceOf(Matrix::class, $w); - $this->assertEquals([3, 4], $w->shape()); + $this->assertSame([3, 4], $w->shape()); } } diff --git a/tests/NeuralNet/Initializers/UniformTest.php b/tests/NeuralNet/Initializers/UniformTest.php index f28ce1a58..b02db65d5 100644 --- a/tests/NeuralNet/Initializers/UniformTest.php +++ b/tests/NeuralNet/Initializers/UniformTest.php @@ -1,48 +1,29 @@ initializer = new Uniform(0.05); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Uniform::class, $this->initializer); - $this->assertInstanceOf(Initializer::class, $this->initializer); - } - - /** - * @test - */ - public function initialize() : void + public function testInitialize() : void { - $w = $this->initializer->initialize(4, 3); + $w = $this->initializer->initialize(fanIn: 4, fanOut: 3); - $this->assertInstanceOf(Matrix::class, $w); - $this->assertEquals([3, 4], $w->shape()); + $this->assertSame([3, 4], $w->shape()); } } diff --git a/tests/NeuralNet/Initializers/Xavier1Test.php b/tests/NeuralNet/Initializers/Xavier1Test.php index c4e81f4ac..9fdbcec79 100644 --- a/tests/NeuralNet/Initializers/Xavier1Test.php +++ b/tests/NeuralNet/Initializers/Xavier1Test.php @@ -1,48 +1,29 @@ initializer = new Xavier1(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Xavier1::class, $this->initializer); - $this->assertInstanceOf(Initializer::class, $this->initializer); - } - - /** - * @test - */ - public function initialize() : void + public function testInitialize() : void { - $w = $this->initializer->initialize(4, 3); + $w = $this->initializer->initialize(fanIn: 4, fanOut: 3); - $this->assertInstanceOf(Matrix::class, $w); - $this->assertEquals([3, 4], $w->shape()); + $this->assertSame([3, 4], $w->shape()); } } diff --git a/tests/NeuralNet/Initializers/Xavier2Test.php b/tests/NeuralNet/Initializers/Xavier2Test.php index d9744f1fb..b179a8708 100644 --- a/tests/NeuralNet/Initializers/Xavier2Test.php +++ b/tests/NeuralNet/Initializers/Xavier2Test.php @@ -1,48 +1,29 @@ initializer = new Xavier2(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Xavier2::class, $this->initializer); - $this->assertInstanceOf(Initializer::class, $this->initializer); - } - - /** - * @test - */ - public function initialize() : void + public function testInitialize() : void { - $w = $this->initializer->initialize(4, 3); + $w = $this->initializer->initialize(fanIn: 4, fanOut: 3); - $this->assertInstanceOf(Matrix::class, $w); - $this->assertEquals([3, 4], $w->shape()); + $this->assertSame([3, 4], $w->shape()); } } diff --git a/tests/NeuralNet/Layers/ActivationTest.php b/tests/NeuralNet/Layers/ActivationTest.php index 2faaf3a28..1b3a363d9 100644 --- a/tests/NeuralNet/Layers/ActivationTest.php +++ b/tests/NeuralNet/Layers/ActivationTest.php @@ -1,50 +1,36 @@ fanIn = 3; @@ -55,7 +41,7 @@ protected function setUp() : void [0.002, -6.0, -0.5], ]); - $this->prevGrad = new Deferred(function () { + $this->prevGrad = new Deferred(fn: function () { return Matrix::quick([ [0.25, 0.7, 0.1], [0.50, 0.2, 0.01], @@ -68,20 +54,7 @@ protected function setUp() : void $this->layer = new Activation(new ReLU()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Activation::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - $this->assertInstanceOf(Hidden::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize($this->fanIn); @@ -95,10 +68,11 @@ public function initializeForwardBackInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEquals($expected, $forward->asArray()); - $gradient = $this->layer->back($this->prevGrad, $this->optimizer)->compute(); + $gradient = $this->layer + ->back(prevGradient: $this->prevGrad, optimizer: $this->optimizer) + ->compute(); $expected = [ [0.25, 0.7, 0.0], @@ -116,8 +90,6 @@ public function initializeForwardBackInfer() : void ]; $infer = $this->layer->infer($this->input); - - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEquals($expected, $infer->asArray()); } } diff --git a/tests/NeuralNet/Layers/BatchNormTest.php b/tests/NeuralNet/Layers/BatchNormTest.php index 211b0bdd6..1387fdd53 100644 --- a/tests/NeuralNet/Layers/BatchNormTest.php +++ b/tests/NeuralNet/Layers/BatchNormTest.php @@ -1,51 +1,36 @@ fanIn = 3; @@ -56,7 +41,7 @@ protected function setUp() : void [0.002, -6., -0.5], ]); - $this->prevGrad = new Deferred(function () { + $this->prevGrad = new Deferred(fn: function () { return Matrix::quick([ [0.25, 0.7, 0.1], [0.50, 0.2, 0.01], @@ -66,24 +51,14 @@ protected function setUp() : void $this->optimizer = new Stochastic(0.001); - $this->layer = new BatchNorm(0.9, new Constant(0.), new Constant(1.)); + $this->layer = new BatchNorm( + decay: 0.9, + betaInitializer: new Constant(0.), + gammaInitializer: new Constant(1.) + ); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(BatchNorm::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - $this->assertInstanceOf(Hidden::class, $this->layer); - $this->assertInstanceOf(Parametric::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize($this->fanIn); @@ -97,10 +72,12 @@ public function initializeForwardBackInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEqualsWithDelta($expected, $forward->asArray(), 1e-8); - $gradient = $this->layer->back($this->prevGrad, $this->optimizer)->compute(); + $gradient = $this->layer->back( + prevGradient: $this->prevGrad, + optimizer: $this->optimizer + )->compute(); $expected = [ [-0.06445877134888621, 0.027271018647605647, 0.03718775270128047], @@ -119,7 +96,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEqualsWithDelta($expected, $infer->asArray(), 1e-8); } } diff --git a/tests/NeuralNet/Layers/BinaryTest.php b/tests/NeuralNet/Layers/BinaryTest.php index 37b8c2591..75fc1dc7e 100644 --- a/tests/NeuralNet/Layers/BinaryTest.php +++ b/tests/NeuralNet/Layers/BinaryTest.php @@ -1,47 +1,36 @@ input = Matrix::quick([ @@ -52,25 +41,12 @@ protected function setUp() : void $this->optimizer = new Stochastic(0.001); - $this->layer = new Binary(['hot', 'cold'], new CrossEntropy()); + $this->layer = new Binary(classes: ['hot', 'cold'], costFn: new CrossEntropy()); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Binary::class, $this->layer); - $this->assertInstanceOf(Output::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize(1); @@ -82,10 +58,9 @@ public function initializeForwardBackInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEqualsWithDelta($expected, $forward->asArray(), 1e-8); - [$computation, $loss] = $this->layer->back($this->labels, $this->optimizer); + [$computation, $loss] = $this->layer->back(labels: $this->labels, optimizer: $this->optimizer); $this->assertInstanceOf(Deferred::class, $computation); $this->assertIsFloat($loss); @@ -105,7 +80,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEqualsWithDelta($expected, $infer->asArray(), 1e-8); } } diff --git a/tests/NeuralNet/Layers/ContinuousTest.php b/tests/NeuralNet/Layers/ContinuousTest.php index 8c69984ba..bdc0f4da2 100644 --- a/tests/NeuralNet/Layers/ContinuousTest.php +++ b/tests/NeuralNet/Layers/ContinuousTest.php @@ -1,47 +1,36 @@ input = Matrix::quick([ @@ -57,20 +46,7 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Continuous::class, $this->layer); - $this->assertInstanceOf(Output::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize(1); @@ -82,10 +58,9 @@ public function initializeForwardBackInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEqualsWithDelta($expected, $forward->asArray(), 1e-8); - [$computation, $loss] = $this->layer->back($this->labels, $this->optimizer); + [$computation, $loss] = $this->layer->back(labels: $this->labels, optimizer: $this->optimizer); $this->assertInstanceOf(Deferred::class, $computation); $this->assertIsFloat($loss); @@ -105,7 +80,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEqualsWithDelta($expected, $infer->asArray(), 1e-8); } } diff --git a/tests/NeuralNet/Layers/DenseTest.php b/tests/NeuralNet/Layers/DenseTest.php index 58f97081c..4f36f0efa 100644 --- a/tests/NeuralNet/Layers/DenseTest.php +++ b/tests/NeuralNet/Layers/DenseTest.php @@ -1,54 +1,39 @@ fanIn = 3; @@ -59,7 +44,7 @@ protected function setUp() : void [0.002, -6.0, -0.5], ]); - $this->prevGrad = new Deferred(function () { + $this->prevGrad = new Deferred(fn: function () { return Matrix::quick([ [0.50, 0.2, 0.01], [0.25, 0.1, 0.89], @@ -68,26 +53,18 @@ protected function setUp() : void $this->optimizer = new Stochastic(0.001); - $this->layer = new Dense(2, 0.0, true, new He(), new Constant(0.0)); + $this->layer = new Dense( + neurons: 2, + l2Penalty: 0.0, + bias: true, + weightInitializer: new He(), + biasInitializer: new Constant(0.0) + ); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Dense::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - $this->assertInstanceOf(Hidden::class, $this->layer); - $this->assertInstanceOf(Parametric::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize($this->fanIn); @@ -100,10 +77,12 @@ public function initializeForwardBackInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEqualsWithDelta($expected, $forward->asArray(), 1e-8); - $gradient = $this->layer->back($this->prevGrad, $this->optimizer)->compute(); + $gradient = $this->layer->back( + prevGradient: $this->prevGrad, + optimizer: $this->optimizer + )->compute(); $expected = [ [0.2513486032877107, 0.10053944131508427, 0.698223970571707], @@ -121,7 +100,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEqualsWithDelta($expected, $infer->asArray(), 1e-8); } } diff --git a/tests/NeuralNet/Layers/DropoutTest.php b/tests/NeuralNet/Layers/DropoutTest.php index 3f5de12a5..549165768 100644 --- a/tests/NeuralNet/Layers/DropoutTest.php +++ b/tests/NeuralNet/Layers/DropoutTest.php @@ -1,51 +1,37 @@ fanIn = 3; @@ -56,7 +42,7 @@ protected function setUp() : void [0.002, -6.0, -0.5], ]); - $this->prevGrad = new Deferred(function () { + $this->prevGrad = new Deferred(fn: function () { return Matrix::quick([ [0.25, 0.7, 0.1], [0.50, 0.2, 0.01], @@ -71,20 +57,7 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Dropout::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - $this->assertInstanceOf(Hidden::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize($this->fanIn); @@ -98,10 +71,12 @@ public function initializeForwardBackInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEquals($expected, $forward->asArray()); - $gradient = $this->layer->back($this->prevGrad, $this->optimizer)->compute(); + $gradient = $this->layer->back( + prevGradient: $this->prevGrad, + optimizer: $this->optimizer + )->compute(); $expected = [ [0.5, 1.4, 0.2], @@ -120,7 +95,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEquals($expected, $infer->asArray()); } } diff --git a/tests/NeuralNet/Layers/MulticlassTest.php b/tests/NeuralNet/Layers/MulticlassTest.php index dd6fc162d..ad4ec0178 100644 --- a/tests/NeuralNet/Layers/MulticlassTest.php +++ b/tests/NeuralNet/Layers/MulticlassTest.php @@ -1,47 +1,36 @@ input = Matrix::quick([ @@ -54,25 +43,15 @@ protected function setUp() : void $this->optimizer = new Stochastic(0.001); - $this->layer = new Multiclass(['hot', 'cold', 'ice cold'], new CrossEntropy()); + $this->layer = new Multiclass( + classes: ['hot', 'cold', 'ice cold'], + costFn: new CrossEntropy() + ); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Multiclass::class, $this->layer); - $this->assertInstanceOf(Output::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize(3); @@ -86,10 +65,12 @@ public function initializeForwardBackInfer() : void [0.2076492379866508, 0.0001879982788470176, 0.028084147227870816], ]; - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEqualsWithDelta($expected, $forward->asArray(), 1e-8); - [$computation, $loss] = $this->layer->back($this->labels, $this->optimizer); + [$computation, $loss] = $this->layer->back( + labels: $this->labels, + optimizer: $this->optimizer + ); $this->assertInstanceOf(Deferred::class, $computation); $this->assertIsFloat($loss); @@ -113,7 +94,6 @@ public function initializeForwardBackInfer() : void [0.2076492379866508, 0.0001879982788470176, 0.028084147227870816], ]; - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEqualsWithDelta($expected, $infer->asArray(), 1e-8); } } diff --git a/tests/NeuralNet/Layers/NoiseTest.php b/tests/NeuralNet/Layers/NoiseTest.php index fb1a9af5e..e414a041d 100644 --- a/tests/NeuralNet/Layers/NoiseTest.php +++ b/tests/NeuralNet/Layers/NoiseTest.php @@ -1,51 +1,43 @@ fanIn = 3; @@ -56,7 +48,7 @@ protected function setUp() : void [0.002, -6., -0.5], ]); - $this->prevGrad = new Deferred(function () { + $this->prevGrad = new Deferred(fn: function () { return Matrix::quick([ [0.25, 0.7, 0.1], [0.50, 0.2, 0.01], @@ -71,20 +63,7 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Noise::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - $this->assertInstanceOf(Hidden::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize($this->fanIn); @@ -98,10 +77,12 @@ public function initializeForwardBackInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEqualsWithDelta($expected, $forward->asArray(), 1e-8); - $gradient = $this->layer->back($this->prevGrad, $this->optimizer)->compute(); + $gradient = $this->layer->back( + prevGradient: $this->prevGrad, + optimizer: $this->optimizer + )->compute(); $expected = [ [0.25, 0.7, 0.1], @@ -120,7 +101,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEqualsWithDelta($expected, $infer->asArray(), 1e-8); } } diff --git a/tests/NeuralNet/Layers/PReLUTest.php b/tests/NeuralNet/Layers/PReLUTest.php index c2f7e41ee..b60370943 100644 --- a/tests/NeuralNet/Layers/PReLUTest.php +++ b/tests/NeuralNet/Layers/PReLUTest.php @@ -1,53 +1,38 @@ fanIn = 3; @@ -58,7 +43,7 @@ protected function setUp() : void [0.002, -6., -0.5], ]); - $this->prevGrad = new Deferred(function () { + $this->prevGrad = new Deferred(fn: function () { return Matrix::quick([ [0.25, 0.7, 0.1], [0.50, 0.2, 0.01], @@ -73,21 +58,7 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(PReLU::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - $this->assertInstanceOf(Hidden::class, $this->layer); - $this->assertInstanceOf(Parametric::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize($this->fanIn); @@ -101,10 +72,12 @@ public function initializeForwardBackInfer() : void [0.002, -1.5, -0.125], ]; - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEquals($expected, $forward->asArray()); - $gradient = $this->layer->back($this->prevGrad, $this->optimizer)->compute(); + $gradient = $this->layer->back( + prevGradient: $this->prevGrad, + optimizer: $this->optimizer + )->compute(); $expected = [ [0.25, 0.7, 0.025001000000000002], @@ -123,7 +96,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEquals($expected, $infer->asArray()); } } diff --git a/tests/NeuralNet/Layers/Placeholder1DTest.php b/tests/NeuralNet/Layers/Placeholder1DTest.php index 71591bf5b..8e0dbf24c 100644 --- a/tests/NeuralNet/Layers/Placeholder1DTest.php +++ b/tests/NeuralNet/Layers/Placeholder1DTest.php @@ -1,32 +1,23 @@ input = Matrix::quick([ @@ -38,20 +29,7 @@ protected function setUp() : void $this->layer = new Placeholder1D(3); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Placeholder1D::class, $this->layer); - $this->assertInstanceOf(Input::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - } - - /** - * @test - */ - public function forwardInfer() : void + public function testForwardInfer() : void { $this->assertEquals(3, $this->layer->width()); @@ -63,12 +41,10 @@ public function forwardInfer() : void $forward = $this->layer->forward($this->input); - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEquals($expected, $forward->asArray()); $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEquals($expected, $infer->asArray()); } } diff --git a/tests/NeuralNet/Layers/SwishTest.php b/tests/NeuralNet/Layers/SwishTest.php index f2e21c1e8..b632bb70b 100644 --- a/tests/NeuralNet/Layers/SwishTest.php +++ b/tests/NeuralNet/Layers/SwishTest.php @@ -1,53 +1,38 @@ fanIn = 3; @@ -58,7 +43,7 @@ protected function setUp() : void [0.002, -6.0, -0.5], ]); - $this->prevGrad = new Deferred(function () { + $this->prevGrad = new Deferred(fn: function () { return Matrix::quick([ [0.25, 0.7, 0.1], [0.50, 0.2, 0.01], @@ -73,21 +58,7 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Swish::class, $this->layer); - $this->assertInstanceOf(Layer::class, $this->layer); - $this->assertInstanceOf(Hidden::class, $this->layer); - $this->assertInstanceOf(Parametric::class, $this->layer); - } - - /** - * @test - */ - public function initializeForwardBackInfer() : void + public function testInitializeForwardBackInfer() : void { $this->layer->initialize($this->fanIn); @@ -101,10 +72,12 @@ public function initializeForwardBackInfer() : void [0.0010009999996666667, -0.014835738939808645, -0.1887703343990727], ]; - $this->assertInstanceOf(Matrix::class, $forward); $this->assertEquals($expected, $forward->asArray()); - $gradient = $this->layer->back($this->prevGrad, $this->optimizer)->compute(); + $gradient = $this->layer->back( + prevGradient: $this->prevGrad, + optimizer: $this->optimizer + )->compute(); $expected = [ [0.2319176279678717, 0.7695807779390686, 0.045008320850177086], @@ -123,7 +96,6 @@ public function initializeForwardBackInfer() : void $infer = $this->layer->infer($this->input); - $this->assertInstanceOf(Matrix::class, $infer); $this->assertEquals($expected, $infer->asArray()); } } diff --git a/tests/NeuralNet/NetworkTest.php b/tests/NeuralNet/NetworkTest.php index 480c97dd2..1421c0a35 100644 --- a/tests/NeuralNet/NetworkTest.php +++ b/tests/NeuralNet/NetworkTest.php @@ -1,8 +1,14 @@ dataset = Labeled::quick([ - [1.0, 2.5], - [0.1, 0.0], - [0.002, -6.0], - ], ['yes', 'no', 'maybe']); + $this->dataset = Labeled::quick( + samples: [ + [1.0, 2.5], + [0.1, 0.0], + [0.002, -6.0], + ], + labels: ['yes', 'no', 'maybe'] + ); $this->input = new Placeholder1D(2); $this->hidden = [ - new Dense(10), + new Dense(neurons: 10), new Activation(new ReLU()), - new Dense(5), + new Dense(neurons: 5), new Activation(new ReLU()), - new Dense(3), + new Dense(neurons: 3), ]; - $this->output = new Multiclass(['yes', 'no', 'maybe'], new CrossEntropy()); - - $this->network = new Network($this->input, $this->hidden, $this->output, new Adam(0.001)); + $this->output = new Multiclass( + classes: ['yes', 'no', 'maybe'], + costFn: new CrossEntropy() + ); + + $this->network = new Network( + input: $this->input, + hidden: $this->hidden, + output: $this->output, + optimizer: new Adam(0.001) + ); } - /** - * @test - */ - public function build() : void + public function testLayers() : void { - $this->assertInstanceOf(Network::class, $this->network); - $this->assertInstanceOf(Network::class, $this->network); - } + $count = 0; - /** - * @test - */ - public function layers() : void - { - $this->assertCount(7, $this->network->layers()); + foreach ($this->network->layers() as $item) { + ++$count; + } + + $this->assertSame(7, $count); } - /** - * @test - */ - public function input() : void + public function testInput() : void { $this->assertInstanceOf(Placeholder1D::class, $this->network->input()); } - /** - * @test - */ - public function hidden() : void + public function testHidden() : void { $this->assertCount(5, $this->network->hidden()); } - /** - * @test - */ - public function output() : void - { - $this->assertInstanceOf(Output::class, $this->network->output()); - } - - /** - * @test - */ - public function numParams() : void + public function testNumParams() : void { $this->network->initialize(); $this->assertEquals(103, $this->network->numParams()); } - - /** - * @test - */ - public function roundtrip() : void - { - $this->network->initialize(); - - $loss = $this->network->roundtrip($this->dataset); - - $this->assertIsFloat($loss); - } } diff --git a/tests/NeuralNet/Optimizers/AdaGradTest.php b/tests/NeuralNet/Optimizers/AdaGradTest.php index dadfb54fa..f971948ab 100644 --- a/tests/NeuralNet/Optimizers/AdaGradTest.php +++ b/tests/NeuralNet/Optimizers/AdaGradTest.php @@ -1,66 +1,26 @@ optimizer = new AdaGrad(0.001); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(AdaGrad::class, $this->optimizer); - $this->assertInstanceOf(Adaptive::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $this->optimizer->warm($param); + protected AdaGrad $optimizer; - $step = $this->optimizer->step($param, $gradient); - - $this->assertEquals($expected, $step->asArray()); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -80,4 +40,24 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new AdaGrad(0.001); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $this->optimizer->warm($param); + + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEquals($expected, $step->asArray()); + } } diff --git a/tests/NeuralNet/Optimizers/AdaMaxTest.php b/tests/NeuralNet/Optimizers/AdaMaxTest.php index 15d7992ea..8ab3daff7 100644 --- a/tests/NeuralNet/Optimizers/AdaMaxTest.php +++ b/tests/NeuralNet/Optimizers/AdaMaxTest.php @@ -1,66 +1,26 @@ optimizer = new AdaMax(0.001, 0.1, 0.001); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(AdaMax::class, $this->optimizer); - $this->assertInstanceOf(Adaptive::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $this->optimizer->warm($param); + protected AdaMax $optimizer; - $step = $this->optimizer->step($param, $gradient); - - $this->assertEqualsWithDelta($expected, $step->asArray(), 1e-8); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -80,4 +40,28 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new AdaMax( + rate: 0.001, + momentumDecay: 0.1, + normDecay: 0.001 + ); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $this->optimizer->warm($param); + + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEqualsWithDelta($expected, $step->asArray(), 1e-8); + } } diff --git a/tests/NeuralNet/Optimizers/AdamTest.php b/tests/NeuralNet/Optimizers/AdamTest.php index 3b760ca7f..f49b5fe08 100644 --- a/tests/NeuralNet/Optimizers/AdamTest.php +++ b/tests/NeuralNet/Optimizers/AdamTest.php @@ -1,66 +1,27 @@ optimizer = new Adam(0.001, 0.1, 0.001); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Adam::class, $this->optimizer); - $this->assertInstanceOf(Adaptive::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $this->optimizer->warm($param); + protected Adam $optimizer; - $step = $this->optimizer->step($param, $gradient); - - $this->assertEqualsWithDelta($expected, $step->asArray(), 1e-8); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -80,4 +41,28 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new Adam( + rate: 0.001, + momentumDecay: 0.1, + normDecay: 0.001 + ); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $this->optimizer->warm($param); + + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEqualsWithDelta($expected, $step->asArray(), 1e-8); + } } diff --git a/tests/NeuralNet/Optimizers/CyclicalTest.php b/tests/NeuralNet/Optimizers/CyclicalTest.php index 5d36b6765..f175a975f 100644 --- a/tests/NeuralNet/Optimizers/CyclicalTest.php +++ b/tests/NeuralNet/Optimizers/CyclicalTest.php @@ -1,62 +1,26 @@ optimizer = new Cyclical(0.001, 0.006, 2000); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Cyclical::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $step = $this->optimizer->step($param, $gradient); + protected Cyclical $optimizer; - $this->assertEquals($expected, $step->asArray()); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -76,4 +40,22 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new Cyclical(lower: 0.001, upper: 0.006, losses: 2000); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEquals($expected, $step->asArray()); + } } diff --git a/tests/NeuralNet/Optimizers/MomentumTest.php b/tests/NeuralNet/Optimizers/MomentumTest.php index 8380c7267..3ede88341 100644 --- a/tests/NeuralNet/Optimizers/MomentumTest.php +++ b/tests/NeuralNet/Optimizers/MomentumTest.php @@ -1,66 +1,26 @@ optimizer = new Momentum(0.001, 0.1, false); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Momentum::class, $this->optimizer); - $this->assertInstanceOf(Adaptive::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $this->optimizer->warm($param); + protected Momentum $optimizer; - $step = $this->optimizer->step($param, $gradient); - - $this->assertEquals($expected, $step->asArray()); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -80,4 +40,24 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new Momentum(rate: 0.001, decay: 0.1, lookahead: false); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $this->optimizer->warm($param); + + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEquals($expected, $step->asArray()); + } } diff --git a/tests/NeuralNet/Optimizers/RMSPropTest.php b/tests/NeuralNet/Optimizers/RMSPropTest.php index 2458a7585..28b2be7b9 100644 --- a/tests/NeuralNet/Optimizers/RMSPropTest.php +++ b/tests/NeuralNet/Optimizers/RMSPropTest.php @@ -1,66 +1,26 @@ optimizer = new RMSProp(0.001, 0.1); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RMSProp::class, $this->optimizer); - $this->assertInstanceOf(Adaptive::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $this->optimizer->warm($param); + protected RMSProp $optimizer; - $step = $this->optimizer->step($param, $gradient); - - $this->assertEquals($expected, $step->asArray()); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -80,4 +40,24 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new RMSProp(rate: 0.001, decay: 0.1); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $this->optimizer->warm($param); + + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEquals($expected, $step->asArray()); + } } diff --git a/tests/NeuralNet/Optimizers/StepDecayTest.php b/tests/NeuralNet/Optimizers/StepDecayTest.php index f8afd101a..76a5380a9 100644 --- a/tests/NeuralNet/Optimizers/StepDecayTest.php +++ b/tests/NeuralNet/Optimizers/StepDecayTest.php @@ -1,62 +1,26 @@ optimizer = new StepDecay(0.001); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(StepDecay::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $step = $this->optimizer->step($param, $gradient); + protected StepDecay $optimizer; - $this->assertEquals($expected, $step->asArray()); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -76,4 +40,22 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new StepDecay(rate: 0.001); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEquals($expected, $step->asArray()); + } } diff --git a/tests/NeuralNet/Optimizers/StochasticTest.php b/tests/NeuralNet/Optimizers/StochasticTest.php index 96ddd0e98..21c54ff14 100644 --- a/tests/NeuralNet/Optimizers/StochasticTest.php +++ b/tests/NeuralNet/Optimizers/StochasticTest.php @@ -1,62 +1,26 @@ optimizer = new Stochastic(0.001); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Stochastic::class, $this->optimizer); - $this->assertInstanceOf(Optimizer::class, $this->optimizer); - } - - /** - * @test - * @dataProvider stepProvider - * - * @param Parameter $param - * @param \Tensor\Tensor $gradient - * @param list> $expected - */ - public function step(Parameter $param, Tensor $gradient, array $expected) : void - { - $step = $this->optimizer->step($param, $gradient); + protected Stochastic $optimizer; - $this->assertEquals($expected, $step->asArray()); - } - - /** - * @return \Generator - */ - public function stepProvider() : Generator + public static function stepProvider() : Generator { yield [ new Parameter(Matrix::quick([ @@ -76,4 +40,22 @@ public function stepProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->optimizer = new Stochastic(0.001); + } + + /** + * @param Parameter $param + * @param Tensor $gradient + * @param list> $expected + */ + #[DataProvider('stepProvider')] + public function testStep(Parameter $param, Tensor $gradient, array $expected) : void + { + $step = $this->optimizer->step(param: $param, gradient: $gradient); + + $this->assertEquals($expected, $step->asArray()); + } } diff --git a/tests/NeuralNet/ParameterTest.php b/tests/NeuralNet/ParameterTest.php index ec54adc51..299d7acd2 100644 --- a/tests/NeuralNet/ParameterTest.php +++ b/tests/NeuralNet/ParameterTest.php @@ -1,31 +1,25 @@ param = new Parameter(Matrix::quick([ @@ -36,26 +30,7 @@ protected function setUp() : void $this->optimizer = new Stochastic(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Parameter::class, $this->param); - } - - /** - * @test - */ - public function id() : void - { - $this->assertIsInt($this->param->id()); - } - - /** - * @test - */ - public function update() : void + public function testUpdate() : void { $gradient = Matrix::quick([ [2, 1], @@ -67,7 +42,7 @@ public function update() : void [-2.01, 6.02], ]; - $this->param->update($gradient, $this->optimizer); + $this->param->update(gradient: $gradient, optimizer: $this->optimizer); $this->assertEquals($expected, $this->param->param()->asArray()); } diff --git a/tests/NeuralNet/SnapshotTest.php b/tests/NeuralNet/SnapshotTest.php index 0ed5885e3..bdf41829e 100644 --- a/tests/NeuralNet/SnapshotTest.php +++ b/tests/NeuralNet/SnapshotTest.php @@ -1,7 +1,11 @@ initialize(); - $snapshot = Snapshot::take($network); + $this->expectNotToPerformAssertions(); - $this->assertInstanceOf(Snapshot::class, $snapshot); + Snapshot::take($network); } } diff --git a/tests/PersistentModelTest.php b/tests/PersistentModelTest.php deleted file mode 100644 index 1741d148d..000000000 --- a/tests/PersistentModelTest.php +++ /dev/null @@ -1,77 +0,0 @@ -estimator = new PersistentModel(new GaussianNB(), new Filesystem('test.model'), new RBX()); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(PersistentModel::class, $this->estimator); - $this->assertInstanceOf(Probabilistic::class, $this->estimator); - $this->assertInstanceOf(Scoring::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void - { - $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); - } - - /** - * @test - */ - public function compatibility() : void - { - $this->assertEquals([DataType::continuous()], $this->estimator->compatibility()); - } - - /** - * @test - */ - public function params() : void - { - $expected = [ - 'base' => new GaussianNB(), - 'persister' => new Filesystem('test.model'), - 'serializer' => new RBX(), - ]; - - $this->assertEquals($expected, $this->estimator->params()); - } -} diff --git a/tests/Persisters/FilesystemTest.php b/tests/Persisters/FilesystemTest.php index 0f9cfed15..7e824a988 100644 --- a/tests/Persisters/FilesystemTest.php +++ b/tests/Persisters/FilesystemTest.php @@ -1,31 +1,26 @@ persister = new Filesystem(self::PATH, true); + $this->persister = new Filesystem(path: self::PATH, history: true); } protected function assertPreConditions() : void @@ -33,9 +28,6 @@ protected function assertPreConditions() : void $this->assertFileDoesNotExist(self::PATH); } - /** - * @after - */ protected function tearDown() : void { if (file_exists(self::PATH)) { @@ -47,28 +39,12 @@ protected function tearDown() : void } } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Filesystem::class, $this->persister); - $this->assertInstanceOf(Persister::class, $this->persister); - } - - /** - * @test - */ - public function saveLoad() : void + public function testSaveLoad() : void { $encoding = new Encoding("Bitch, I'm for real!"); $this->persister->save($encoding); $this->assertFileExists(self::PATH); - - $encoding = $this->persister->load(); - - $this->assertInstanceOf(Encoding::class, $encoding); } } diff --git a/tests/Regressors/AdalineTest.php b/tests/Regressors/AdalineTest.php index 1b327bc9e..67ac5b1e0 100644 --- a/tests/Regressors/AdalineTest.php +++ b/tests/Regressors/AdalineTest.php @@ -1,14 +1,12 @@ generator = new Hyperplane([1.0, 5.5, -7, 0.01], 0.0, 1.0); - - $this->estimator = new Adaline(32, new Adam(0.001), 1e-4, 100, 1e-4, 5, new HuberLoss(1.0)); + $this->generator = new Hyperplane( + coefficients: [1.0, 5.5, -7, 0.01], + intercept: 0.0, + noise: 1.0 + ); + + $this->estimator = new Adaline( + batchSize: 32, + optimizer: new Adam(rate: 0.001), + l2Penalty: 1e-4, + epochs: 100, + minChange: 1e-4, + window: 5, + costFn: new HuberLoss(1.0) + ); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Adaline::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badBatchSize() : void + public function testBadBatchSize() : void { $this->expectException(InvalidArgumentException::class); new Adaline(-100); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -134,10 +99,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'batch size' => 32, @@ -152,10 +114,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredictImportances() : void + public function testTrainPredictImportances() : void { $this->estimator->setLogger(new BlackHole()); @@ -169,35 +128,33 @@ public function trainPredictImportances() : void $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $importances = $this->estimator->featureImportances(); - $this->assertIsArray($importances); $this->assertCount(4, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], [2])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: [2])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/ExtraTreeRegressorTest.php b/tests/Regressors/ExtraTreeRegressorTest.php index d9d88a178..aecd0b367 100644 --- a/tests/Regressors/ExtraTreeRegressorTest.php +++ b/tests/Regressors/ExtraTreeRegressorTest.php @@ -1,12 +1,12 @@ generator = new Hyperplane([1.0, 5.5, -7, 0.01], 35.0, 1.0); - - $this->estimator = new ExtraTreeRegressor(30, 3, 1e-7, 4); + $this->generator = new Hyperplane( + coefficients: [1.0, 5.5, -7, 0.01], + intercept: 35.0, + noise: 1.0 + ); + + $this->estimator = new ExtraTreeRegressor( + maxHeight: 30, + maxLeafSize: 3, + minPurityIncrease: 1e-7, + maxFeatures: 4 + ); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ExtraTreeRegressor::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badMaxDepth() : void + public function testBadMaxDepth() : void { $this->expectException(InvalidArgumentException::class); new ExtraTreeRegressor(0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -128,10 +94,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'max height' => 30, @@ -143,10 +106,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredictImportancesContinuous() : void + public function testTrainPredictImportancesContinuous() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -157,24 +117,27 @@ public function trainPredictImportancesContinuous() : void $importances = $this->estimator->featureImportances(); - $this->assertIsArray($importances); $this->assertCount(4, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainPredictCategorical() : void + public function testTrainPredictCategorical() : void { - $training = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE) - ->apply(new IntervalDiscretizer(5)); + $training = $this->generator + ->generate(self::TRAIN_SIZE + self::TEST_SIZE) + ->apply(new IntervalDiscretizer(bins: 5)); $testing = $training->randomize()->take(self::TEST_SIZE); @@ -184,15 +147,18 @@ public function trainPredictCategorical() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/GradientBoostTest.php b/tests/Regressors/GradientBoostTest.php index 967f8be42..70f5a053d 100644 --- a/tests/Regressors/GradientBoostTest.php +++ b/tests/Regressors/GradientBoostTest.php @@ -1,13 +1,12 @@ generator = new SwissRoll(4.0, -7.0, 0.0, 1.0, 21.0, 0.5); - - $this->estimator = new GradientBoost(new RegressionTree(3), 0.1, 0.3, 300, 1e-4, 3, 10, 0.1, new RMSE()); + $this->generator = new SwissRoll( + x: 4.0, + y: -7.0, + z: 0.0, + scale: 1.0, + depth: 21.0, + noise: 0.5 + ); + + $this->estimator = new GradientBoost( + booster: new RegressionTree(maxHeight: 3), + rate: 0.1, + ratio: 0.3, + epochs: 300, + minChange: 1e-4, + evalInterval: 3, + window: 10, + holdOut: 0.1, + metric: new RMSE() + ); $this->metric = new RSquared(); @@ -89,51 +83,26 @@ protected function assertPreConditions() : void $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GradientBoost::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function incompatibleBooster() : void + public function testIncompatibleBooster() : void { $this->expectException(InvalidArgumentException::class); - new GradientBoost(new Ridge()); + new GradientBoost(booster: new Ridge()); } - /** - * @test - */ - public function badLearningRate() : void + public function testBadLearningRate() : void { $this->expectException(InvalidArgumentException::class); - new GradientBoost(null, -1e-3); + new GradientBoost(booster: null, rate: -1e-3); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -143,13 +112,10 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ - 'booster' => new RegressionTree(3), + 'booster' => new RegressionTree(maxHeight: 3), 'rate' => 0.1, 'ratio' => 0.3, 'epochs' => 300, @@ -163,10 +129,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredictImportances() : void + public function testTrainPredictImportances() : void { $this->estimator->setLogger(new BlackHole()); @@ -180,30 +143,32 @@ public function trainPredictImportances() : void $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $scores = $this->estimator->scores(); $this->assertIsArray($scores); - $this->assertContainsOnly('float', $scores); + $this->assertContainsOnlyFloat($scores); $importances = $this->estimator->featureImportances(); - $this->assertIsArray($importances); $this->assertCount(3, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/KDNeighborsRegressorTest.php b/tests/Regressors/KDNeighborsRegressorTest.php index 21f3e7923..9982f5886 100644 --- a/tests/Regressors/KDNeighborsRegressorTest.php +++ b/tests/Regressors/KDNeighborsRegressorTest.php @@ -1,11 +1,12 @@ generator = new HalfMoon(4.0, -7.0, 1.0, 90, 0.25); + $this->generator = new HalfMoon(x: 4.0, y: -7.0, scale: 1.0, rotation: 90, noise: 0.25); - $this->estimator = new KDNeighborsRegressor(5, true, new KDTree()); + $this->estimator = new KDNeighborsRegressor(k: 5, weighted: true, tree: new KDTree()); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KDNeighborsRegressor::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badK() : void + public function testBadK() : void { $this->expectException(InvalidArgumentException::class); - new KDNeighborsRegressor(0); + new KDNeighborsRegressor(k: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -126,10 +85,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'k' => 5, @@ -140,10 +96,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -154,25 +107,25 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], [2])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: [2])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/KNNRegressorTest.php b/tests/Regressors/KNNRegressorTest.php index 7cfaddb11..bb2761fb0 100644 --- a/tests/Regressors/KNNRegressorTest.php +++ b/tests/Regressors/KNNRegressorTest.php @@ -1,12 +1,12 @@ generator = new HalfMoon(4.0, -7.0, 1.0, 90, 0.25); + $this->generator = new HalfMoon(x: 4.0, y: -7.0, scale: 1.0, rotation: 90, noise: 0.25); - $this->estimator = new KNNRegressor(10, true, new Minkowski(3.0)); + $this->estimator = new KNNRegressor(k: 10, weighted: true, kernel: new Minkowski(3.0)); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KNNRegressor::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badK() : void + public function testBadK() : void { $this->expectException(InvalidArgumentException::class); - new KNNRegressor(0); + new KNNRegressor(k: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -128,10 +85,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'k' => 10, @@ -142,10 +96,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -160,25 +111,24 @@ public function trainPartialPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], [2])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: [2])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/MLPRegressorTest.php b/tests/Regressors/MLPRegressorTest.php index 5eeae37d2..9d7dc7650 100644 --- a/tests/Regressors/MLPRegressorTest.php +++ b/tests/Regressors/MLPRegressorTest.php @@ -1,20 +1,16 @@ generator = new SwissRoll(4.0, -7.0, 0.0, 1.0, 21.0, 0.5); + $this->generator = new SwissRoll(x: 4.0, y: -7.0, z: 0.0, scale: 1.0, depth: 21.0, noise: 0.5); - $this->estimator = new MLPRegressor([ - new Dense(32), - new Activation(new SiLU()), - new Dense(16), - new Activation(new SiLU()), - new Dense(8), - new Activation(new SiLU()), - ], 32, new Adam(0.01), 100, 1e-4, 3, 5, 0.1, new LeastSquares(), new RMSE()); + $this->estimator = new MLPRegressor( + hiddenLayers: [ + new Dense(32), + new Activation(new SiLU()), + new Dense(16), + new Activation(new SiLU()), + new Dense(8), + new Activation(new SiLU()), + ], + batchSize: 32, + optimizer: new Adam(0.01), + epochs: 100, + minChange: 1e-4, + evalInterval: 3, + window: 5, + holdOut: 0.1, + costFn: new LeastSquares(), + metric: new RMSE() + ); $this->metric = new RSquared(); @@ -101,46 +86,24 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MLPRegressor::class, $this->estimator); - $this->assertInstanceOf(Online::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Verbose::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badBatchSize() : void + public function testBadBatchSize() : void { $this->expectException(InvalidArgumentException::class); - new MLPRegressor([], -100); + new MLPRegressor(hiddenLayers: [], batchSize: -100); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -149,10 +112,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'hidden layers' => [ @@ -177,10 +137,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPartialPredict() : void + public function testTrainPartialPredict() : void { $dataset = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE); @@ -200,40 +157,38 @@ public function trainPartialPredict() : void // Graphviz::dotToImage($dot)->saveTo(new Filesystem('test.png')); - $this->assertInstanceOf(Encoding::class, $dot); - $this->assertStringStartsWith('digraph Tree {', $dot); + $this->assertStringStartsWith('digraph Tree {', (string) $dot); $losses = $this->estimator->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); $scores = $this->estimator->scores(); $this->assertIsArray($scores); - $this->assertContainsOnly('float', $scores); + $this->assertContainsOnlyFloat($scores); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], [2])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: [2])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/RadiusNeighborsRegressorTest.php b/tests/Regressors/RadiusNeighborsRegressorTest.php index fe233b14b..ebecc902b 100644 --- a/tests/Regressors/RadiusNeighborsRegressorTest.php +++ b/tests/Regressors/RadiusNeighborsRegressorTest.php @@ -1,11 +1,12 @@ generator = new HalfMoon(4.0, -7.0, 1.0, 90, 0.25); + $this->generator = new HalfMoon(x: 4.0, y: -7.0, scale: 1.0, rotation: 90, noise: 0.25); - $this->estimator = new RadiusNeighborsRegressor(0.8, true, new BallTree()); + $this->estimator = new RadiusNeighborsRegressor(radius: 0.8, weighted: true, tree: new BallTree()); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RadiusNeighborsRegressor::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function badRadius() : void + public function testBadRadius() : void { $this->expectException(InvalidArgumentException::class); - new RadiusNeighborsRegressor(0.0); + new RadiusNeighborsRegressor(radius: 0.0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -126,10 +85,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -140,25 +96,24 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], [2])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: [2])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/RegressionTreeTest.php b/tests/Regressors/RegressionTreeTest.php index 0ea454551..0b9903f79 100644 --- a/tests/Regressors/RegressionTreeTest.php +++ b/tests/Regressors/RegressionTreeTest.php @@ -1,17 +1,14 @@ generator = new Hyperplane([1.0, 5.5, -7, 0.01], 35.0, 1.0); - - $this->estimator = new RegressionTree(30, 5, 1e-7, 3); + $this->generator = new Hyperplane( + coefficients: [1.0, 5.5, -7, 0.01], + intercept: 35.0, + noise: 1.0 + ); + + $this->estimator = new RegressionTree( + maxHeight: 30, + maxLeafSize: 5, + minPurityIncrease: 1e-7, + maxFeatures: 3 + ); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RegressionTree::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badMaxDepth() : void + public function testBadMaxDepth() : void { $this->expectException(InvalidArgumentException::class); - new RegressionTree(0); + new RegressionTree(maxHeight: 0); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::categorical(), @@ -131,10 +94,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function params() : void + public function testParams() : void { $expected = [ 'max height' => 30, @@ -147,10 +107,7 @@ public function params() : void $this->assertEquals($expected, $this->estimator->params()); } - /** - * @test - */ - public function trainPredictImportancesContinuous() : void + public function testTrainPredictImportancesContinuous() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -161,31 +118,32 @@ public function trainPredictImportancesContinuous() : void $importances = $this->estimator->featureImportances(); - $this->assertIsArray($importances); $this->assertCount(4, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $dot = $this->estimator->exportGraphviz(); // Graphviz::dotToImage($dot)->saveTo(new Filesystem('test.png')); - $this->assertInstanceOf(Encoding::class, $dot); - $this->assertStringStartsWith('digraph Tree {', $dot); + $this->assertStringStartsWith('digraph Tree {', (string) $dot); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainPredictCategorical() : void + public function testTrainPredictCategorical() : void { - $training = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE) - ->apply(new IntervalDiscretizer(5)); + $training = $this->generator + ->generate(self::TRAIN_SIZE + self::TEST_SIZE) + ->apply(new IntervalDiscretizer(bins: 5)); $testing = $training->randomize()->take(self::TEST_SIZE); @@ -197,20 +155,21 @@ public function trainPredictCategorical() : void // Graphviz::dotToImage($dot)->saveTo(new Filesystem('test.png')); - $this->assertInstanceOf(Encoding::class, $dot); - $this->assertStringStartsWith('digraph Tree {', $dot); + $this->assertStringStartsWith('digraph Tree {', (string) $dot); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/RidgeTest.php b/tests/Regressors/RidgeTest.php index 48daccff5..d486d0e12 100644 --- a/tests/Regressors/RidgeTest.php +++ b/tests/Regressors/RidgeTest.php @@ -1,12 +1,12 @@ generator = new Hyperplane([1.0, 5.5, -7, 0.01], 0.0, 1.0); + $this->generator = new Hyperplane( + coefficients: [1.0, 5.5, -7, 0.01], + intercept: 0.0, + noise: 1.0 + ); $this->estimator = new Ridge(1.0); @@ -80,45 +62,24 @@ protected function setUp() : void srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Ridge::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(RanksFeatures::class, $this->estimator); - $this->assertInstanceOf(Persistable::class, $this->estimator); - } - - /** - * @test - */ - public function badL2Penalty() : void + public function testBadL2Penalty() : void { $this->expectException(InvalidArgumentException::class); new Ridge(-1e-4); } - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -127,10 +88,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function trainPredictImportances() : void + public function testTrainPredictImportances() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); @@ -148,31 +106,29 @@ public function trainPredictImportances() : void $importances = $this->estimator->featureImportances(); - $this->assertIsArray($importances); $this->assertCount(4, $importances); - $this->assertContainsOnly('float', $importances); + $this->assertContainsOnlyFloat($importances); $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']], [2])); + $this->estimator->train(Labeled::quick(samples: [['bad']], labels: [2])); } - /** - * @test - */ - public function predictUntrained() : void + public function testPredictUntrained() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Regressors/SVRTest.php b/tests/Regressors/SVRTest.php index 2710d0b61..17e0e19b4 100644 --- a/tests/Regressors/SVRTest.php +++ b/tests/Regressors/SVRTest.php @@ -1,10 +1,12 @@ generator = new Hyperplane([1.0, 5.5, -7, 0.01], 0.0, 1.0); - - $this->estimator = new SVR(1, 1e-8, new Linear(), false, 1e-3); + $this->generator = new Hyperplane( + coefficients: [1.0, 5.5, -7, 0.01], + intercept: 0.0, + noise: 1.0 + ); + + $this->estimator = new SVR( + c: 1, + epsilon: 1e-8, + kernel: new Linear(), + shrinking: false, + tolerance: 1e-3 + ); $this->metric = new RSquared(); srand(self::RANDOM_SEED); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SVR::class, $this->estimator); - $this->assertInstanceOf(Learner::class, $this->estimator); - $this->assertInstanceOf(Estimator::class, $this->estimator); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(EstimatorType::regressor(), $this->estimator->type()); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -116,10 +89,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->estimator->compatibility()); } - /** - * @test - */ - public function trainPredict() : void + public function testTrainPredict() : void { $dataset = $this->generator->generate(self::TRAIN_SIZE + self::TEST_SIZE); @@ -133,28 +103,27 @@ public function trainPredict() : void $predictions = $this->estimator->predict($testing); - $score = $this->metric->score($predictions, $testing->labels()); + /** @var list $labels */ + $labels = $testing->labels(); + $score = $this->metric->score( + predictions: $predictions, + labels: $labels + ); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } - /** - * @test - */ - public function trainIncompatible() : void + public function testTrainIncompatible() : void { $this->expectException(InvalidArgumentException::class); - $this->estimator->train(Labeled::quick([['bad']])); + $this->estimator->train(Labeled::quick(samples: [['bad']])); } - /** - * @test - */ public function predictUntrained() : void { $this->expectException(RuntimeException::class); - $this->estimator->predict(Unlabeled::quick([[1.5]])); + $this->estimator->predict(Unlabeled::quick(samples: [[1.5]])); } } diff --git a/tests/Serializers/GzipNativeTest.php b/tests/Serializers/GzipNativeTest.php index 01d494a38..56e883fd7 100644 --- a/tests/Serializers/GzipNativeTest.php +++ b/tests/Serializers/GzipNativeTest.php @@ -1,33 +1,24 @@ serializer = new GzipNative(6); @@ -35,27 +26,12 @@ protected function setUp() : void $this->persistable = new GaussianNB(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GzipNative::class, $this->serializer); - $this->assertInstanceOf(Serializer::class, $this->serializer); - } - - /** - * @test - */ - public function serializeDeserialize() : void + public function testSerializeDeserialize() : void { $data = $this->serializer->serialize($this->persistable); - $this->assertInstanceOf(Encoding::class, $data); - $persistable = $this->serializer->deserialize($data); $this->assertInstanceOf(GaussianNB::class, $persistable); - $this->assertInstanceOf(Persistable::class, $persistable); } } diff --git a/tests/Serializers/NativeTest.php b/tests/Serializers/NativeTest.php index c49e498bb..012de575f 100644 --- a/tests/Serializers/NativeTest.php +++ b/tests/Serializers/NativeTest.php @@ -1,11 +1,15 @@ |array> */ + public static function deserializeInvalidData() : array + { + return [ + [3], + [new stdClass()], + ]; + } + protected function setUp() : void { $this->serializer = new Native(); @@ -39,49 +43,20 @@ protected function setUp() : void $this->persistable = new GaussianNB(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Native::class, $this->serializer); - $this->assertInstanceOf(Serializer::class, $this->serializer); - } - - /** - * @test - */ - public function serializeDeserialize() : void + public function testSerializeDeserialize() : void { $data = $this->serializer->serialize($this->persistable); - $this->assertInstanceOf(Encoding::class, $data); - $persistable = $this->serializer->deserialize($data); $this->assertInstanceOf(GaussianNB::class, $persistable); - $this->assertInstanceOf(Persistable::class, $persistable); - } - - /** - * @return array - */ - public function deserializeInvalidData() : array - { - return [ - [3], - [new stdClass()], - ]; } /** - * @test - * - * @param mixed $obj - * - * @dataProvider deserializeInvalidData + * @param int|object $obj */ - public function deserializeBadData($obj) : void + #[DataProvider('deserializeInvalidData')] + public function testDeserializeBadData(mixed $obj) : void { $data = new Encoding(serialize($obj)); diff --git a/tests/Serializers/RBXTest.php b/tests/Serializers/RBXTest.php index b45b999d4..b5122c61b 100644 --- a/tests/Serializers/RBXTest.php +++ b/tests/Serializers/RBXTest.php @@ -1,37 +1,41 @@ |array> */ + public static function deserializeInvalidData() : array + { + return [ + [3], + [new stdClass()], + ]; + } + protected function setUp() : void { $this->serializer = new RBX(); @@ -39,49 +43,20 @@ protected function setUp() : void $this->persistable = new AdaBoost(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RBX::class, $this->serializer); - $this->assertInstanceOf(Serializer::class, $this->serializer); - } - - /** - * @test - */ - public function serializeDeserialize() : void + public function testSerializeDeserialize() : void { $data = $this->serializer->serialize($this->persistable); - $this->assertInstanceOf(Encoding::class, $data); - $persistable = $this->serializer->deserialize($data); $this->assertInstanceOf(AdaBoost::class, $persistable); - $this->assertInstanceOf(Persistable::class, $persistable); - } - - /** - * @return array - */ - public function deserializeInvalidData() : array - { - return [ - [3], - [new stdClass()], - ]; } /** - * @test - * - * @param mixed $obj - * - * @dataProvider deserializeInvalidData + * @param int|object $obj */ - public function deserializeBadData($obj) : void + #[DataProvider('deserializeInvalidData')] + public function testDeserializeBadData(mixed $obj) : void { $data = new Encoding(serialize($obj)); diff --git a/tests/Specifications/DatasetHasDimensionalityTest.php b/tests/Specifications/DatasetHasDimensionalityTest.php index 8fce16464..6e6e6c85a 100644 --- a/tests/Specifications/DatasetHasDimensionalityTest.php +++ b/tests/Specifications/DatasetHasDimensionalityTest.php @@ -1,35 +1,22 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ DatasetHasDimensionality::with(Unlabeled::quick([ @@ -45,4 +32,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param DatasetHasDimensionality $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(DatasetHasDimensionality $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/DatasetIsLabeledTest.php b/tests/Specifications/DatasetIsLabeledTest.php index 77908558a..d5d344741 100644 --- a/tests/Specifications/DatasetIsLabeledTest.php +++ b/tests/Specifications/DatasetIsLabeledTest.php @@ -1,35 +1,23 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ DatasetIsLabeled::with(Labeled::quick([ @@ -45,4 +33,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param DatasetIsLabeled $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(DatasetIsLabeled $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/DatasetIsNotEmptyTest.php b/tests/Specifications/DatasetIsNotEmptyTest.php index 99057da69..c2c9535d6 100644 --- a/tests/Specifications/DatasetIsNotEmptyTest.php +++ b/tests/Specifications/DatasetIsNotEmptyTest.php @@ -1,34 +1,22 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ DatasetIsNotEmpty::with(Unlabeled::quick([ @@ -42,4 +30,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param DatasetIsNotEmpty $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(DatasetIsNotEmpty $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/EstimatorIsCompatibleWithMetricTest.php b/tests/Specifications/EstimatorIsCompatibleWithMetricTest.php index f3ffcbf6b..2ccc1b030 100644 --- a/tests/Specifications/EstimatorIsCompatibleWithMetricTest.php +++ b/tests/Specifications/EstimatorIsCompatibleWithMetricTest.php @@ -1,7 +1,12 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ EstimatorIsCompatibleWithMetric::with( @@ -75,4 +63,14 @@ public function passesProvider() : Generator true, ]; } + + /** + * @param EstimatorIsCompatibleWithMetric $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(EstimatorIsCompatibleWithMetric $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/ExtensionIsLoadedTest.php b/tests/Specifications/ExtensionIsLoadedTest.php index 2fb2c0ca2..86c4d561e 100644 --- a/tests/Specifications/ExtensionIsLoadedTest.php +++ b/tests/Specifications/ExtensionIsLoadedTest.php @@ -1,34 +1,23 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ ExtensionIsLoaded::with('json'), @@ -40,4 +29,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param ExtensionIsLoaded $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(ExtensionIsLoaded $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/ExtensionMinimumVersionTest.php b/tests/Specifications/ExtensionMinimumVersionTest.php index 84a4c0692..18f2dc12a 100644 --- a/tests/Specifications/ExtensionMinimumVersionTest.php +++ b/tests/Specifications/ExtensionMinimumVersionTest.php @@ -1,34 +1,23 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ ExtensionMinimumVersion::with('json', '0.0.0'), @@ -45,4 +34,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param ExtensionMinimumVersion $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(ExtensionMinimumVersion $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/LabelsAreCompatibleWithLearnerTest.php b/tests/Specifications/LabelsAreCompatibleWithLearnerTest.php index 85053d195..c39be875d 100644 --- a/tests/Specifications/LabelsAreCompatibleWithLearnerTest.php +++ b/tests/Specifications/LabelsAreCompatibleWithLearnerTest.php @@ -1,7 +1,12 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ LabelsAreCompatibleWithLearner::with( @@ -72,4 +60,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param LabelsAreCompatibleWithLearner $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(LabelsAreCompatibleWithLearner $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/SamplesAreCompatibleWithDistanceTest.php b/tests/Specifications/SamplesAreCompatibleWithDistanceTest.php index 52e279f0d..885eb5d7b 100644 --- a/tests/Specifications/SamplesAreCompatibleWithDistanceTest.php +++ b/tests/Specifications/SamplesAreCompatibleWithDistanceTest.php @@ -1,7 +1,12 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ SamplesAreCompatibleWithDistance::with( @@ -72,4 +60,14 @@ public function passesProvider() : Generator true, ]; } + + /** + * @param SamplesAreCompatibleWithDistance $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function passes(SamplesAreCompatibleWithDistance $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/SamplesAreCompatibleWithEstimatorTest.php b/tests/Specifications/SamplesAreCompatibleWithEstimatorTest.php index 5d1aff3af..5779573e3 100644 --- a/tests/Specifications/SamplesAreCompatibleWithEstimatorTest.php +++ b/tests/Specifications/SamplesAreCompatibleWithEstimatorTest.php @@ -1,7 +1,12 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ SamplesAreCompatibleWithEstimator::with( @@ -73,4 +61,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param SamplesAreCompatibleWithEstimator $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(SamplesAreCompatibleWithEstimator $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/SamplesAreCompatibleWithTransformerTest.php b/tests/Specifications/SamplesAreCompatibleWithTransformerTest.php index 9b65c0b48..f89a2b50c 100644 --- a/tests/Specifications/SamplesAreCompatibleWithTransformerTest.php +++ b/tests/Specifications/SamplesAreCompatibleWithTransformerTest.php @@ -1,7 +1,12 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator + * @return Generator */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { yield [ SamplesAreCompatibleWithTransformer::with( @@ -73,4 +64,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param SamplesAreCompatibleWithTransformer $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(SamplesAreCompatibleWithTransformer $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Specifications/SpecificationChainTest.php b/tests/Specifications/SpecificationChainTest.php index 9365f0dc9..407725acb 100644 --- a/tests/Specifications/SpecificationChainTest.php +++ b/tests/Specifications/SpecificationChainTest.php @@ -1,7 +1,12 @@ assertSame($expected, $specification->passes()); - } - - /** - * @return \Generator - */ - public function passesProvider() : Generator + public static function passesProvider() : Generator { $dataset = Unlabeled::quick([ ['swamp', 'island', 'black knight', 'counter spell'], @@ -51,4 +39,14 @@ public function passesProvider() : Generator false, ]; } + + /** + * @param SpecificationChain $specification + * @param bool $expected + */ + #[DataProvider('passesProvider')] + public function testPasses(SpecificationChain $specification, bool $expected) : void + { + $this->assertSame($expected, $specification->passes()); + } } diff --git a/tests/Strategies/ConstantTest.php b/tests/Strategies/ConstantTest.php index 7c870fcdf..f16ab2955 100644 --- a/tests/Strategies/ConstantTest.php +++ b/tests/Strategies/ConstantTest.php @@ -1,57 +1,37 @@ strategy = new Constant(42); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertTrue($this->strategy->fitted()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Constant::class, $this->strategy); - $this->assertInstanceOf(Strategy::class, $this->strategy); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(DataType::continuous(), $this->strategy->type()); } - /** - * @test - */ - public function fitGuess() : void + public function testFitGuess() : void { $this->strategy->fit([]); diff --git a/tests/Strategies/KMostFrequentTest.php b/tests/Strategies/KMostFrequentTest.php index c4ea7891f..1770ad325 100644 --- a/tests/Strategies/KMostFrequentTest.php +++ b/tests/Strategies/KMostFrequentTest.php @@ -1,57 +1,37 @@ strategy = new KMostFrequent(2); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->strategy->fitted()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KMostFrequent::class, $this->strategy); - $this->assertInstanceOf(Strategy::class, $this->strategy); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(DataType::categorical(), $this->strategy->type()); } - /** - * @test - */ - public function fitGuess() : void + public function testFitGuess() : void { $values = ['a', 'a', 'b', 'b', 'c']; diff --git a/tests/Strategies/MeanTest.php b/tests/Strategies/MeanTest.php index acfb082a8..3025feffd 100644 --- a/tests/Strategies/MeanTest.php +++ b/tests/Strategies/MeanTest.php @@ -1,57 +1,37 @@ strategy = new Mean(); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->strategy->fitted()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Mean::class, $this->strategy); - $this->assertInstanceOf(Strategy::class, $this->strategy); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(DataType::continuous(), $this->strategy->type()); } - /** - * @test - */ - public function fitGuess() : void + public function testFitGuess() : void { $this->strategy->fit([1, 2, 3, 4, 5]); diff --git a/tests/Strategies/PercentileTest.php b/tests/Strategies/PercentileTest.php index d9620a943..826ad4448 100644 --- a/tests/Strategies/PercentileTest.php +++ b/tests/Strategies/PercentileTest.php @@ -1,43 +1,26 @@ strategy = new Percentile(50.0); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Percentile::class, $this->strategy); - $this->assertInstanceOf(Strategy::class, $this->strategy); - } - - /** - * @test - */ - public function fitGuess() : void + public function testFitGuess() : void { $this->strategy->fit([1, 2, 3, 4, 5]); diff --git a/tests/Strategies/PriorTest.php b/tests/Strategies/PriorTest.php index b2317d049..89a6d766e 100644 --- a/tests/Strategies/PriorTest.php +++ b/tests/Strategies/PriorTest.php @@ -1,57 +1,32 @@ strategy = new Prior(); } - protected function assertPreConditions() : void - { - $this->assertFalse($this->strategy->fitted()); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Prior::class, $this->strategy); - $this->assertInstanceOf(Strategy::class, $this->strategy); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(DataType::categorical(), $this->strategy->type()); } - /** - * @test - */ - public function fitGuess() : void + public function testFitGuess() : void { $values = ['a', 'a', 'b', 'a', 'c']; @@ -63,4 +38,9 @@ public function fitGuess() : void $this->assertContains($value, $values); } + + protected function testAssertPreConditions() : void + { + $this->assertFalse($this->strategy->fitted()); + } } diff --git a/tests/Strategies/WildGuessTest.php b/tests/Strategies/WildGuessTest.php index b39677535..36acaabfd 100644 --- a/tests/Strategies/WildGuessTest.php +++ b/tests/Strategies/WildGuessTest.php @@ -1,57 +1,37 @@ strategy = new WildGuess(); } - protected function assertPreConditions() : void + public function testAssertPreConditions() : void { $this->assertFalse($this->strategy->fitted()); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(WildGuess::class, $this->strategy); - $this->assertInstanceOf(Strategy::class, $this->strategy); - } - - /** - * @test - */ - public function type() : void + public function testType() : void { $this->assertEquals(DataType::continuous(), $this->strategy->type()); } - /** - * @test - */ - public function fitGuess() : void + public function testFitGuess() : void { $this->strategy->fit([1, 2, 3, 4, 5]); diff --git a/tests/Tokenizers/KSkipNGramTest.php b/tests/Tokenizers/KSkipNGramTest.php index f05723865..def930da0 100644 --- a/tests/Tokenizers/KSkipNGramTest.php +++ b/tests/Tokenizers/KSkipNGramTest.php @@ -1,58 +1,23 @@ tokenizer = new KSkipNGram(2, 3, 2); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KSkipNGram::class, $this->tokenizer); - $this->assertInstanceOf(Tokenizer::class, $this->tokenizer); - } - - /** - * @test - * @dataProvider tokenizeProvider - * - * @param string $text - * @param list $expected - */ - public function tokenize(string $text, array $expected) : void - { - $tokens = $this->tokenizer->tokenize($text); + protected KSkipNGram $tokenizer; - $this->assertEquals($expected, $tokens); - } - - /** - * @return \Generator - */ - public function tokenizeProvider() : Generator + public static function tokenizeProvider() : Generator { /** * English @@ -72,4 +37,21 @@ public function tokenizeProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->tokenizer = new KSkipNGram(min: 2, max: 3, skip: 2); + } + + /** + * @param string $text + * @param list $expected + */ + #[DataProvider('tokenizeProvider')] + public function testTokenize(string $text, array $expected) : void + { + $tokens = $this->tokenizer->tokenize($text); + + $this->assertEquals($expected, $tokens); + } } diff --git a/tests/Tokenizers/NGramTest.php b/tests/Tokenizers/NGramTest.php index b7915f35a..33bef0a68 100644 --- a/tests/Tokenizers/NGramTest.php +++ b/tests/Tokenizers/NGramTest.php @@ -1,69 +1,51 @@ tokenizer = new NGram(1, 2); + /** + * English + */ + yield [ + "I'd like to die on Mars, just not on impact. The end.", + [ + "I'd", "I'd like", 'like', 'like to', 'to', 'to die', 'die', + 'die on', 'on', 'on Mars', 'Mars', 'Mars just', 'just', 'just not', 'not', 'not on', + 'on', 'on impact', 'impact', 'The', 'The end', 'end', + ], + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(NGram::class, $this->tokenizer); - $this->assertInstanceOf(Tokenizer::class, $this->tokenizer); + $this->tokenizer = new NGram(min: 1, max: 2); } /** - * @test - * @dataProvider tokenizeProvider - * * @param string $text * @param list $expected */ - public function tokenize(string $text, array $expected) : void + #[DataProvider('tokenizeProvider')] + public function testTokenize(string $text, array $expected) : void { $tokens = $this->tokenizer->tokenize($text); $this->assertEquals($expected, $tokens); } - - /** - * @return \Generator - */ - public function tokenizeProvider() : Generator - { - /** - * English - */ - yield [ - "I'd like to die on Mars, just not on impact. The end.", - [ - "I'd", "I'd like", 'like', 'like to', 'to', 'to die', 'die', - 'die on', 'on', 'on Mars', 'Mars', 'Mars just', 'just', 'just not', 'not', 'not on', - 'on', 'on impact', 'impact', 'The', 'The end', 'end', - ], - ]; - } } diff --git a/tests/Tokenizers/SentenceTest.php b/tests/Tokenizers/SentenceTest.php index 1d4166dd3..f086706df 100644 --- a/tests/Tokenizers/SentenceTest.php +++ b/tests/Tokenizers/SentenceTest.php @@ -1,58 +1,23 @@ tokenizer = new Sentence(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Sentence::class, $this->tokenizer); - $this->assertInstanceOf(Tokenizer::class, $this->tokenizer); - } - - /** - * @test - * @dataProvider tokenizeProvider - * - * @param string $text - * @param list $expected - */ - public function tokenize(string $text, array $expected) : void - { - $tokens = $this->tokenizer->tokenize($text); - - $this->assertEquals($expected, $tokens); - } + protected Sentence $tokenizer; - /** - * @return \Generator - */ - public function tokenizeProvider() : Generator + public static function tokenizeProvider() : Generator { /** * English @@ -238,4 +203,21 @@ public function tokenizeProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->tokenizer = new Sentence(); + } + + /** + * @param string $text + * @param list $expected + */ + #[DataProvider('tokenizeProvider')] + public function testTokenize(string $text, array $expected) : void + { + $tokens = $this->tokenizer->tokenize($text); + + $this->assertEquals($expected, $tokens); + } } diff --git a/tests/Tokenizers/WhitespaceTest.php b/tests/Tokenizers/WhitespaceTest.php index 57fa251be..372420bc3 100644 --- a/tests/Tokenizers/WhitespaceTest.php +++ b/tests/Tokenizers/WhitespaceTest.php @@ -1,55 +1,23 @@ tokenizer = new Whitespace(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Whitespace::class, $this->tokenizer); - $this->assertInstanceOf(Tokenizer::class, $this->tokenizer); - } - - /** - * @test - * @dataProvider tokenizeProvider - * - * @param string $text - * @param list $expected - */ - public function tokenize(string $text, array $expected) : void - { - $tokens = $this->tokenizer->tokenize($text); + protected Whitespace $tokenizer; - $this->assertEquals($expected, $tokens); - } - - /** - * @return \Generator - */ - public function tokenizeProvider() : Generator + public static function tokenizeProvider() : Generator { /** * English @@ -95,4 +63,21 @@ public function tokenizeProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->tokenizer = new Whitespace(); + } + + /** + * @param string $text + * @param list $expected + */ + #[DataProvider('tokenizeProvider')] + public function testTokenize(string $text, array $expected) : void + { + $tokens = $this->tokenizer->tokenize($text); + + $this->assertEquals($expected, $tokens); + } } diff --git a/tests/Tokenizers/WordStemmerTest.php b/tests/Tokenizers/WordStemmerTest.php index 5e5fdebb8..19ffda01b 100644 --- a/tests/Tokenizers/WordStemmerTest.php +++ b/tests/Tokenizers/WordStemmerTest.php @@ -1,70 +1,50 @@ tokenizer = new WordStemmer('english'); + /** + * English + */ + yield [ + "If something's important enough, you should try. Even if - the probable outcome is failure.", + [ + 'If', 'someth', 'import', 'enough', 'you', 'should', 'tri', + 'even', 'if', '-', 'the', 'probabl', 'outcom', 'is', 'failur', + ], + ]; } - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(WordStemmer::class, $this->tokenizer); - $this->assertInstanceOf(Word::class, $this->tokenizer); - $this->assertInstanceOf(Tokenizer::class, $this->tokenizer); + $this->tokenizer = new WordStemmer('english'); } /** - * @test - * @dataProvider tokenizeProvider - * * @param string $text * @param list $expected */ - public function tokenize(string $text, array $expected) : void + #[DataProvider('tokenizeProvider')] + public function testTokenize(string $text, array $expected) : void { $tokens = $this->tokenizer->tokenize($text); $this->assertEquals($expected, $tokens); } - - /** - * @return \Generator - */ - public function tokenizeProvider() : Generator - { - /** - * English - */ - yield [ - "If something's important enough, you should try. Even if - the probable outcome is failure.", - [ - 'If', 'someth', 'import', 'enough', 'you', 'should', 'tri', - 'even', 'if', '-', 'the', 'probabl', 'outcom', 'is', 'failur', - ], - ]; - } } diff --git a/tests/Tokenizers/WordTest.php b/tests/Tokenizers/WordTest.php index 4ea2f7677..4c7fded73 100644 --- a/tests/Tokenizers/WordTest.php +++ b/tests/Tokenizers/WordTest.php @@ -1,58 +1,23 @@ tokenizer = new Word(); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(Word::class, $this->tokenizer); - $this->assertInstanceOf(Tokenizer::class, $this->tokenizer); - } - - /** - * @test - * @dataProvider tokenizeProvider - * - * @param string $text - * @param list $expected - */ - public function tokenize(string $text, array $expected) : void - { - $tokens = $this->tokenizer->tokenize($text); - - $this->assertEquals($expected, $tokens); - } + protected Word $tokenizer; - /** - * @return \Generator - */ - public function tokenizeProvider() : Generator + public static function tokenizeProvider() : Generator { /** * English @@ -109,4 +74,21 @@ public function tokenizeProvider() : Generator ], ]; } + + protected function setUp() : void + { + $this->tokenizer = new Word(); + } + + /** + * @param string $text + * @param list $expected + */ + #[DataProvider('tokenizeProvider')] + public function testTokenize(string $text, array $expected) : void + { + $tokens = $this->tokenizer->tokenize($text); + + $this->assertEquals($expected, $tokens); + } } diff --git a/tests/Transformers/BM25TransformerTest.php b/tests/Transformers/BM25TransformerTest.php index e13df13f3..c83f8d908 100644 --- a/tests/Transformers/BM25TransformerTest.php +++ b/tests/Transformers/BM25TransformerTest.php @@ -1,48 +1,27 @@ transformer = new BM25Transformer(1.2, 0.75); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(BM25Transformer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - $this->assertInstanceOf(Elastic::class, $this->transformer); + $this->transformer = new BM25Transformer(dampening: 1.2, normalization: 0.75); } - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { $dataset = new Unlabeled([ [1, 3, 0, 0, 1, 0, 0, 0, 1, 2, 0, 2, 0, 0, 0, 4, 1, 0, 1], @@ -58,7 +37,7 @@ public function fitTransform() : void $this->assertIsArray($dfs); $this->assertCount(19, $dfs); - $this->assertContainsOnly('int', $dfs); + $this->assertContainsOnlyInt($dfs); $dataset->apply($this->transformer); diff --git a/tests/Transformers/BooleanConverterTest.php b/tests/Transformers/BooleanConverterTest.php index e9ef41c58..5e8ab3053 100644 --- a/tests/Transformers/BooleanConverterTest.php +++ b/tests/Transformers/BooleanConverterTest.php @@ -1,44 +1,27 @@ transformer = new BooleanConverter('!true!', '!false!'); - } + protected BooleanConverter $transformer; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(BooleanConverter::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); + $this->transformer = new BooleanConverter(trueValue: '!true!', falseValue: '!false!'); } - /** - * @test - */ - public function transform() : void + public function testTransform() : void { $dataset = new Unlabeled([ [true, 'true', '1', 1], diff --git a/tests/Transformers/GaussianRandomProjectorTest.php b/tests/Transformers/GaussianRandomProjectorTest.php index b1ffce116..aa12f3895 100644 --- a/tests/Transformers/GaussianRandomProjectorTest.php +++ b/tests/Transformers/GaussianRandomProjectorTest.php @@ -1,77 +1,32 @@ generator = new Blob(array_fill(0, 20, 0.0), 3.0); + protected const int RANDOM_SEED = 0; - $this->transformer = new GaussianRandomProjector(5); - - srand(self::RANDOM_SEED); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(GaussianRandomProjector::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } + protected Blob $generator; - /** - * @test - * @dataProvider minDimensionsProvider - * - * @param int $n - * @param float $maxDistortion - * @param int $expected - */ - public function minDimensions(int $n, float $maxDistortion, int $expected) : void - { - $this->assertEqualsWithDelta($expected, GaussianRandomProjector::minDimensions($n, $maxDistortion), 1e-8); - } + protected GaussianRandomProjector $transformer; - /** - * @return \Generator - */ - public function minDimensionsProvider() : Generator + public static function minDimensionsProvider() : Generator { yield [10, 0.1, 1974]; @@ -94,10 +49,30 @@ public function minDimensionsProvider() : Generator yield [10000, 0.99, 221]; } + protected function setUp() : void + { + $this->generator = new Blob( + center: array_fill(start_index: 0, count: 20, value: 0.0), + stdDev: 3.0 + ); + + $this->transformer = new GaussianRandomProjector(5); + + srand(self::RANDOM_SEED); + } + /** - * @test + * @param int $n + * @param float $maxDistortion + * @param int $expected */ - public function fitTransform() : void + #[DataProvider('minDimensionsProvider')] + public function testMinDimensions(int $n, float $maxDistortion, int $expected) : void + { + $this->assertEqualsWithDelta($expected, GaussianRandomProjector::minDimensions($n, $maxDistortion), 1e-8); + } + + public function testFitTransform() : void { $dataset = $this->generator->generate(30); @@ -112,10 +87,7 @@ public function fitTransform() : void $this->assertCount(5, $sample); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Transformers/HotDeckImputerTest.php b/tests/Transformers/HotDeckImputerTest.php index e11d5a5d0..9d5db144c 100644 --- a/tests/Transformers/HotDeckImputerTest.php +++ b/tests/Transformers/HotDeckImputerTest.php @@ -1,60 +1,38 @@ generator = new Blob([30.0, 0.0]); + $this->generator = new Blob(center: [30.0, 0.0]); - $this->transformer = new HotDeckImputer(2, true, '?'); + $this->transformer = new HotDeckImputer(k: 2, weighted: true, categoricalPlaceholder: '?'); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(HotDeckImputer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [30, 0.001], [NAN, 0.055], [50, -2.0], diff --git a/tests/Transformers/ImageResizerTest.php b/tests/Transformers/ImageResizerTest.php index 63816c15c..f573dc777 100644 --- a/tests/Transformers/ImageResizerTest.php +++ b/tests/Transformers/ImageResizerTest.php @@ -1,45 +1,29 @@ transformer = new ImageResizer(32, 32); - } + protected ImageResizer $transformer; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(ImageResizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); + $this->transformer = new ImageResizer(width: 32, height: 32); } - /** - * @test - */ - public function transform() : void + public function testTransform() : void { $dataset = Unlabeled::quick([ [imagecreatefrompng('./tests/test.png'), 'whatever', 69], diff --git a/tests/Transformers/ImageRotatorTest.php b/tests/Transformers/ImageRotatorTest.php index 10ccd5bef..c7341ddbc 100644 --- a/tests/Transformers/ImageRotatorTest.php +++ b/tests/Transformers/ImageRotatorTest.php @@ -1,45 +1,29 @@ transformer = new ImageRotator(0.0, 1.0); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ImageRotator::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); + $this->transformer = new ImageRotator(offset: 0.0, jitter: 1.0); } - /** - * @test - */ - public function transform() : void + public function testTransform() : void { $dataset = Unlabeled::quick([ [imagecreatefrompng('./tests/test.png'), 'whatever', 69], diff --git a/tests/Transformers/ImageVectorizerTest.php b/tests/Transformers/ImageVectorizerTest.php index 666bc08f7..bc80842d2 100644 --- a/tests/Transformers/ImageVectorizerTest.php +++ b/tests/Transformers/ImageVectorizerTest.php @@ -1,48 +1,30 @@ transformer = new ImageVectorizer(false); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ImageVectorizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { $dataset = Unlabeled::quick([ [imagecreatefrompng('tests/test.png'), 'something else'], diff --git a/tests/Transformers/IntervalDiscretizerTest.php b/tests/Transformers/IntervalDiscretizerTest.php index 36db24ac4..c98d84327 100644 --- a/tests/Transformers/IntervalDiscretizerTest.php +++ b/tests/Transformers/IntervalDiscretizerTest.php @@ -1,54 +1,35 @@ generator = new Blob([0.0, 4.0, 0.0, -1.5], [1.0, 5.0, 0.01, 10.0]); + protected Blob $generator; - $this->transformer = new IntervalDiscretizer(5, false); - } + protected IntervalDiscretizer $transformer; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(IntervalDiscretizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); + $this->generator = new Blob( + center: [0.0, 4.0, 0.0, -1.5], + stdDev: [1.0, 5.0, 0.01, 10.0] + ); + + $this->transformer = new IntervalDiscretizer(bins: 5, equiWidth: false); } - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { $dataset = $this->generator->generate(30); @@ -60,7 +41,7 @@ public function fitTransform() : void $this->assertIsArray($intervals); $this->assertCount(4, $intervals); - $this->assertContainsOnly('array', $intervals); + $this->assertContainsOnlyArray($intervals); $sample = $this->generator->generate(1) ->apply($this->transformer) @@ -76,10 +57,7 @@ public function fitTransform() : void $this->assertContains($sample[3], $expected); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Transformers/KNNImputerTest.php b/tests/Transformers/KNNImputerTest.php index c22c6c04c..17d6e3ddc 100644 --- a/tests/Transformers/KNNImputerTest.php +++ b/tests/Transformers/KNNImputerTest.php @@ -1,60 +1,38 @@ generator = new Blob([30.0, 0.0]); + $this->generator = new Blob(center: [30.0, 0.0]); - $this->transformer = new KNNImputer(2, true, '?'); + $this->transformer = new KNNImputer(k: 2, weighted: true, categoricalPlaceholder: '?'); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(KNNImputer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [30, 0.001], [NAN, 0.055], [50, -2.0], diff --git a/tests/Transformers/L1NormalizerTest.php b/tests/Transformers/L1NormalizerTest.php index 7a76d6432..e9be89349 100644 --- a/tests/Transformers/L1NormalizerTest.php +++ b/tests/Transformers/L1NormalizerTest.php @@ -1,46 +1,29 @@ transformer = new L1Normalizer(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(L1Normalizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - } - - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [1, 2, 3, 4], [40, 0, 30, 10], [100, 300, 200, 400], diff --git a/tests/Transformers/L2NormalizerTest.php b/tests/Transformers/L2NormalizerTest.php index d3baea515..369364451 100644 --- a/tests/Transformers/L2NormalizerTest.php +++ b/tests/Transformers/L2NormalizerTest.php @@ -1,46 +1,29 @@ transformer = new L2Normalizer(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(L2Normalizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - } - - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [1, 2, 3, 4], [40, 0, 30, 10], [100, 300, 200, 400], diff --git a/tests/Transformers/LambdaFunctionTest.php b/tests/Transformers/LambdaFunctionTest.php index 5750a6224..7d5ddafc1 100644 --- a/tests/Transformers/LambdaFunctionTest.php +++ b/tests/Transformers/LambdaFunctionTest.php @@ -1,50 +1,33 @@ transformer = new LambdaFunction($callback, 'context'); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LambdaFunction::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); + $this->transformer = new LambdaFunction(callback: $callback, context: 'context'); } - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [1, 2, 3, 4], [40, 20, 30, 10], [100, 300, 200, 400], diff --git a/tests/Transformers/LinearDiscriminantAnalysisTest.php b/tests/Transformers/LinearDiscriminantAnalysisTest.php index 3e240a926..083933790 100644 --- a/tests/Transformers/LinearDiscriminantAnalysisTest.php +++ b/tests/Transformers/LinearDiscriminantAnalysisTest.php @@ -1,60 +1,42 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 0, 0], 30.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 0, 255], 20.0), - ], [3, 4, 3]); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob(center: [255, 0, 0], stdDev: 30.0), + 'green' => new Blob(center: [0, 128, 0], stdDev: 10.0), + 'blue' => new Blob(center: [0, 0, 255], stdDev: 20.0), + ], + weights: [3, 4, 3] + ); $this->transformer = new LinearDiscriminantAnalysis(1); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(LinearDiscriminantAnalysis::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { $dataset = $this->generator->generate(30); @@ -69,10 +51,7 @@ public function fitTransform() : void $this->assertCount(1, $sample); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Transformers/MaxAbsoluteScalerTest.php b/tests/Transformers/MaxAbsoluteScalerTest.php index 094230c2c..941d320de 100644 --- a/tests/Transformers/MaxAbsoluteScalerTest.php +++ b/tests/Transformers/MaxAbsoluteScalerTest.php @@ -1,60 +1,36 @@ generator = new Blob([0.0, 3000.0, -6.0], [1.0, 30.0, 0.001]); + $this->generator = new Blob( + center: [0.0, 3000.0, -6.0], + stdDev: [1.0, 30.0, 0.001] + ); $this->transformer = new MaxAbsoluteScaler(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MaxAbsoluteScaler::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - $this->assertInstanceOf(Elastic::class, $this->transformer); - $this->assertInstanceOf(Reversible::class, $this->transformer); - $this->assertInstanceOf(Persistable::class, $this->transformer); - } - - /** - * @test - */ - public function fitUpdateTransformReverse() : void + public function testFitUpdateTransformReverse() : void { $this->transformer->fit($this->generator->generate(30)); @@ -86,10 +62,7 @@ public function fitUpdateTransformReverse() : void $this->assertEqualsWithDelta($original, $dataset->sample(0), 1e-8); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); @@ -98,10 +71,7 @@ public function transformUnfitted() : void $this->transformer->transform($samples); } - /** - * @test - */ - public function reverseTransformUnfitted() : void + public function testReverseTransformUnfitted() : void { $this->expectException(RuntimeException::class); @@ -110,12 +80,11 @@ public function reverseTransformUnfitted() : void $this->transformer->reverseTransform($samples); } - /** - * @test - */ - public function skipsNonFinite(): void + public function testSkipsNonFinite() : void { - $samples = Unlabeled::build([[0.0, 3000.0, NAN, -6.0], [1.0, 30.0, NAN, 0.001]]); + $samples = Unlabeled::build(samples: [ + [0.0, 3000.0, NAN, -6.0], [1.0, 30.0, NAN, 0.001] + ]); $this->transformer->fit($samples); $this->assertNan($samples[0][2]); $this->assertNan($samples[1][2]); diff --git a/tests/Transformers/MinMaxNormalizerTest.php b/tests/Transformers/MinMaxNormalizerTest.php index 8b8848e45..d427a3485 100644 --- a/tests/Transformers/MinMaxNormalizerTest.php +++ b/tests/Transformers/MinMaxNormalizerTest.php @@ -1,60 +1,36 @@ generator = new Blob([0.0, 3000.0, -6.0, 1.0], [1.0, 30.0, 0.001, 0.0]); + protected Blob $generator; - $this->transformer = new MinMaxNormalizer(0.0, 1.0); - } + protected MinMaxNormalizer $transformer; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(MinMaxNormalizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - $this->assertInstanceOf(Elastic::class, $this->transformer); - $this->assertInstanceOf(Reversible::class, $this->transformer); - $this->assertInstanceOf(Persistable::class, $this->transformer); + $this->generator = new Blob( + center: [0.0, 3000.0, -6.0, 1.0], + stdDev: [1.0, 30.0, 0.001, 0.0] + ); + + $this->transformer = new MinMaxNormalizer(min: 0.0, max: 1.0); } - /** - * @test - */ - public function fitUpdateTransformReverse() : void + public function testFitUpdateTransformReverse() : void { $this->transformer->fit($this->generator->generate(30)); @@ -91,10 +67,7 @@ public function fitUpdateTransformReverse() : void $this->assertEqualsWithDelta($original, $dataset->sample(0), 1e-8); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); @@ -103,12 +76,11 @@ public function transformUnfitted() : void $this->transformer->transform($samples); } - /** - * @test - */ - public function skipsNonFinite(): void + public function testSkipsNonFinite() : void { - $samples = Unlabeled::build([[0.0, 3000.0, NAN, -6.0], [1.0, 30.0, NAN, 0.001]]); + $samples = Unlabeled::build(samples: [ + [0.0, 3000.0, NAN, -6.0], [1.0, 30.0, NAN, 0.001] + ]); $this->transformer->fit($samples); $this->assertNan($samples[0][2]); $this->assertNan($samples[1][2]); diff --git a/tests/Transformers/MissingDataImputerTest.php b/tests/Transformers/MissingDataImputerTest.php index b2e2c4e5d..834c1379b 100644 --- a/tests/Transformers/MissingDataImputerTest.php +++ b/tests/Transformers/MissingDataImputerTest.php @@ -1,50 +1,35 @@ transformer = new MissingDataImputer(new Mean(), new KMostFrequent(), '?'); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MissingDataImputer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); + $this->transformer = new MissingDataImputer( + continuous: new Mean(), + categorical: new KMostFrequent(), + categoricalPlaceholder: '?' + ); } - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [30, 'friendly'], [NAN, 'mean'], [50, 'friendly'], diff --git a/tests/Transformers/MultibyteTextNormalizerTest.php b/tests/Transformers/MultibyteTextNormalizerTest.php index 61607457a..ed6413d9d 100644 --- a/tests/Transformers/MultibyteTextNormalizerTest.php +++ b/tests/Transformers/MultibyteTextNormalizerTest.php @@ -1,51 +1,31 @@ transformer = new MultibyteTextNormalizer(false); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(MultibyteTextNormalizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - } - - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = Unlabeled::quick([ + $dataset = Unlabeled::quick(samples: [ ['The quick brown fox jumped over the lazy man sitting at a bus' . ' stop drinking a can of Coke'], ['with a Dandy umbrella'], diff --git a/tests/Transformers/NumericStringConverterTest.php b/tests/Transformers/NumericStringConverterTest.php index 1bd17c4f2..ee2f93b49 100644 --- a/tests/Transformers/NumericStringConverterTest.php +++ b/tests/Transformers/NumericStringConverterTest.php @@ -1,48 +1,29 @@ transformer = new NumericStringConverter(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(NumericStringConverter::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Reversible::class, $this->transformer); - } - - /** - * @test - */ - public function transformReverse() : void + public function testTransformReverse() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ ['1', '2', 3, 4, 'NAN'], ['4.0', '2.0', 3.0, 1.0, 'INF'], ['100', '3.0', 200, 2.5, '-INF'], diff --git a/tests/Transformers/OneHotEncoderTest.php b/tests/Transformers/OneHotEncoderTest.php index 583afb980..ab94110bb 100644 --- a/tests/Transformers/OneHotEncoderTest.php +++ b/tests/Transformers/OneHotEncoderTest.php @@ -1,48 +1,29 @@ transformer = new OneHotEncoder(); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(OneHotEncoder::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ ['nice', 'furry', 'friendly'], ['mean', 'furry', 'loner'], ['nice', 'rough', 'friendly'], @@ -57,7 +38,7 @@ public function fitTransform() : void $this->assertIsArray($categories); $this->assertCount(3, $categories); - $this->assertContainsOnly('array', $categories); + $this->assertContainsOnlyArray($categories); $dataset->apply($this->transformer); diff --git a/tests/Transformers/PolynomialExpanderTest.php b/tests/Transformers/PolynomialExpanderTest.php index 667f964bc..4c19eba25 100644 --- a/tests/Transformers/PolynomialExpanderTest.php +++ b/tests/Transformers/PolynomialExpanderTest.php @@ -1,46 +1,29 @@ transformer = new PolynomialExpander(2); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(PolynomialExpander::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - } - - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [1, 2, 3, 4], [40, 20, 30, 10], [100, 300, 200, 400], diff --git a/tests/Transformers/PrincipalComponentAnalysisTest.php b/tests/Transformers/PrincipalComponentAnalysisTest.php index beb3cc935..5854c87e6 100644 --- a/tests/Transformers/PrincipalComponentAnalysisTest.php +++ b/tests/Transformers/PrincipalComponentAnalysisTest.php @@ -1,55 +1,37 @@ generator = new Blob([0.0, 3000.0, -6.0, 25], [1.0, 30.0, 0.001, 10.0]); + $this->generator = new Blob( + center: [0.0, 3000.0, -6.0, 25], + stdDev: [1.0, 30.0, 0.001, 10.0] + ); $this->transformer = new PrincipalComponentAnalysis(2); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(PrincipalComponentAnalysis::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { $this->assertEquals(4, $this->generator->dimensions()); @@ -64,10 +46,7 @@ public function fitTransform() : void $this->assertCount(2, $sample); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Transformers/RegexFilterTest.php b/tests/Transformers/RegexFilterTest.php index 4f9fce61f..8e12193a6 100644 --- a/tests/Transformers/RegexFilterTest.php +++ b/tests/Transformers/RegexFilterTest.php @@ -1,26 +1,21 @@ transformer = new RegexFilter([ @@ -35,19 +30,7 @@ protected function setUp() : void ]); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RegexFilter::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - } - - /** - * @test - */ - public function transform() : void + public function testTransform() : void { $dataset = Unlabeled::quick([ ['I was not proud of what I had learned, but I never doubted that it was worth $$$ knowing..'], diff --git a/tests/Transformers/RobustStandardizerTest.php b/tests/Transformers/RobustStandardizerTest.php index c706d9bfc..b9370eb0f 100644 --- a/tests/Transformers/RobustStandardizerTest.php +++ b/tests/Transformers/RobustStandardizerTest.php @@ -1,58 +1,35 @@ generator = new Blob([0.0, 3000.0, -6.0], [1.0, 30.0, 0.001]); + $this->generator = new Blob( + center: [0.0, 3000.0, -6.0], + stdDev: [1.0, 30.0, 0.001] + ); $this->transformer = new RobustStandardizer(true); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(RobustStandardizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - $this->assertInstanceOf(Reversible::class, $this->transformer); - $this->assertInstanceOf(Persistable::class, $this->transformer); - } - - /** - * @test - */ - public function fitUpdateTransformReverse() : void + public function testFitUpdateTransformReverse() : void { $this->transformer->fit($this->generator->generate(30)); @@ -62,13 +39,13 @@ public function fitUpdateTransformReverse() : void $this->assertIsArray($medians); $this->assertCount(3, $medians); - $this->assertContainsOnly('float', $medians); + $this->assertContainsOnlyFloat($medians); $mads = $this->transformer->mads(); $this->assertIsArray($mads); $this->assertCount(3, $mads); - $this->assertContainsOnly('float', $mads); + $this->assertContainsOnlyFloat($mads); $dataset = $this->generator->generate(1); @@ -89,10 +66,7 @@ public function fitUpdateTransformReverse() : void $this->assertEqualsWithDelta($original, $dataset->sample(0), 1e-8); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Transformers/SparseRandomProjectorTest.php b/tests/Transformers/SparseRandomProjectorTest.php index 15442dbb8..226aba047 100644 --- a/tests/Transformers/SparseRandomProjectorTest.php +++ b/tests/Transformers/SparseRandomProjectorTest.php @@ -1,63 +1,42 @@ generator = new Blob(array_fill(0, 10, 0.0), 3.0); + $this->generator = new Blob( + center: array_fill(start_index: 0, count: 10, value: 0.0), + stdDev: 3.0 + ); - $this->transformer = new SparseRandomProjector(4); + $this->transformer = new SparseRandomProjector(dimensions: 4); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(SparseRandomProjector::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { $this->assertCount(10, $this->generator->generate(1)->sample(0)); @@ -80,10 +59,7 @@ public function fitTransform() : void $this->assertEqualsWithDelta($expected, $sample, 1e-8); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Transformers/StopWordFilterTest.php b/tests/Transformers/StopWordFilterTest.php index 4d0b24360..245cab7c7 100644 --- a/tests/Transformers/StopWordFilterTest.php +++ b/tests/Transformers/StopWordFilterTest.php @@ -1,46 +1,29 @@ transformer = new StopWordFilter(['a', 'quick', 'pig', 'à']); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(StopWordFilter::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - } - - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = Unlabeled::quick([ + $dataset = Unlabeled::quick(samples: [ ['the quick brown fox jumped over the lazy man sitting at a bus' . ' stop drinking a can of coke'], ['with a dandy umbrella'], diff --git a/tests/Transformers/TSNETest.php b/tests/Transformers/TSNETest.php index 1be227636..880b267f2 100644 --- a/tests/Transformers/TSNETest.php +++ b/tests/Transformers/TSNETest.php @@ -1,8 +1,11 @@ generator = new Agglomerate([ - 'red' => new Blob([255, 32, 0], 30.0), - 'green' => new Blob([0, 128, 0], 10.0), - 'blue' => new Blob([0, 32, 255], 20.0), - ], [2, 3, 4]); - - $this->embedder = new TSNE(1, 10.0, 10, 12.0, 500, 1e-7, 10, new Euclidean()); + $this->generator = new Agglomerate( + generators: [ + 'red' => new Blob([255, 32, 0], 30.0), + 'green' => new Blob([0, 128, 0], 10.0), + 'blue' => new Blob([0, 32, 255], 20.0), + ], + weights: [2, 3, 4] + ); + + $this->embedder = new TSNE( + dimensions: 1, + rate: 10.0, + perplexity: 10, + exaggeration: 12.0, + epochs: 500, + minGradient: 1e-7, + window: 10, + kernel: new Euclidean() + ); $this->embedder->setLogger(new BlackHole()); srand(self::RANDOM_SEED); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(TSNE::class, $this->embedder); - $this->assertInstanceOf(Verbose::class, $this->embedder); - } - - /** - * @test - */ - public function badNumDimensions() : void + public function testBadNumDimensions() : void { $this->expectException(InvalidArgumentException::class); - new TSNE(0); + new TSNE(dimensions: 0); } - /** - * @test - */ - public function compatibility() : void + public function testCompatibility() : void { $expected = [ DataType::continuous(), @@ -91,10 +76,7 @@ public function compatibility() : void $this->assertEquals($expected, $this->embedder->compatibility()); } - /** - * @test - */ - public function transform() : void + public function testTransform() : void { $dataset = $this->generator->generate(self::TEST_SIZE); @@ -106,6 +88,6 @@ public function transform() : void $losses = $this->embedder->losses(); $this->assertIsArray($losses); - $this->assertContainsOnly('float', $losses); + $this->assertContainsOnlyFloat($losses); } } diff --git a/tests/Transformers/TextNormalizerTest.php b/tests/Transformers/TextNormalizerTest.php index ad294ec06..3676dc70a 100644 --- a/tests/Transformers/TextNormalizerTest.php +++ b/tests/Transformers/TextNormalizerTest.php @@ -1,46 +1,29 @@ transformer = new TextNormalizer(true); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(TextNormalizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - } - - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = Unlabeled::quick([ + $dataset = Unlabeled::quick(samples: [ ['The quick brown fox jumped over the lazy man sitting at a bus' . ' stop drinking a can of Coke'], ['with a Dandy umbrella'], diff --git a/tests/Transformers/TfIdfTransformerTest.php b/tests/Transformers/TfIdfTransformerTest.php index c0bd998ac..4dec02794 100644 --- a/tests/Transformers/TfIdfTransformerTest.php +++ b/tests/Transformers/TfIdfTransformerTest.php @@ -1,54 +1,29 @@ transformer = new TfIdfTransformer(1.0, false); - } + protected TfIdfTransformer $transformer; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(TfIdfTransformer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - $this->assertInstanceOf(Elastic::class, $this->transformer); - $this->assertInstanceOf(Reversible::class, $this->transformer); - $this->assertInstanceOf(Persistable::class, $this->transformer); + $this->transformer = new TfIdfTransformer(smoothing: 1.0, sublinear: false); } - /** - * @test - */ - public function fitTransformReverse() : void + public function testFitTransformReverse() : void { - $dataset = new Unlabeled([ + $dataset = new Unlabeled(samples: [ [1, 3, 0, 0, 1, 0, 0, 0, 1, 2, 0, 2, 0, 0, 0, 4, 1, 0, 1], [0, 1, 1, 0, 0, 2, 1, 0, 0, 0, 0, 3, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 2, 3, 0, 0, 4, 2, 0, 0, 1, 0, 2, 0, 1, 0, 0], @@ -62,7 +37,7 @@ public function fitTransformReverse() : void $this->assertIsArray($dfs); $this->assertCount(19, $dfs); - $this->assertContainsOnly('int', $dfs); + $this->assertContainsOnlyInt($dfs); $original = clone $dataset; diff --git a/tests/Transformers/TokenHashingVectorizerTest.php b/tests/Transformers/TokenHashingVectorizerTest.php index b17fbf202..cd8f7201c 100644 --- a/tests/Transformers/TokenHashingVectorizerTest.php +++ b/tests/Transformers/TokenHashingVectorizerTest.php @@ -1,47 +1,34 @@ transformer = new TokenHashingVectorizer(20, new Word(), 'crc32'); - } + protected TokenHashingVectorizer $transformer; - /** - * @test - */ - public function build() : void + protected function setUp() : void { - $this->assertInstanceOf(TokenHashingVectorizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); + $this->transformer = new TokenHashingVectorizer( + dimensions: 20, + tokenizer: new Word(), + hashFn: 'crc32' + ); } - /** - * @test - */ - public function transform() : void + public function testTransform() : void { - $dataset = Unlabeled::quick([ + $dataset = Unlabeled::quick(samples: [ ['the quick brown fox jumped over the lazy man sitting at a bus stop drinking a can of coke'], ['with a dandy umbrella'], ]); diff --git a/tests/Transformers/TruncatedSVDTest.php b/tests/Transformers/TruncatedSVDTest.php index 97662ad5d..1a7c64f43 100644 --- a/tests/Transformers/TruncatedSVDTest.php +++ b/tests/Transformers/TruncatedSVDTest.php @@ -1,55 +1,37 @@ generator = new Blob([0.0, 3000.0, -6.0, 25], [1.0, 30.0, 0.001, 10.0]); + $this->generator = new Blob( + center: [0.0, 3000.0, -6.0, 25], + stdDev: [1.0, 30.0, 0.001, 10.0] + ); $this->transformer = new TruncatedSVD(2); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(TruncatedSVD::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - } - - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { $this->assertEquals(4, $this->generator->dimensions()); @@ -64,10 +46,7 @@ public function fitTransform() : void $this->assertCount(2, $sample); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class); diff --git a/tests/Transformers/WordCountVectorizerTest.php b/tests/Transformers/WordCountVectorizerTest.php index af0ec88bd..071e245d3 100644 --- a/tests/Transformers/WordCountVectorizerTest.php +++ b/tests/Transformers/WordCountVectorizerTest.php @@ -1,49 +1,35 @@ transformer = new WordCountVectorizer(50, 1, 1.0, new Word()); - } - - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(WordCountVectorizer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); + $this->transformer = new WordCountVectorizer( + maxVocabularySize: 50, + minDocumentCount: 1, + maxDocumentRatio: 1.0, + tokenizer: new Word() + ); } - /** - * @test - */ - public function fitTransform() : void + public function testFitTransform() : void { - $dataset = Unlabeled::quick([ + $dataset = Unlabeled::quick(samples: [ ['the quick brown fox jumped over the lazy man sitting at a bus stop drinking a can of coke'], ['with a dandy umbrella'], ]); @@ -56,7 +42,7 @@ public function fitTransform() : void $this->assertIsArray($vocabulary); $this->assertCount(20, $vocabulary); - $this->assertContainsOnly('string', $vocabulary); + $this->assertContainsOnlyString($vocabulary); $dataset->apply($this->transformer); diff --git a/tests/Transformers/ZScaleStandardizerTest.php b/tests/Transformers/ZScaleStandardizerTest.php index f3fe76cd8..5a72f4df3 100644 --- a/tests/Transformers/ZScaleStandardizerTest.php +++ b/tests/Transformers/ZScaleStandardizerTest.php @@ -1,60 +1,35 @@ generator = new Blob([0.0, 3000.0, -6.0], [1.0, 30.0, 0.001]); + $this->generator = new Blob( + center: [0.0, 3000.0, -6.0], + stdDev: [1.0, 30.0, 0.001] + ); $this->transformer = new ZScaleStandardizer(true); } - /** - * @test - */ - public function build() : void - { - $this->assertInstanceOf(ZScaleStandardizer::class, $this->transformer); - $this->assertInstanceOf(Transformer::class, $this->transformer); - $this->assertInstanceOf(Stateful::class, $this->transformer); - $this->assertInstanceOf(Elastic::class, $this->transformer); - $this->assertInstanceOf(Reversible::class, $this->transformer); - $this->assertInstanceOf(Persistable::class, $this->transformer); - } - - /** - * @test - */ - public function fitUpdateTransformReverse() : void + public function testFitUpdateTransformReverse() : void { $this->transformer->fit($this->generator->generate(30)); @@ -66,13 +41,13 @@ public function fitUpdateTransformReverse() : void $this->assertIsArray($means); $this->assertCount(3, $means); - $this->assertContainsOnly('float', $means); + $this->assertContainsOnlyFloat($means); $variances = $this->transformer->variances(); $this->assertIsArray($variances); $this->assertCount(3, $variances); - $this->assertContainsOnly('float', $variances); + $this->assertContainsOnlyFloat($variances); $dataset = $this->generator->generate(1); @@ -93,10 +68,7 @@ public function fitUpdateTransformReverse() : void $this->assertEqualsWithDelta($original, $dataset->sample(0), 1e-8); } - /** - * @test - */ - public function transformUnfitted() : void + public function testTransformUnfitted() : void { $this->expectException(RuntimeException::class);