From a348111e97ae89e2c969835e5671555230bdd2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Votruba?= Date: Sat, 6 Jan 2018 13:09:33 +0100 Subject: [PATCH] Add PHPStan and level to max (#168) * tests: update to PHPUnit 6.0 with rector * fix namespaces on tests * composer + tests: use standard test namespace naming * update travis * resolve conflict * phpstan lvl 2 * phpstan lvl 3 * phpstan lvl 4 * phpstan lvl 5 * phpstan lvl 6 * phpstan lvl 7 * level max * resolve conflict * [cs] clean empty docs * composer: bump to PHPUnit 6.4 * cleanup * composer + travis: add phpstan * phpstan lvl 1 * composer: update dev deps * phpstan fixes * update Contributing with new tools * docs: link fixes, PHP version update * composer: drop php-cs-fixer, cs already handled by ecs * ecs: add old set rules * [cs] apply rest of rules --- .php_cs | 32 --- .travis.yml | 1 + CONTRIBUTING.md | 27 ++- composer.json | 23 ++- composer.lock | 184 ++++++++++-------- docs/index.md | 68 +++---- easy-coding-standard.neon | 19 ++ phpstan.neon | 19 ++ src/Phpml/Association/Apriori.php | 1 + src/Phpml/Classification/DecisionTree.php | 8 +- .../DecisionTree/DecisionTreeLeaf.php | 4 +- src/Phpml/Classification/Ensemble/Bagging.php | 2 +- src/Phpml/Classification/Linear/Adaline.php | 2 +- .../Classification/Linear/DecisionStump.php | 2 +- .../Linear/LogisticRegression.php | 16 +- .../Classification/Linear/Perceptron.php | 10 +- src/Phpml/Clustering/KMeans/Point.php | 3 + src/Phpml/Clustering/KMeans/Space.php | 5 +- src/Phpml/DimensionReduction/KernelPCA.php | 2 +- .../TokenCountVectorizer.php | 2 +- src/Phpml/Helper/OneVsRest.php | 2 +- src/Phpml/Helper/Optimizer/GD.php | 4 +- src/Phpml/Helper/Optimizer/StochasticGD.php | 6 +- .../LinearAlgebra/EigenvalueDecomposition.php | 2 + .../Math/LinearAlgebra/LUDecomposition.php | 4 +- src/Phpml/Math/Set.php | 6 +- src/Phpml/Metric/ClassificationReport.php | 1 + .../Network/MultilayerPerceptron.php | 9 +- src/Phpml/NeuralNetwork/Node/Neuron.php | 10 +- .../Training/Backpropagation.php | 8 +- src/Phpml/Preprocessing/Imputer.php | 3 +- .../SupportVectorMachine/DataTransformer.php | 2 + .../SupportVectorMachine.php | 2 +- tests/Phpml/Association/AprioriTest.php | 6 +- .../DecisionTree/DecisionTreeLeafTest.php | 2 +- .../Phpml/Classification/DecisionTreeTest.php | 2 +- .../Classification/Ensemble/AdaBoostTest.php | 2 +- .../Classification/Ensemble/BaggingTest.php | 2 +- .../Ensemble/RandomForestTest.php | 3 +- .../Classification/KNearestNeighborsTest.php | 2 +- .../Classification/Linear/AdalineTest.php | 2 +- .../Linear/DecisionStumpTest.php | 2 +- .../Classification/Linear/PerceptronTest.php | 2 +- .../Classification/MLPClassifierTest.php | 2 +- tests/Phpml/Classification/NaiveBayesTest.php | 2 +- tests/Phpml/Classification/SVCTest.php | 2 +- tests/Phpml/Clustering/DBSCANTest.php | 2 +- tests/Phpml/Clustering/FuzzyCMeansTest.php | 2 +- tests/Phpml/Clustering/KMeansTest.php | 2 +- .../Phpml/CrossValidation/RandomSplitTest.php | 2 +- .../StratifiedRandomSplitTest.php | 2 +- tests/Phpml/Dataset/ArrayDatasetTest.php | 2 +- tests/Phpml/Dataset/CsvDatasetTest.php | 2 +- tests/Phpml/Dataset/Demo/GlassDatasetTest.php | 2 +- tests/Phpml/Dataset/Demo/IrisDatasetTest.php | 2 +- tests/Phpml/Dataset/Demo/WineDatasetTest.php | 2 +- tests/Phpml/Dataset/FilesDatasetTest.php | 2 +- .../DimensionReduction/KernelPCATest.php | 2 +- tests/Phpml/DimensionReduction/LDATest.php | 2 +- tests/Phpml/DimensionReduction/PCATest.php | 2 +- .../Phpml/FeatureExtraction/StopWordsTest.php | 2 +- .../TfIdfTransformerTest.php | 2 +- .../TokenCountVectorizerTest.php | 2 +- tests/Phpml/Math/ComparisonTest.php | 6 +- tests/Phpml/Math/Distance/ChebyshevTest.php | 2 +- tests/Phpml/Math/Distance/EuclideanTest.php | 2 +- tests/Phpml/Math/Distance/ManhattanTest.php | 2 +- tests/Phpml/Math/Distance/MinkowskiTest.php | 2 +- tests/Phpml/Math/Kernel/RBFTest.php | 2 +- .../LinearAlgebra/EigenDecompositionTest.php | 2 +- tests/Phpml/Math/MatrixTest.php | 2 +- tests/Phpml/Math/ProductTest.php | 2 +- tests/Phpml/Math/SetTest.php | 2 +- .../Phpml/Math/Statistic/CorrelationTest.php | 2 +- tests/Phpml/Math/Statistic/CovarianceTest.php | 2 +- tests/Phpml/Math/Statistic/GaussianTest.php | 2 +- tests/Phpml/Math/Statistic/MeanTest.php | 2 +- .../Math/Statistic/StandardDeviationTest.php | 2 +- tests/Phpml/Metric/AccuracyTest.php | 2 +- .../Phpml/Metric/ClassificationReportTest.php | 2 +- tests/Phpml/Metric/ConfusionMatrixTest.php | 2 +- tests/Phpml/ModelManagerTest.php | 2 +- .../ActivationFunction/BinaryStepTest.php | 2 +- .../ActivationFunction/GaussianTest.php | 2 +- .../HyperboliTangentTest.php | 2 +- .../ActivationFunction/PReLUTest.php | 2 +- .../ActivationFunction/SigmoidTest.php | 2 +- .../ThresholdedReLUTest.php | 2 +- tests/Phpml/NeuralNetwork/LayerTest.php | 2 +- .../Network/LayeredNetworkTest.php | 8 +- tests/Phpml/NeuralNetwork/Node/BiasTest.php | 2 +- tests/Phpml/NeuralNetwork/Node/InputTest.php | 2 +- .../NeuralNetwork/Node/Neuron/SynapseTest.php | 6 +- tests/Phpml/NeuralNetwork/Node/NeuronTest.php | 3 +- tests/Phpml/PipelineTest.php | 2 +- tests/Phpml/Preprocessing/ImputerTest.php | 2 +- tests/Phpml/Preprocessing/NormalizerTest.php | 2 +- tests/Phpml/Regression/LeastSquaresTest.php | 2 +- tests/Phpml/Regression/SVRTest.php | 2 +- .../DataTransformerTest.php | 2 +- .../SupportVectorMachineTest.php | 2 +- .../Tokenization/WhitespaceTokenizerTest.php | 2 +- .../Phpml/Tokenization/WordTokenizerTest.php | 2 +- 103 files changed, 365 insertions(+), 284 deletions(-) delete mode 100644 .php_cs create mode 100644 phpstan.neon diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 9fb8baa..0000000 --- a/.php_cs +++ /dev/null @@ -1,32 +0,0 @@ -setRules([ - '@PSR2' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => ['align_double_arrow' => false, 'align_equals' => false], - 'blank_line_after_opening_tag' => true, - 'blank_line_before_return' => true, - 'cast_spaces' => true, - 'concat_space' => ['spacing' => 'none'], - 'declare_strict_types' => true, - 'method_separation' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_spaces_around_offset' => ['positions' => ['inside', 'outside']], - 'no_unneeded_control_parentheses' => true, - 'no_unused_imports' => true, - 'phpdoc_align' => true, - 'phpdoc_no_access' => true, - 'phpdoc_separation' => true, - 'pre_increment' => true, - 'single_quote' => true, - 'trim_array_spaces' => true, - 'single_blank_line_before_namespace' => true, - ]) - ->setFinder( - PhpCsFixer\Finder::create() - ->in(__DIR__ . '/src') - ->in(__DIR__ . '/tests') - ) - ->setRiskyAllowed(true) - ->setUsingCache(false); diff --git a/.travis.yml b/.travis.yml index 8f8a68b..bf26816 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ install: script: - vendor/bin/phpunit $PHPUNIT_FLAGS - if [[ $STATIC_ANALYSIS != "" ]]; then vendor/bin/ecs check src tests; fi + - if [[ $STATIC_ANALYSIS != "" ]]; then vendor/bin/phpstan.phar analyse src tests --level max --configuration phpstan.neon; fi after_success: - | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7d2f451..b2d5f9e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,31 +6,40 @@ code base clean, unified and future proof. ## Branch -You should only open pull requests against the master branch. +You should only open pull requests against the `master` branch. ## Unit-Tests Please try to add a test for your pull-request. You can run the unit-tests by calling: -``` -bin/phpunit +```bash +vendor/bin/phpunit ``` ## Travis -GitHub automatically run your pull request through Travis CI against PHP 7. -If you break the tests, I cannot merge your code, so please make sure that your code is working -before opening up a Pull-Request. +GitHub automatically run your pull request through Travis CI. +If you break the tests, I cannot merge your code, so please make sure that your code is working before opening up a Pull-Request. ## Merge Please allow me time to review your pull requests. I will give my best to review everything as fast as possible, but cannot always live up to my own expectations. -## Coding Standards +## Coding Standards & Static Analysis -When contributing code to PHP-ML, you must follow its coding standards. It's as easy as executing `./bin/php-cs-fixer fix` in root directory. +When contributing code to PHP-ML, you must follow its coding standards. To do that, just run: + +```bash +vendor/bin/ecs check src tests --fix +``` +[More about EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard) + +Code has to also pass static analysis by [PHPStan](https://github.com/phpstan/phpstan): + +```bash +vendor/bin/phpstan.phar analyse src tests --level max --configuration phpstan.neon +``` -More about PHP-CS-Fixer: [http://cs.sensiolabs.org/](http://cs.sensiolabs.org/) ## Documentation diff --git a/composer.json b/composer.json index 7b774f2..b08d6f8 100644 --- a/composer.json +++ b/composer.json @@ -11,19 +11,24 @@ "email": "arkadiusz.kondas@gmail.com" } ], - "autoload": { - "psr-4": { - "Phpml\\": "src/Phpml" - } - }, "require": { "php": "^7.1" }, "require-dev": { "phpunit/phpunit": "^6.4", - "friendsofphp/php-cs-fixer": "^2.4", - "symplify/easy-coding-standard": "dev-master as 2.5", - "symplify/coding-standard": "dev-master as 2.5", - "symplify/package-builder": "dev-master#3604bea as 2.5" + "symplify/easy-coding-standard": "v3.0.0-RC3", + "symplify/coding-standard": "v3.0.0-RC3", + "symplify/package-builder": "v3.0.0-RC3", + "phpstan/phpstan-shim": "^0.8" + }, + "autoload": { + "psr-4": { + "Phpml\\": "src/Phpml" + } + }, + "autoload-dev": { + "psr-4": { + "Phpml\\Tests\\": "tests/Phpml" + } } } diff --git a/composer.lock b/composer.lock index e10b2d8..4236a2d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "0b709f785c1e62498755f557e49e1ba4", + "content-hash": "032ab1160f58aff496453a86648f7012", "packages": [], "packages-dev": [ { @@ -247,16 +247,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v2.8.1", + "version": "v2.8.2", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "04f71e56e03ba2627e345e8c949c80dcef0e683e" + "reference": "b331701944cbe492e466d2b46b2880068803eb08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/04f71e56e03ba2627e345e8c949c80dcef0e683e", - "reference": "04f71e56e03ba2627e345e8c949c80dcef0e683e", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/b331701944cbe492e466d2b46b2880068803eb08", + "reference": "b331701944cbe492e466d2b46b2880068803eb08", "shasum": "" }, "require": { @@ -323,7 +323,7 @@ } ], "description": "A tool to automatically fix PHP code style", - "time": "2017-11-09T13:31:39+00:00" + "time": "2017-11-19T22:51:25+00:00" }, { "name": "gecko-packages/gecko-php-unit", @@ -1219,16 +1219,16 @@ }, { "name": "phpspec/prophecy", - "version": "v1.7.2", + "version": "1.7.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6" + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", "shasum": "" }, "require": { @@ -1240,7 +1240,7 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7" }, "type": "library", "extra": { @@ -1278,7 +1278,43 @@ "spy", "stub" ], - "time": "2017-09-04T11:05:03+00:00" + "time": "2017-11-24T13:59:53+00:00" + }, + { + "name": "phpstan/phpstan-shim", + "version": "0.8.5", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-shim.git", + "reference": "0b174a61fd99dea61f15ea6bd3bc424389f273d4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-shim/zipball/0b174a61fd99dea61f15ea6bd3bc424389f273d4", + "reference": "0b174a61fd99dea61f15ea6bd3bc424389f273d4", + "shasum": "" + }, + "require": { + "php": "~7.0" + }, + "provide": { + "phpstan/phpstan": "0.8" + }, + "bin": [ + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.8-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan Phar distribution", + "time": "2017-10-24T04:16:00+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1346,16 +1382,16 @@ }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "8ebba84e5bd74fc5fdeb916b38749016c7232f93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/8ebba84e5bd74fc5fdeb916b38749016c7232f93", + "reference": "8ebba84e5bd74fc5fdeb916b38749016c7232f93", "shasum": "" }, "require": { @@ -1389,7 +1425,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2017-11-24T15:00:59+00:00" }, { "name": "phpunit/php-text-template", @@ -2418,7 +2454,7 @@ }, { "name": "symfony/config", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/config.git", @@ -2480,16 +2516,16 @@ }, { "name": "symfony/console", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "099302cc53e57cbb7414fd9f3ace40e5e2767c0b" + "reference": "63cd7960a0a522c3537f6326706d7f3b8de65805" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/099302cc53e57cbb7414fd9f3ace40e5e2767c0b", - "reference": "099302cc53e57cbb7414fd9f3ace40e5e2767c0b", + "url": "https://api.github.com/repos/symfony/console/zipball/63cd7960a0a522c3537f6326706d7f3b8de65805", + "reference": "63cd7960a0a522c3537f6326706d7f3b8de65805", "shasum": "" }, "require": { @@ -2544,11 +2580,11 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-11-12T16:53:41+00:00" + "time": "2017-11-16T15:24:32+00:00" }, { "name": "symfony/debug", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", @@ -2604,7 +2640,7 @@ }, { "name": "symfony/dependency-injection", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", @@ -2674,7 +2710,7 @@ }, { "name": "symfony/event-dispatcher", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -2737,7 +2773,7 @@ }, { "name": "symfony/filesystem", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", @@ -2786,7 +2822,7 @@ }, { "name": "symfony/finder", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -2835,7 +2871,7 @@ }, { "name": "symfony/http-foundation", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", @@ -2888,16 +2924,16 @@ }, { "name": "symfony/http-kernel", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "371ed63691c1ee8749613a6b48cf0e0cfa2b01e7" + "reference": "a2a942172b742217ab2ccd9399494af2aa17c766" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/371ed63691c1ee8749613a6b48cf0e0cfa2b01e7", - "reference": "371ed63691c1ee8749613a6b48cf0e0cfa2b01e7", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/a2a942172b742217ab2ccd9399494af2aa17c766", + "reference": "a2a942172b742217ab2ccd9399494af2aa17c766", "shasum": "" }, "require": { @@ -2970,11 +3006,11 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2017-11-13T19:37:21+00:00" + "time": "2017-11-16T18:14:43+00:00" }, { "name": "symfony/options-resolver", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", @@ -3201,7 +3237,7 @@ }, { "name": "symfony/process", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/process.git", @@ -3250,7 +3286,7 @@ }, { "name": "symfony/stopwatch", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", @@ -3299,7 +3335,7 @@ }, { "name": "symfony/yaml", - "version": "v3.3.12", + "version": "v3.3.13", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", @@ -3354,16 +3390,16 @@ }, { "name": "symplify/coding-standard", - "version": "dev-master", + "version": "v3.0.0-RC3", "source": { "type": "git", "url": "https://github.com/Symplify/CodingStandard.git", - "reference": "309fd562066cdc86b81375ff080b1ee2f900778e" + "reference": "0a3958f1cb6ce733def98f3abdf52a4e6c723879" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Symplify/CodingStandard/zipball/309fd562066cdc86b81375ff080b1ee2f900778e", - "reference": "309fd562066cdc86b81375ff080b1ee2f900778e", + "url": "https://api.github.com/repos/Symplify/CodingStandard/zipball/0a3958f1cb6ce733def98f3abdf52a4e6c723879", + "reference": "0a3958f1cb6ce733def98f3abdf52a4e6c723879", "shasum": "" }, "require": { @@ -3382,6 +3418,11 @@ "symplify/package-builder": "^2.5|^3.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, "autoload": { "psr-4": { "Symplify\\CodingStandard\\": "src", @@ -3394,20 +3435,20 @@ "MIT" ], "description": "Set of Symplify rules for PHP_CodeSniffer.", - "time": "2017-11-16 00:38:24" + "time": "2017-11-18T01:05:00+00:00" }, { "name": "symplify/easy-coding-standard", - "version": "dev-master", + "version": "v3.0.0-RC3", "source": { "type": "git", "url": "https://github.com/Symplify/EasyCodingStandard.git", - "reference": "4bac5271050f063b4455bd870cc215e0db57ddf8" + "reference": "7f2e7728a184c72945da482b23eb05b796f6502c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Symplify/EasyCodingStandard/zipball/4bac5271050f063b4455bd870cc215e0db57ddf8", - "reference": "4bac5271050f063b4455bd870cc215e0db57ddf8", + "url": "https://api.github.com/repos/Symplify/EasyCodingStandard/zipball/7f2e7728a184c72945da482b23eb05b796f6502c", + "reference": "7f2e7728a184c72945da482b23eb05b796f6502c", "shasum": "" }, "require": { @@ -3440,6 +3481,11 @@ "bin/easy-coding-standard.php" ], "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, "autoload": { "psr-4": { "Symplify\\EasyCodingStandard\\": "src", @@ -3455,20 +3501,20 @@ "MIT" ], "description": "Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer.", - "time": "2017-11-16 15:36:21" + "time": "2017-11-18T14:13:17+00:00" }, { "name": "symplify/package-builder", - "version": "dev-master", + "version": "v3.0.0-RC3", "source": { "type": "git", "url": "https://github.com/Symplify/PackageBuilder.git", - "reference": "3604beadddfdee295b978d87475a834810a0ffd4" + "reference": "c86f75165ed2370563a9d4ff6604bbb24cffd5e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Symplify/PackageBuilder/zipball/3604beadddfdee295b978d87475a834810a0ffd4", - "reference": "3604beadddfdee295b978d87475a834810a0ffd4", + "url": "https://api.github.com/repos/Symplify/PackageBuilder/zipball/c86f75165ed2370563a9d4ff6604bbb24cffd5e5", + "reference": "c86f75165ed2370563a9d4ff6604bbb24cffd5e5", "shasum": "" }, "require": { @@ -3486,6 +3532,11 @@ "tracy/tracy": "^2.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, "autoload": { "psr-4": { "Symplify\\PackageBuilder\\": "src" @@ -3496,7 +3547,7 @@ "MIT" ], "description": "Dependency Injection, Console and Kernel toolkit for Symplify packages.", - "time": "2017-11-16T01:05:48+00:00" + "time": "2017-11-17T13:58:38+00:00" }, { "name": "theseer/tokenizer", @@ -3656,31 +3707,12 @@ "time": "2016-11-23T20:04:58+00:00" } ], - "aliases": [ - { - "alias": "2.5", - "alias_normalized": "2.5.0.0", - "version": "9999999-dev", - "package": "symplify/easy-coding-standard" - }, - { - "alias": "2.5", - "alias_normalized": "2.5.0.0", - "version": "9999999-dev", - "package": "symplify/coding-standard" - }, - { - "alias": "2.5", - "alias_normalized": "2.5.0.0", - "version": "9999999-dev", - "package": "symplify/package-builder" - } - ], + "aliases": [], "minimum-stability": "stable", "stability-flags": { - "symplify/easy-coding-standard": 20, - "symplify/coding-standard": 20, - "symplify/package-builder": 20 + "symplify/easy-coding-standard": 5, + "symplify/coding-standard": 5, + "symplify/package-builder": 5 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/docs/index.md b/docs/index.md index ef3a0e9..f817b0a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,11 +17,11 @@ Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library. -PHP-ML requires PHP >= 7.0. +PHP-ML requires PHP >= 7.1. Simple example of classification: ```php -require_once 'vendor/autoload.php'; +require_once __DIR__ . '/vendor/autoload.php'; use Phpml\Classification\KNearestNeighbors; @@ -54,57 +54,57 @@ Example scripts are available in a separate repository [php-ai/php-ml-examples]( ## Features * Association rule Lerning - * [Apriori](machine-learning/association/apriori/) + * [Apriori](machine-learning/association/apriori.md) * Classification - * [SVC](machine-learning/classification/svc/) - * [k-Nearest Neighbors](machine-learning/classification/k-nearest-neighbors/) - * [Naive Bayes](machine-learning/classification/naive-bayes/) + * [SVC](machine-learning/classification/svc.md) + * [k-Nearest Neighbors](machine-learning/classification/k-nearest-neighbors.md) + * [Naive Bayes](machine-learning/classification/naive-bayes.md) * Regression - * [Least Squares](machine-learning/regression/least-squares/) - * [SVR](machine-learning/regression/svr/) + * [Least Squares](machine-learning/regression/least-squares.md) + * [SVR](machine-learning/regression/svr.md) * Clustering - * [k-Means](machine-learning/clustering/k-means/) - * [DBSCAN](machine-learning/clustering/dbscan/) + * [k-Means](machine-learning/clustering/k-means.md) + * [DBSCAN](machine-learning/clustering/dbscan.md) * Metric - * [Accuracy](machine-learning/metric/accuracy/) - * [Confusion Matrix](machine-learning/metric/confusion-matrix/) - * [Classification Report](machine-learning/metric/classification-report/) + * [Accuracy](machine-learning/metric/accuracy.md) + * [Confusion Matrix](machine-learning/metric/confusion-matrix.md) + * [Classification Report](machine-learning/metric/classification-report.md) * Workflow * [Pipeline](machine-learning/workflow/pipeline) * Neural Network - * [Multilayer Perceptron Classifier](machine-learning/neural-network/multilayer-perceptron-classifier/) + * [Multilayer Perceptron Classifier](machine-learning/neural-network/multilayer-perceptron-classifier.md) * Cross Validation - * [Random Split](machine-learning/cross-validation/random-split/) - * [Stratified Random Split](machine-learning/cross-validation/stratified-random-split/) + * [Random Split](machine-learning/cross-validation/random-split.md) + * [Stratified Random Split](machine-learning/cross-validation/stratified-random-split.md) * Preprocessing - * [Normalization](machine-learning/preprocessing/normalization/) - * [Imputation missing values](machine-learning/preprocessing/imputation-missing-values/) + * [Normalization](machine-learning/preprocessing/normalization.md) + * [Imputation missing values](machine-learning/preprocessing/imputation-missing-values.md) * Feature Extraction - * [Token Count Vectorizer](machine-learning/feature-extraction/token-count-vectorizer/) - * [Tf-idf Transformer](machine-learning/feature-extraction/tf-idf-transformer/) + * [Token Count Vectorizer](machine-learning/feature-extraction/token-count-vectorizer.md) + * [Tf-idf Transformer](machine-learning/feature-extraction/tf-idf-transformer.md) * Datasets - * [Array](machine-learning/datasets/array-dataset/) - * [CSV](machine-learning/datasets/csv-dataset/) - * [Files](machine-learning/datasets/files-dataset/) + * [Array](machine-learning/datasets/array-dataset.md) + * [CSV](machine-learning/datasets/csv-dataset.md) + * [Files](machine-learning/datasets/files-dataset.md) * Ready to use: - * [Iris](machine-learning/datasets/demo/iris/) - * [Wine](machine-learning/datasets/demo/wine/) - * [Glass](machine-learning/datasets/demo/glass/) + * [Iris](machine-learning/datasets/demo/iris.md) + * [Wine](machine-learning/datasets/demo/wine.md) + * [Glass](machine-learning/datasets/demo/glass.md) * Models management - * [Persistency](machine-learning/model-manager/persistency/) + * [Persistency](machine-learning/model-manager/persistency.md) * Math - * [Distance](math/distance/) - * [Matrix](math/matrix/) - * [Set](math/set/) - * [Statistic](math/statistic/) + * [Distance](math/distance.md) + * [Matrix](math/matrix.md) + * [Set](math/set.md) + * [Statistic](math/statistic.md) ## Contribute -- Issue Tracker: github.com/php-ai/php-ml/issues -- Source Code: github.com/php-ai/php-ml +- Issue Tracker: [github.com/php-ai/php-ml/issues](https://github.com/php-ai/php-ml/issues) +- Source Code: [github.com/php-ai/php-ml](https://github.com/php-ai/php-ml) -You can find more about contributing in [CONTRIBUTING.md](CONTRIBUTING.md). +You can find more about contributing in [CONTRIBUTING.md](../CONTRIBUTING.md). ## License diff --git a/easy-coding-standard.neon b/easy-coding-standard.neon index 14d8770..9155b10 100644 --- a/easy-coding-standard.neon +++ b/easy-coding-standard.neon @@ -11,6 +11,25 @@ includes: #- vendor/symplify/easy-coding-standard/config/common/strict.neon checkers: + # spacing + - PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer + - PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer + - PhpCsFixer\Fixer\CastNotation\CastSpacesFixer + PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: + spacing: none + - PhpCsFixer\Fixer\ClassNotation\MethodSeparationFixer + - PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer + PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer: + positions: ['inside', 'outside'] + PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer: + align_double_arrow: false + align_equals: false + + # phpdoc + - PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer + - PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer + + # Symplify - Symplify\CodingStandard\Fixer\Import\ImportNamespacedNameFixer - Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer - Symplify\CodingStandard\Fixer\Property\ArrayPropertyDefaultValueFixer diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..19e3c20 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +parameters: + ignoreErrors: + - '#Phpml\\Dataset\\FilesDataset::__construct\(\) does not call parent constructor from Phpml\\Dataset\\ArrayDataset#' + - '#Parameter \#2 \$predictedLabels of static method Phpml\\Metric\\Accuracy::score\(\) expects mixed\[\], mixed\[\]\|string given#' + + # should be always defined + - '#Undefined variable: \$j#' + + # bugged + - '#expects [a-z\\\|\[\]]*, [a-z\\\|\(\)\[\]]*\[\] given#' + + # mock + - '#Parameter \#1 \$node of class Phpml\\NeuralNetwork\\Node\\Neuron\\Synapse constructor expects Phpml\\NeuralNetwork\\Node, Phpml\\NeuralNetwork\\Node\\Neuron\|PHPUnit_Framework_MockObject_MockObject given#' + - '#Parameter \#1 \$(activationFunction|synapse) of class Phpml\\NeuralNetwork\\Node\\Neuron constructor expects Phpml\\NeuralNetwork\\ActivationFunction|null, Phpml\\NeuralNetwork\\ActivationFunction\\BinaryStep|PHPUnit_Framework_MockObject_MockObject given#' + + # probably known value + - '#Method Phpml\\Classification\\DecisionTree::getBestSplit\(\) should return Phpml\\Classification\\DecisionTree\\DecisionTreeLeaf but returns Phpml\\Classification\\DecisionTree\\DecisionTreeLeaf\|null#' + - '#Method Phpml\\Classification\\Linear\\DecisionStump::getBestNumericalSplit\(\) should return mixed\[\] but returns \(float\|int\|mixed\|string\)\[\]\|null#' + - '#Method Phpml\\Classification\\Linear\\DecisionStump::getBestNominalSplit\(\) should return mixed\[\] but returns mixed\[\]\|null#' diff --git a/src/Phpml/Association/Apriori.php b/src/Phpml/Association/Apriori.php index e13f556..76d8624 100644 --- a/src/Phpml/Association/Apriori.php +++ b/src/Phpml/Association/Apriori.php @@ -244,6 +244,7 @@ class Apriori implements Associator foreach ((array) $this->samples as $sample) { if ($this->subset($sample, $candidate)) { $candidates[] = $candidate; + continue 2; } } diff --git a/src/Phpml/Classification/DecisionTree.php b/src/Phpml/Classification/DecisionTree.php index 5bb730b..d660322 100644 --- a/src/Phpml/Classification/DecisionTree.php +++ b/src/Phpml/Classification/DecisionTree.php @@ -59,14 +59,14 @@ class DecisionTree implements Classifier private $selectedFeatures = []; /** - * @var array + * @var array|null */ - private $featureImportances = null; + private $featureImportances; /** - * @var array + * @var array|null */ - private $columnNames = null; + private $columnNames; public function __construct(int $maxDepth = 10) { diff --git a/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php b/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php index f3f9449..5164472 100644 --- a/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php +++ b/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php @@ -9,7 +9,7 @@ use Phpml\Math\Comparison; class DecisionTreeLeaf { /** - * @var string + * @var string|int */ public $value; @@ -52,7 +52,7 @@ class DecisionTreeLeaf public $classValue = ''; /** - * @var bool + * @var bool|int */ public $isTerminal = false; diff --git a/src/Phpml/Classification/Ensemble/Bagging.php b/src/Phpml/Classification/Ensemble/Bagging.php index 6fa1ec8..a3d8e5e 100644 --- a/src/Phpml/Classification/Ensemble/Bagging.php +++ b/src/Phpml/Classification/Ensemble/Bagging.php @@ -31,7 +31,7 @@ class Bagging implements Classifier protected $numClassifier; /** - * @var Classifier + * @var string */ protected $classifier = DecisionTree::class; diff --git a/src/Phpml/Classification/Linear/Adaline.php b/src/Phpml/Classification/Linear/Adaline.php index cda746f..de2e152 100644 --- a/src/Phpml/Classification/Linear/Adaline.php +++ b/src/Phpml/Classification/Linear/Adaline.php @@ -21,7 +21,7 @@ class Adaline extends Perceptron /** * Training type may be either 'Batch' or 'Online' learning * - * @var string + * @var string|int */ protected $trainingType; diff --git a/src/Phpml/Classification/Linear/DecisionStump.php b/src/Phpml/Classification/Linear/DecisionStump.php index 3f6eb58..439ea56 100644 --- a/src/Phpml/Classification/Linear/DecisionStump.php +++ b/src/Phpml/Classification/Linear/DecisionStump.php @@ -224,7 +224,7 @@ class DecisionStump extends WeightedClassifier foreach ($distinctVals as $val) { [$errorRate, $prob] = $this->calculateErrorRate($targets, $val, $operator, $values); - if ($split == null || $split['trainingErrorRate'] < $errorRate) { + if ($split === null || $split['trainingErrorRate'] < $errorRate) { $split = [ 'value' => $val, 'operator' => $operator, diff --git a/src/Phpml/Classification/Linear/LogisticRegression.php b/src/Phpml/Classification/Linear/LogisticRegression.php index 3818161..b595587 100644 --- a/src/Phpml/Classification/Linear/LogisticRegression.php +++ b/src/Phpml/Classification/Linear/LogisticRegression.php @@ -119,19 +119,25 @@ class LogisticRegression extends Adaline * * @throws \Exception */ - protected function runTraining(array $samples, array $targets) + protected function runTraining(array $samples, array $targets): void { $callback = $this->getCostFunction(); switch ($this->trainingType) { case self::BATCH_TRAINING: - return $this->runGradientDescent($samples, $targets, $callback, true); + $this->runGradientDescent($samples, $targets, $callback, true); + + return; case self::ONLINE_TRAINING: - return $this->runGradientDescent($samples, $targets, $callback, false); + $this->runGradientDescent($samples, $targets, $callback, false); + + return; case self::CONJUGATE_GRAD_TRAINING: - return $this->runConjugateGradient($samples, $targets, $callback); + $this->runConjugateGradient($samples, $targets, $callback); + + return; default: throw new Exception('Logistic regression has invalid training type: %s.', $this->trainingType); @@ -143,7 +149,7 @@ class LogisticRegression extends Adaline */ protected function runConjugateGradient(array $samples, array $targets, Closure $gradientFunc): void { - if (empty($this->optimizer)) { + if ($this->optimizer === null) { $this->optimizer = (new ConjugateGradient($this->featureCount)) ->setMaxIterations($this->maxIterations); } diff --git a/src/Phpml/Classification/Linear/Perceptron.php b/src/Phpml/Classification/Linear/Perceptron.php index 0db7496..6838227 100644 --- a/src/Phpml/Classification/Linear/Perceptron.php +++ b/src/Phpml/Classification/Linear/Perceptron.php @@ -19,7 +19,7 @@ class Perceptron implements Classifier, IncrementalEstimator use Predictable, OneVsRest; /** - * @var \Phpml\Helper\Optimizer\Optimizer + * @var \Phpml\Helper\Optimizer\Optimizer|GD|StochasticGD|null */ protected $optimizer; @@ -34,7 +34,7 @@ class Perceptron implements Classifier, IncrementalEstimator protected $featureCount = 0; /** - * @var array + * @var array|null */ protected $weights = []; @@ -67,8 +67,8 @@ class Perceptron implements Classifier, IncrementalEstimator * Initalize a perceptron classifier with given learning rate and maximum * number of iterations used while training the perceptron * - * @param float $learningRate Value between 0.0(exclusive) and 1.0(inclusive) - * @param int $maxIterations Must be at least 1 + * @param float $learningRate Value between 0.0(exclusive) and 1.0(inclusive) + * @param int $maxIterations Must be at least 1 * * @throws \Exception */ @@ -178,7 +178,7 @@ class Perceptron implements Classifier, IncrementalEstimator { $class = $isBatch ? GD::class : StochasticGD::class; - if (empty($this->optimizer)) { + if ($this->optimizer === null) { $this->optimizer = (new $class($this->featureCount)) ->setLearningRate($this->learningRate) ->setMaxIterations($this->maxIterations) diff --git a/src/Phpml/Clustering/KMeans/Point.php b/src/Phpml/Clustering/KMeans/Point.php index 6aa40a9..8c918a7 100644 --- a/src/Phpml/Clustering/KMeans/Point.php +++ b/src/Phpml/Clustering/KMeans/Point.php @@ -48,12 +48,15 @@ class Point implements ArrayAccess */ public function getClosest(array $points) { + $minPoint = null; + foreach ($points as $point) { $distance = $this->getDistanceWith($point, false); if (!isset($minDistance)) { $minDistance = $distance; $minPoint = $point; + continue; } diff --git a/src/Phpml/Clustering/KMeans/Space.php b/src/Phpml/Clustering/KMeans/Space.php index 0d4adf5..371bbc3 100644 --- a/src/Phpml/Clustering/KMeans/Space.php +++ b/src/Phpml/Clustering/KMeans/Space.php @@ -45,7 +45,7 @@ class Space extends SplObjectStorage } /** - * @param null $data + * @param null $data */ public function addPoint(array $coordinates, $data = null): void { @@ -124,10 +124,12 @@ class Space extends SplObjectStorage switch ($initMethod) { case KMeans::INIT_RANDOM: $clusters = $this->initializeRandomClusters($clustersNumber); + break; case KMeans::INIT_KMEANS_PLUS_PLUS: $clusters = $this->initializeKMPPClusters($clustersNumber); + break; default: @@ -200,6 +202,7 @@ class Space extends SplObjectStorage } $clusters[] = new Cluster($this, $point->getCoordinates()); + break; } } diff --git a/src/Phpml/DimensionReduction/KernelPCA.php b/src/Phpml/DimensionReduction/KernelPCA.php index 1981cb5..65bb324 100644 --- a/src/Phpml/DimensionReduction/KernelPCA.php +++ b/src/Phpml/DimensionReduction/KernelPCA.php @@ -30,7 +30,7 @@ class KernelPCA extends PCA /** * Gamma value used by the kernel * - * @var float + * @var float|null */ protected $gamma; diff --git a/src/Phpml/FeatureExtraction/TokenCountVectorizer.php b/src/Phpml/FeatureExtraction/TokenCountVectorizer.php index e0bd402..e0d4e10 100644 --- a/src/Phpml/FeatureExtraction/TokenCountVectorizer.php +++ b/src/Phpml/FeatureExtraction/TokenCountVectorizer.php @@ -15,7 +15,7 @@ class TokenCountVectorizer implements Transformer private $tokenizer; /** - * @var StopWords + * @var StopWords|null */ private $stopWords; diff --git a/src/Phpml/Helper/OneVsRest.php b/src/Phpml/Helper/OneVsRest.php index 4f661ba..1c0ca93 100644 --- a/src/Phpml/Helper/OneVsRest.php +++ b/src/Phpml/Helper/OneVsRest.php @@ -33,7 +33,7 @@ trait OneVsRest // Clears previous stuff. $this->reset(); - $this->trainBylabel($samples, $targets); + $this->trainByLabel($samples, $targets); } /** diff --git a/src/Phpml/Helper/Optimizer/GD.php b/src/Phpml/Helper/Optimizer/GD.php index 4eadf28..11577c9 100644 --- a/src/Phpml/Helper/Optimizer/GD.php +++ b/src/Phpml/Helper/Optimizer/GD.php @@ -15,9 +15,9 @@ class GD extends StochasticGD /** * Number of samples given * - * @var int + * @var int|null */ - protected $sampleCount = null; + protected $sampleCount; public function runOptimization(array $samples, array $targets, Closure $gradientCb): array { diff --git a/src/Phpml/Helper/Optimizer/StochasticGD.php b/src/Phpml/Helper/Optimizer/StochasticGD.php index 07ad216..18a5f0c 100644 --- a/src/Phpml/Helper/Optimizer/StochasticGD.php +++ b/src/Phpml/Helper/Optimizer/StochasticGD.php @@ -31,7 +31,7 @@ class StochasticGD extends Optimizer * Callback function to get the gradient and cost value * for a specific set of theta (ϴ) and a pair of sample & target * - * @var \Closure + * @var \Closure|null */ protected $gradientCb = null; @@ -144,7 +144,7 @@ class StochasticGD extends Optimizer * The cost function to minimize and the gradient of the function are to be * handled by the callback function provided as the third parameter of the method. */ - public function runOptimization(array $samples, array $targets, Closure $gradientCb): array + public function runOptimization(array $samples, array $targets, Closure $gradientCb): ?array { $this->samples = $samples; $this->targets = $targets; @@ -181,7 +181,7 @@ class StochasticGD extends Optimizer // Solution in the pocket is better than or equal to the last state // so, we use this solution - return $this->theta = $bestTheta; + return $this->theta = (array) $bestTheta; } /** diff --git a/src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php b/src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php index 4d7f662..1730309 100644 --- a/src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php +++ b/src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php @@ -88,6 +88,8 @@ class EigenvalueDecomposition private $cdivi; + private $A; + /** * Constructor: Check for symmetry, then construct the eigenvalue decomposition */ diff --git a/src/Phpml/Math/LinearAlgebra/LUDecomposition.php b/src/Phpml/Math/LinearAlgebra/LUDecomposition.php index 6ebd8cb..151e2cc 100644 --- a/src/Phpml/Math/LinearAlgebra/LUDecomposition.php +++ b/src/Phpml/Math/LinearAlgebra/LUDecomposition.php @@ -212,9 +212,9 @@ class LUDecomposition /** * Is the matrix nonsingular? * - * @return true if U, and hence A, is nonsingular. + * @return bool true if U, and hence A, is nonsingular. */ - public function isNonsingular() + public function isNonsingular(): bool { for ($j = 0; $j < $this->n; ++$j) { if ($this->LU[$j][$j] == 0) { diff --git a/src/Phpml/Math/Set.php b/src/Phpml/Math/Set.php index a67d5c2..dcb02e6 100644 --- a/src/Phpml/Math/Set.php +++ b/src/Phpml/Math/Set.php @@ -15,7 +15,7 @@ class Set implements IteratorAggregate private $elements = []; /** - * @param string[]|int[]|float[] $elements + * @param string[]|int[]|float[]|bool[] $elements */ public function __construct(array $elements = []) { @@ -83,7 +83,7 @@ class Set implements IteratorAggregate } /** - * @param string|int|float $element + * @param string|int|float|bool $element */ public function add($element): self { @@ -91,7 +91,7 @@ class Set implements IteratorAggregate } /** - * @param string[]|int[]|float[] $elements + * @param string[]|int[]|float[]|bool[] $elements */ public function addAll(array $elements): self { diff --git a/src/Phpml/Metric/ClassificationReport.php b/src/Phpml/Metric/ClassificationReport.php index 0f27b06..0c3198f 100644 --- a/src/Phpml/Metric/ClassificationReport.php +++ b/src/Phpml/Metric/ClassificationReport.php @@ -91,6 +91,7 @@ class ClassificationReport $values = array_filter($this->{$metric}); if (empty($values)) { $this->average[$metric] = 0.0; + continue; } diff --git a/src/Phpml/NeuralNetwork/Network/MultilayerPerceptron.php b/src/Phpml/NeuralNetwork/Network/MultilayerPerceptron.php index 5ace597..1a997be 100644 --- a/src/Phpml/NeuralNetwork/Network/MultilayerPerceptron.php +++ b/src/Phpml/NeuralNetwork/Network/MultilayerPerceptron.php @@ -26,14 +26,14 @@ abstract class MultilayerPerceptron extends LayeredNetwork implements Estimator, protected $classes = []; /** - * @var ActivationFunction + * @var ActivationFunction|null */ protected $activationFunction; /** * @var Backpropagation */ - protected $backpropagation = null; + protected $backpropagation; /** * @var int @@ -50,6 +50,11 @@ abstract class MultilayerPerceptron extends LayeredNetwork implements Estimator, */ private $learningRate; + /** + * @var int + */ + private $iterations; + /** * @throws InvalidArgumentException */ diff --git a/src/Phpml/NeuralNetwork/Node/Neuron.php b/src/Phpml/NeuralNetwork/Node/Neuron.php index a6c10e6..2dff600 100644 --- a/src/Phpml/NeuralNetwork/Node/Neuron.php +++ b/src/Phpml/NeuralNetwork/Node/Neuron.php @@ -24,13 +24,11 @@ class Neuron implements Node /** * @var float */ - protected $output; + protected $output = 0.0; public function __construct(?ActivationFunction $activationFunction = null) { $this->activationFunction = $activationFunction ?: new Sigmoid(); - $this->synapses = []; - $this->output = 0; } public function addSynapse(Synapse $synapse): void @@ -48,8 +46,8 @@ class Neuron implements Node public function getOutput(): float { - if ($this->output === 0) { - $sum = 0; + if ($this->output === 0.0) { + $sum = 0.0; foreach ($this->synapses as $synapse) { $sum += $synapse->getOutput(); } @@ -62,6 +60,6 @@ class Neuron implements Node public function reset(): void { - $this->output = 0; + $this->output = 0.0; } } diff --git a/src/Phpml/NeuralNetwork/Training/Backpropagation.php b/src/Phpml/NeuralNetwork/Training/Backpropagation.php index df515b2..4144c30 100644 --- a/src/Phpml/NeuralNetwork/Training/Backpropagation.php +++ b/src/Phpml/NeuralNetwork/Training/Backpropagation.php @@ -15,14 +15,14 @@ class Backpropagation private $learningRate; /** - * @var array + * @var array|null */ - private $sigmas = null; + private $sigmas; /** - * @var array + * @var array|null */ - private $prevSigmas = null; + private $prevSigmas; public function __construct(float $learningRate) { diff --git a/src/Phpml/Preprocessing/Imputer.php b/src/Phpml/Preprocessing/Imputer.php index fdf8796..593756c 100644 --- a/src/Phpml/Preprocessing/Imputer.php +++ b/src/Phpml/Preprocessing/Imputer.php @@ -33,8 +33,7 @@ class Imputer implements Preprocessor private $samples = []; /** - * @param mixed $missingValue - * @param array|null $samples + * @param mixed $missingValue */ public function __construct($missingValue, Strategy $strategy, int $axis = self::AXIS_COLUMN, array $samples = []) { diff --git a/src/Phpml/SupportVectorMachine/DataTransformer.php b/src/Phpml/SupportVectorMachine/DataTransformer.php index 2ce938e..6516cbf 100644 --- a/src/Phpml/SupportVectorMachine/DataTransformer.php +++ b/src/Phpml/SupportVectorMachine/DataTransformer.php @@ -9,6 +9,8 @@ class DataTransformer public static function trainingSet(array $samples, array $labels, bool $targets = false): string { $set = ''; + $numericLabels = []; + if (!$targets) { $numericLabels = self::numericLabels($labels); } diff --git a/src/Phpml/SupportVectorMachine/SupportVectorMachine.php b/src/Phpml/SupportVectorMachine/SupportVectorMachine.php index 2415eda..4565332 100644 --- a/src/Phpml/SupportVectorMachine/SupportVectorMachine.php +++ b/src/Phpml/SupportVectorMachine/SupportVectorMachine.php @@ -37,7 +37,7 @@ class SupportVectorMachine private $degree; /** - * @var float + * @var float|null */ private $gamma; diff --git a/tests/Phpml/Association/AprioriTest.php b/tests/Phpml/Association/AprioriTest.php index 68456ff..8b95237 100644 --- a/tests/Phpml/Association/AprioriTest.php +++ b/tests/Phpml/Association/AprioriTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification; +namespace Phpml\Tests\Association; use Phpml\Association\Apriori; use Phpml\ModelManager; @@ -173,8 +173,8 @@ class AprioriTest extends TestCase /** * Invokes objects method. Private/protected will be set accessible. * - * @param string $method Method name to be called - * @param array $params Array of params to be passed + * @param string $method Method name to be called + * @param array $params Array of params to be passed * * @return mixed */ diff --git a/tests/Phpml/Classification/DecisionTree/DecisionTreeLeafTest.php b/tests/Phpml/Classification/DecisionTree/DecisionTreeLeafTest.php index 626ed64..abcf10d 100644 --- a/tests/Phpml/Classification/DecisionTree/DecisionTreeLeafTest.php +++ b/tests/Phpml/Classification/DecisionTree/DecisionTreeLeafTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification\DecisionTree; +namespace Phpml\Tests\Classification\DecisionTree; use Phpml\Classification\DecisionTree\DecisionTreeLeaf; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Classification/DecisionTreeTest.php b/tests/Phpml/Classification/DecisionTreeTest.php index 8533500..9478a2a 100644 --- a/tests/Phpml/Classification/DecisionTreeTest.php +++ b/tests/Phpml/Classification/DecisionTreeTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification; +namespace Phpml\Tests\Classification; use Phpml\Classification\DecisionTree; use Phpml\ModelManager; diff --git a/tests/Phpml/Classification/Ensemble/AdaBoostTest.php b/tests/Phpml/Classification/Ensemble/AdaBoostTest.php index e01066c..7677c31 100644 --- a/tests/Phpml/Classification/Ensemble/AdaBoostTest.php +++ b/tests/Phpml/Classification/Ensemble/AdaBoostTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification\Ensemble; +namespace Phpml\Tests\Classification\Ensemble; use Phpml\Classification\Ensemble\AdaBoost; use Phpml\ModelManager; diff --git a/tests/Phpml/Classification/Ensemble/BaggingTest.php b/tests/Phpml/Classification/Ensemble/BaggingTest.php index 175b79a..69c4d01 100644 --- a/tests/Phpml/Classification/Ensemble/BaggingTest.php +++ b/tests/Phpml/Classification/Ensemble/BaggingTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification\Ensemble; +namespace Phpml\Tests\Classification\Ensemble; use Phpml\Classification\DecisionTree; use Phpml\Classification\Ensemble\Bagging; diff --git a/tests/Phpml/Classification/Ensemble/RandomForestTest.php b/tests/Phpml/Classification/Ensemble/RandomForestTest.php index f2871e3..ea0cce1 100644 --- a/tests/Phpml/Classification/Ensemble/RandomForestTest.php +++ b/tests/Phpml/Classification/Ensemble/RandomForestTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification\Ensemble; +namespace Phpml\Tests\Classification\Ensemble; use Phpml\Classification\DecisionTree; use Phpml\Classification\Ensemble\RandomForest; @@ -21,6 +21,7 @@ class RandomForestTest extends BaggingTest $this->assertEquals(1, 1); } } + protected function getClassifier($numBaseClassifiers = 50) { $classifier = new RandomForest($numBaseClassifiers); diff --git a/tests/Phpml/Classification/KNearestNeighborsTest.php b/tests/Phpml/Classification/KNearestNeighborsTest.php index d9114b5..d96152a 100644 --- a/tests/Phpml/Classification/KNearestNeighborsTest.php +++ b/tests/Phpml/Classification/KNearestNeighborsTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification; +namespace Phpml\Tests\Classification; use Phpml\Classification\KNearestNeighbors; use Phpml\Math\Distance\Chebyshev; diff --git a/tests/Phpml/Classification/Linear/AdalineTest.php b/tests/Phpml/Classification/Linear/AdalineTest.php index 0a90a18..c8ca752 100644 --- a/tests/Phpml/Classification/Linear/AdalineTest.php +++ b/tests/Phpml/Classification/Linear/AdalineTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification\Linear; +namespace Phpml\Tests\Classification\Linear; use Phpml\Classification\Linear\Adaline; use Phpml\ModelManager; diff --git a/tests/Phpml/Classification/Linear/DecisionStumpTest.php b/tests/Phpml/Classification/Linear/DecisionStumpTest.php index 7fbabec..93c8595 100644 --- a/tests/Phpml/Classification/Linear/DecisionStumpTest.php +++ b/tests/Phpml/Classification/Linear/DecisionStumpTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification\Linear; +namespace Phpml\Tests\Classification\Linear; use Phpml\Classification\Linear\DecisionStump; use Phpml\ModelManager; diff --git a/tests/Phpml/Classification/Linear/PerceptronTest.php b/tests/Phpml/Classification/Linear/PerceptronTest.php index 17b1db8..35af855 100644 --- a/tests/Phpml/Classification/Linear/PerceptronTest.php +++ b/tests/Phpml/Classification/Linear/PerceptronTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification\Linear; +namespace Phpml\Tests\Classification\Linear; use Phpml\Classification\Linear\Perceptron; use Phpml\ModelManager; diff --git a/tests/Phpml/Classification/MLPClassifierTest.php b/tests/Phpml/Classification/MLPClassifierTest.php index ef62d06..ef40618 100644 --- a/tests/Phpml/Classification/MLPClassifierTest.php +++ b/tests/Phpml/Classification/MLPClassifierTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification; +namespace Phpml\Tests\Classification; use Phpml\Classification\MLPClassifier; use Phpml\Exception\InvalidArgumentException; diff --git a/tests/Phpml/Classification/NaiveBayesTest.php b/tests/Phpml/Classification/NaiveBayesTest.php index c423c6d..8312e9c 100644 --- a/tests/Phpml/Classification/NaiveBayesTest.php +++ b/tests/Phpml/Classification/NaiveBayesTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification; +namespace Phpml\Tests\Classification; use Phpml\Classification\NaiveBayes; use Phpml\ModelManager; diff --git a/tests/Phpml/Classification/SVCTest.php b/tests/Phpml/Classification/SVCTest.php index 0941b34..0709e04 100644 --- a/tests/Phpml/Classification/SVCTest.php +++ b/tests/Phpml/Classification/SVCTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Classification; +namespace Phpml\Tests\Classification; use Phpml\Classification\SVC; use Phpml\ModelManager; diff --git a/tests/Phpml/Clustering/DBSCANTest.php b/tests/Phpml/Clustering/DBSCANTest.php index f12fb03..c0d0401 100644 --- a/tests/Phpml/Clustering/DBSCANTest.php +++ b/tests/Phpml/Clustering/DBSCANTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Clustering; +namespace Phpml\Tests\Clustering; use Phpml\Clustering\DBSCAN; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Clustering/FuzzyCMeansTest.php b/tests/Phpml/Clustering/FuzzyCMeansTest.php index 7b19422..1c3af15 100644 --- a/tests/Phpml/Clustering/FuzzyCMeansTest.php +++ b/tests/Phpml/Clustering/FuzzyCMeansTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Clustering; +namespace Phpml\Tests\Clustering; use Phpml\Clustering\FuzzyCMeans; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Clustering/KMeansTest.php b/tests/Phpml/Clustering/KMeansTest.php index d212157..dedf981 100644 --- a/tests/Phpml/Clustering/KMeansTest.php +++ b/tests/Phpml/Clustering/KMeansTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Clustering; +namespace Phpml\Tests\Clustering; use Phpml\Clustering\KMeans; use Phpml\Exception\InvalidArgumentException; diff --git a/tests/Phpml/CrossValidation/RandomSplitTest.php b/tests/Phpml/CrossValidation/RandomSplitTest.php index 8058fd6..75f60ff 100644 --- a/tests/Phpml/CrossValidation/RandomSplitTest.php +++ b/tests/Phpml/CrossValidation/RandomSplitTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\CrossValidation; +namespace Phpml\Tests\CrossValidation; use Phpml\CrossValidation\RandomSplit; use Phpml\Dataset\ArrayDataset; diff --git a/tests/Phpml/CrossValidation/StratifiedRandomSplitTest.php b/tests/Phpml/CrossValidation/StratifiedRandomSplitTest.php index e953ca7..5309dc6 100644 --- a/tests/Phpml/CrossValidation/StratifiedRandomSplitTest.php +++ b/tests/Phpml/CrossValidation/StratifiedRandomSplitTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\CrossValidation; +namespace Phpml\Tests\CrossValidation; use Phpml\CrossValidation\StratifiedRandomSplit; use Phpml\Dataset\ArrayDataset; diff --git a/tests/Phpml/Dataset/ArrayDatasetTest.php b/tests/Phpml/Dataset/ArrayDatasetTest.php index e0a6b91..bca9e43 100644 --- a/tests/Phpml/Dataset/ArrayDatasetTest.php +++ b/tests/Phpml/Dataset/ArrayDatasetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Dataset; +namespace Phpml\Tests\Dataset; use Phpml\Dataset\ArrayDataset; use Phpml\Exception\InvalidArgumentException; diff --git a/tests/Phpml/Dataset/CsvDatasetTest.php b/tests/Phpml/Dataset/CsvDatasetTest.php index 5049253..90eb1d0 100644 --- a/tests/Phpml/Dataset/CsvDatasetTest.php +++ b/tests/Phpml/Dataset/CsvDatasetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Dataset; +namespace Phpml\Tests\Dataset; use Phpml\Dataset\CsvDataset; use Phpml\Exception\FileException; diff --git a/tests/Phpml/Dataset/Demo/GlassDatasetTest.php b/tests/Phpml/Dataset/Demo/GlassDatasetTest.php index 8feef45..0d873e6 100644 --- a/tests/Phpml/Dataset/Demo/GlassDatasetTest.php +++ b/tests/Phpml/Dataset/Demo/GlassDatasetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Dataset\Demo; +namespace Phpml\Tests\Dataset\Demo; use Phpml\Dataset\Demo\GlassDataset; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Dataset/Demo/IrisDatasetTest.php b/tests/Phpml/Dataset/Demo/IrisDatasetTest.php index faa48c6..4fb2ee2 100644 --- a/tests/Phpml/Dataset/Demo/IrisDatasetTest.php +++ b/tests/Phpml/Dataset/Demo/IrisDatasetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Dataset\Demo; +namespace Phpml\Tests\Dataset\Demo; use Phpml\Dataset\Demo\IrisDataset; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Dataset/Demo/WineDatasetTest.php b/tests/Phpml/Dataset/Demo/WineDatasetTest.php index e0324b4..1b7a982 100644 --- a/tests/Phpml/Dataset/Demo/WineDatasetTest.php +++ b/tests/Phpml/Dataset/Demo/WineDatasetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Dataset\Demo; +namespace Phpml\Tests\Dataset\Demo; use Phpml\Dataset\Demo\WineDataset; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Dataset/FilesDatasetTest.php b/tests/Phpml/Dataset/FilesDatasetTest.php index ee08395..08b568d 100644 --- a/tests/Phpml/Dataset/FilesDatasetTest.php +++ b/tests/Phpml/Dataset/FilesDatasetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Dataset; +namespace Phpml\Tests\Dataset; use Phpml\Dataset\FilesDataset; use Phpml\Exception\DatasetException; diff --git a/tests/Phpml/DimensionReduction/KernelPCATest.php b/tests/Phpml/DimensionReduction/KernelPCATest.php index 3f37e3c..05a4138 100644 --- a/tests/Phpml/DimensionReduction/KernelPCATest.php +++ b/tests/Phpml/DimensionReduction/KernelPCATest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\DimensionReduction; +namespace Phpml\Tests\DimensionReduction; use Phpml\DimensionReduction\KernelPCA; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/DimensionReduction/LDATest.php b/tests/Phpml/DimensionReduction/LDATest.php index 42a0283..2803a4b 100644 --- a/tests/Phpml/DimensionReduction/LDATest.php +++ b/tests/Phpml/DimensionReduction/LDATest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\DimensionReduction; +namespace Phpml\Tests\DimensionReduction; use Phpml\Dataset\Demo\IrisDataset; use Phpml\DimensionReduction\LDA; diff --git a/tests/Phpml/DimensionReduction/PCATest.php b/tests/Phpml/DimensionReduction/PCATest.php index 38b4744..337b253 100644 --- a/tests/Phpml/DimensionReduction/PCATest.php +++ b/tests/Phpml/DimensionReduction/PCATest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\DimensionReduction; +namespace Phpml\Tests\DimensionReduction; use Phpml\DimensionReduction\PCA; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/FeatureExtraction/StopWordsTest.php b/tests/Phpml/FeatureExtraction/StopWordsTest.php index 6d97a23..5780c39 100644 --- a/tests/Phpml/FeatureExtraction/StopWordsTest.php +++ b/tests/Phpml/FeatureExtraction/StopWordsTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\FeatureExtraction; +namespace Phpml\Tests\FeatureExtraction; use Phpml\Exception\InvalidArgumentException; use Phpml\FeatureExtraction\StopWords; diff --git a/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php b/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php index a8faacb..30bc0e5 100644 --- a/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php +++ b/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\FeatureExtraction; +namespace Phpml\Tests\FeatureExtraction; use Phpml\FeatureExtraction\TfIdfTransformer; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/FeatureExtraction/TokenCountVectorizerTest.php b/tests/Phpml/FeatureExtraction/TokenCountVectorizerTest.php index 463570c..aaba5fc 100644 --- a/tests/Phpml/FeatureExtraction/TokenCountVectorizerTest.php +++ b/tests/Phpml/FeatureExtraction/TokenCountVectorizerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\FeatureExtraction; +namespace Phpml\Tests\FeatureExtraction; use Phpml\FeatureExtraction\StopWords; use Phpml\FeatureExtraction\TokenCountVectorizer; diff --git a/tests/Phpml/Math/ComparisonTest.php b/tests/Phpml/Math/ComparisonTest.php index ecb58c2..0118ee4 100644 --- a/tests/Phpml/Math/ComparisonTest.php +++ b/tests/Phpml/Math/ComparisonTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Math; +namespace Phpml\Tests\Math; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Comparison; @@ -11,8 +11,8 @@ use PHPUnit\Framework\TestCase; class ComparisonTest extends TestCase { /** - * @param mixed $a - * @param mixed $b + * @param mixed $a + * @param mixed $b * * @dataProvider provideData */ diff --git a/tests/Phpml/Math/Distance/ChebyshevTest.php b/tests/Phpml/Math/Distance/ChebyshevTest.php index 56d6685..262927b 100644 --- a/tests/Phpml/Math/Distance/ChebyshevTest.php +++ b/tests/Phpml/Math/Distance/ChebyshevTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Metric; +namespace Phpml\Tests\Math\Distance; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Chebyshev; diff --git a/tests/Phpml/Math/Distance/EuclideanTest.php b/tests/Phpml/Math/Distance/EuclideanTest.php index 4acb3d4..734bbd2 100644 --- a/tests/Phpml/Math/Distance/EuclideanTest.php +++ b/tests/Phpml/Math/Distance/EuclideanTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Metric; +namespace Phpml\Tests\Math\Distance; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Euclidean; diff --git a/tests/Phpml/Math/Distance/ManhattanTest.php b/tests/Phpml/Math/Distance/ManhattanTest.php index 2a05874..2eb9f06 100644 --- a/tests/Phpml/Math/Distance/ManhattanTest.php +++ b/tests/Phpml/Math/Distance/ManhattanTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Metric; +namespace Phpml\Tests\Math\Distance; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Manhattan; diff --git a/tests/Phpml/Math/Distance/MinkowskiTest.php b/tests/Phpml/Math/Distance/MinkowskiTest.php index a8159d7..6c7b897 100644 --- a/tests/Phpml/Math/Distance/MinkowskiTest.php +++ b/tests/Phpml/Math/Distance/MinkowskiTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Metric; +namespace Phpml\Tests\Math\Distance; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Minkowski; diff --git a/tests/Phpml/Math/Kernel/RBFTest.php b/tests/Phpml/Math/Kernel/RBFTest.php index 3ed7017..08f795d 100644 --- a/tests/Phpml/Math/Kernel/RBFTest.php +++ b/tests/Phpml/Math/Kernel/RBFTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace test\Phpml\Math\Kernel; +namespace Phpml\Tests\Math\Kernel; use Phpml\Math\Kernel\RBF; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Math/LinearAlgebra/EigenDecompositionTest.php b/tests/Phpml/Math/LinearAlgebra/EigenDecompositionTest.php index 3956830..47c4798 100644 --- a/tests/Phpml/Math/LinearAlgebra/EigenDecompositionTest.php +++ b/tests/Phpml/Math/LinearAlgebra/EigenDecompositionTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Math\LinearAlgebra; +namespace Phpml\Tests\Math\LinearAlgebra; use Phpml\Math\LinearAlgebra\EigenvalueDecomposition; use Phpml\Math\Matrix; diff --git a/tests/Phpml/Math/MatrixTest.php b/tests/Phpml/Math/MatrixTest.php index fce83bf..da535bf 100644 --- a/tests/Phpml/Math/MatrixTest.php +++ b/tests/Phpml/Math/MatrixTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Math; +namespace Phpml\Tests\Math; use Phpml\Exception\InvalidArgumentException; use Phpml\Exception\MatrixException; diff --git a/tests/Phpml/Math/ProductTest.php b/tests/Phpml/Math/ProductTest.php index bd55d11..da7450b 100644 --- a/tests/Phpml/Math/ProductTest.php +++ b/tests/Phpml/Math/ProductTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Math; +namespace Phpml\Tests\Math; use Phpml\Math\Product; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Math/SetTest.php b/tests/Phpml/Math/SetTest.php index 645e607..2335c73 100644 --- a/tests/Phpml/Math/SetTest.php +++ b/tests/Phpml/Math/SetTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Math; +namespace Phpml\Tests\Math; use Phpml\Math\Set; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Math/Statistic/CorrelationTest.php b/tests/Phpml/Math/Statistic/CorrelationTest.php index c091bb2..eebb065 100644 --- a/tests/Phpml/Math/Statistic/CorrelationTest.php +++ b/tests/Phpml/Math/Statistic/CorrelationTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace test\Phpml\Math\StandardDeviation; +namespace Phpml\Tests\Math\Statistic; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Statistic\Correlation; diff --git a/tests/Phpml/Math/Statistic/CovarianceTest.php b/tests/Phpml/Math/Statistic/CovarianceTest.php index 97ec194..2b64854 100644 --- a/tests/Phpml/Math/Statistic/CovarianceTest.php +++ b/tests/Phpml/Math/Statistic/CovarianceTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Math\Statistic; +namespace Phpml\Tests\Math\Statistic; use Phpml\Math\Statistic\Covariance; use Phpml\Math\Statistic\Mean; diff --git a/tests/Phpml/Math/Statistic/GaussianTest.php b/tests/Phpml/Math/Statistic/GaussianTest.php index 8030f85..e4627f4 100644 --- a/tests/Phpml/Math/Statistic/GaussianTest.php +++ b/tests/Phpml/Math/Statistic/GaussianTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace test\Phpml\Math\StandardDeviation; +namespace Phpml\Tests\Math\Statistic; use Phpml\Math\Statistic\Gaussian; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Math/Statistic/MeanTest.php b/tests/Phpml/Math/Statistic/MeanTest.php index f19479a..3b98032 100644 --- a/tests/Phpml/Math/Statistic/MeanTest.php +++ b/tests/Phpml/Math/Statistic/MeanTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace test\Phpml\Math\StandardDeviation; +namespace Phpml\Tests\Math\Statistic; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Statistic\Mean; diff --git a/tests/Phpml/Math/Statistic/StandardDeviationTest.php b/tests/Phpml/Math/Statistic/StandardDeviationTest.php index 4bc4392..8333740 100644 --- a/tests/Phpml/Math/Statistic/StandardDeviationTest.php +++ b/tests/Phpml/Math/Statistic/StandardDeviationTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace test\Phpml\Math\StandardDeviation; +namespace Phpml\Tests\Math\Statistic; use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Statistic\StandardDeviation; diff --git a/tests/Phpml/Metric/AccuracyTest.php b/tests/Phpml/Metric/AccuracyTest.php index e876da1..08d1c44 100644 --- a/tests/Phpml/Metric/AccuracyTest.php +++ b/tests/Phpml/Metric/AccuracyTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Metric; +namespace Phpml\Tests\Metric; use Phpml\Classification\SVC; use Phpml\CrossValidation\RandomSplit; diff --git a/tests/Phpml/Metric/ClassificationReportTest.php b/tests/Phpml/Metric/ClassificationReportTest.php index fb3471a..483f769 100644 --- a/tests/Phpml/Metric/ClassificationReportTest.php +++ b/tests/Phpml/Metric/ClassificationReportTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Metric; +namespace Phpml\Tests\Metric; use Phpml\Metric\ClassificationReport; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Metric/ConfusionMatrixTest.php b/tests/Phpml/Metric/ConfusionMatrixTest.php index f958bdf..590aff8 100644 --- a/tests/Phpml/Metric/ConfusionMatrixTest.php +++ b/tests/Phpml/Metric/ConfusionMatrixTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Metric; +namespace Phpml\Tests\Metric; use Phpml\Metric\ConfusionMatrix; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/ModelManagerTest.php b/tests/Phpml/ModelManagerTest.php index f47efb7..48ab747 100644 --- a/tests/Phpml/ModelManagerTest.php +++ b/tests/Phpml/ModelManagerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests; +namespace Phpml\Tests; use Phpml\Exception\FileException; use Phpml\ModelManager; diff --git a/tests/Phpml/NeuralNetwork/ActivationFunction/BinaryStepTest.php b/tests/Phpml/NeuralNetwork/ActivationFunction/BinaryStepTest.php index 91fc1c7..acc7977 100644 --- a/tests/Phpml/NeuralNetwork/ActivationFunction/BinaryStepTest.php +++ b/tests/Phpml/NeuralNetwork/ActivationFunction/BinaryStepTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\ActivationFunction; +namespace Phpml\Tests\NeuralNetwork\ActivationFunction; use Phpml\NeuralNetwork\ActivationFunction\BinaryStep; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/ActivationFunction/GaussianTest.php b/tests/Phpml/NeuralNetwork/ActivationFunction/GaussianTest.php index 58b4b87..2b08793 100644 --- a/tests/Phpml/NeuralNetwork/ActivationFunction/GaussianTest.php +++ b/tests/Phpml/NeuralNetwork/ActivationFunction/GaussianTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\ActivationFunction; +namespace Phpml\Tests\NeuralNetwork\ActivationFunction; use Phpml\NeuralNetwork\ActivationFunction\Gaussian; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/ActivationFunction/HyperboliTangentTest.php b/tests/Phpml/NeuralNetwork/ActivationFunction/HyperboliTangentTest.php index 00348d9..91e7eba 100644 --- a/tests/Phpml/NeuralNetwork/ActivationFunction/HyperboliTangentTest.php +++ b/tests/Phpml/NeuralNetwork/ActivationFunction/HyperboliTangentTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\ActivationFunction; +namespace Phpml\Tests\NeuralNetwork\ActivationFunction; use Phpml\NeuralNetwork\ActivationFunction\HyperbolicTangent; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/ActivationFunction/PReLUTest.php b/tests/Phpml/NeuralNetwork/ActivationFunction/PReLUTest.php index 7e8e718..f407060 100644 --- a/tests/Phpml/NeuralNetwork/ActivationFunction/PReLUTest.php +++ b/tests/Phpml/NeuralNetwork/ActivationFunction/PReLUTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\ActivationFunction; +namespace Phpml\Tests\NeuralNetwork\ActivationFunction; use Phpml\NeuralNetwork\ActivationFunction\PReLU; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/ActivationFunction/SigmoidTest.php b/tests/Phpml/NeuralNetwork/ActivationFunction/SigmoidTest.php index d5a0ea3..30b50f8 100644 --- a/tests/Phpml/NeuralNetwork/ActivationFunction/SigmoidTest.php +++ b/tests/Phpml/NeuralNetwork/ActivationFunction/SigmoidTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\ActivationFunction; +namespace Phpml\Tests\NeuralNetwork\ActivationFunction; use Phpml\NeuralNetwork\ActivationFunction\Sigmoid; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php b/tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php index 19a0312..f46ff02 100644 --- a/tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php +++ b/tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\ActivationFunction; +namespace Phpml\Tests\NeuralNetwork\ActivationFunction; use Phpml\NeuralNetwork\ActivationFunction\ThresholdedReLU; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/LayerTest.php b/tests/Phpml/NeuralNetwork/LayerTest.php index 11f5e6a..baa3f9a 100644 --- a/tests/Phpml/NeuralNetwork/LayerTest.php +++ b/tests/Phpml/NeuralNetwork/LayerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork; +namespace Phpml\Tests\NeuralNetwork; use Phpml\Exception\InvalidArgumentException; use Phpml\NeuralNetwork\Layer; diff --git a/tests/Phpml/NeuralNetwork/Network/LayeredNetworkTest.php b/tests/Phpml/NeuralNetwork/Network/LayeredNetworkTest.php index c1779b8..21f5e9c 100644 --- a/tests/Phpml/NeuralNetwork/Network/LayeredNetworkTest.php +++ b/tests/Phpml/NeuralNetwork/Network/LayeredNetworkTest.php @@ -2,12 +2,13 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\Network; +namespace Phpml\Tests\NeuralNetwork\Network; use Phpml\NeuralNetwork\Layer; use Phpml\NeuralNetwork\Network\LayeredNetwork; use Phpml\NeuralNetwork\Node\Input; use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject; class LayeredNetworkTest extends TestCase { @@ -44,7 +45,10 @@ class LayeredNetworkTest extends TestCase $this->assertEquals([0.5], $network->getOutput()); } - private function getLayeredNetworkMock(): LayeredNetwork + /** + * @return LayeredNetwork|PHPUnit_Framework_MockObject_MockObject + */ + private function getLayeredNetworkMock() { return $this->getMockForAbstractClass(LayeredNetwork::class); } diff --git a/tests/Phpml/NeuralNetwork/Node/BiasTest.php b/tests/Phpml/NeuralNetwork/Node/BiasTest.php index ee311f5..e42a737 100644 --- a/tests/Phpml/NeuralNetwork/Node/BiasTest.php +++ b/tests/Phpml/NeuralNetwork/Node/BiasTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\Node; +namespace Phpml\Tests\NeuralNetwork\Node; use Phpml\NeuralNetwork\Node\Bias; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/Node/InputTest.php b/tests/Phpml/NeuralNetwork/Node/InputTest.php index 2d3be71..09ca831 100644 --- a/tests/Phpml/NeuralNetwork/Node/InputTest.php +++ b/tests/Phpml/NeuralNetwork/Node/InputTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\Node; +namespace Phpml\Tests\NeuralNetwork\Node; use Phpml\NeuralNetwork\Node\Input; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/NeuralNetwork/Node/Neuron/SynapseTest.php b/tests/Phpml/NeuralNetwork/Node/Neuron/SynapseTest.php index 1c09eae..973d216 100644 --- a/tests/Phpml/NeuralNetwork/Node/Neuron/SynapseTest.php +++ b/tests/Phpml/NeuralNetwork/Node/Neuron/SynapseTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\Node\Neuron; +namespace Phpml\Tests\NeuralNetwork\Node\Neuron; use Phpml\NeuralNetwork\Node\Neuron; use Phpml\NeuralNetwork\Node\Neuron\Synapse; @@ -41,8 +41,10 @@ class SynapseTest extends TestCase /** * @param int|float $output + * + * @return Neuron|PHPUnit_Framework_MockObject_MockObject */ - private function getNodeMock($output = 1): PHPUnit_Framework_MockObject_MockObject + private function getNodeMock($output = 1) { $node = $this->getMockBuilder(Neuron::class)->getMock(); $node->method('getOutput')->willReturn($output); diff --git a/tests/Phpml/NeuralNetwork/Node/NeuronTest.php b/tests/Phpml/NeuralNetwork/Node/NeuronTest.php index a58f2ec..03e309d 100644 --- a/tests/Phpml/NeuralNetwork/Node/NeuronTest.php +++ b/tests/Phpml/NeuralNetwork/Node/NeuronTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\NeuralNetwork\Node; +namespace Phpml\Tests\NeuralNetwork\Node; use Phpml\NeuralNetwork\ActivationFunction\BinaryStep; use Phpml\NeuralNetwork\Node\Neuron; @@ -22,6 +22,7 @@ class NeuronTest extends TestCase public function testNeuronActivationFunction(): void { + /** @var BinaryStep|PHPUnit_Framework_MockObject_MockObject $activationFunction */ $activationFunction = $this->getMockBuilder(BinaryStep::class)->getMock(); $activationFunction->method('compute')->with(0)->willReturn($output = 0.69); diff --git a/tests/Phpml/PipelineTest.php b/tests/Phpml/PipelineTest.php index caf1961..e45675d 100644 --- a/tests/Phpml/PipelineTest.php +++ b/tests/Phpml/PipelineTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests; +namespace Phpml\Tests; use Phpml\Classification\SVC; use Phpml\FeatureExtraction\TfIdfTransformer; diff --git a/tests/Phpml/Preprocessing/ImputerTest.php b/tests/Phpml/Preprocessing/ImputerTest.php index 658b454..c229c15 100644 --- a/tests/Phpml/Preprocessing/ImputerTest.php +++ b/tests/Phpml/Preprocessing/ImputerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Preprocessing; +namespace Phpml\Tests\Preprocessing; use Phpml\Preprocessing\Imputer; use Phpml\Preprocessing\Imputer\Strategy\MeanStrategy; diff --git a/tests/Phpml/Preprocessing/NormalizerTest.php b/tests/Phpml/Preprocessing/NormalizerTest.php index 5dfc207..ea762da 100644 --- a/tests/Phpml/Preprocessing/NormalizerTest.php +++ b/tests/Phpml/Preprocessing/NormalizerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Preprocessing; +namespace Phpml\Tests\Preprocessing; use Phpml\Exception\NormalizerException; use Phpml\Preprocessing\Normalizer; diff --git a/tests/Phpml/Regression/LeastSquaresTest.php b/tests/Phpml/Regression/LeastSquaresTest.php index 7517a9b..71215bc 100644 --- a/tests/Phpml/Regression/LeastSquaresTest.php +++ b/tests/Phpml/Regression/LeastSquaresTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Regression; +namespace Phpml\Tests\Regression; use Phpml\ModelManager; use Phpml\Regression\LeastSquares; diff --git a/tests/Phpml/Regression/SVRTest.php b/tests/Phpml/Regression/SVRTest.php index a220d21..d2fdefb 100644 --- a/tests/Phpml/Regression/SVRTest.php +++ b/tests/Phpml/Regression/SVRTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Regression; +namespace Phpml\Tests\Regression; use Phpml\ModelManager; use Phpml\Regression\SVR; diff --git a/tests/Phpml/SupportVectorMachine/DataTransformerTest.php b/tests/Phpml/SupportVectorMachine/DataTransformerTest.php index b1f8522..1db1fdf 100644 --- a/tests/Phpml/SupportVectorMachine/DataTransformerTest.php +++ b/tests/Phpml/SupportVectorMachine/DataTransformerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\SupportVectorMachine; +namespace Phpml\Tests\SupportVectorMachine; use Phpml\SupportVectorMachine\DataTransformer; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php b/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php index 59154e3..180b8d3 100644 --- a/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php +++ b/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\SupportVectorMachine; +namespace Phpml\Tests\SupportVectorMachine; use Phpml\Exception\InvalidArgumentException; use Phpml\SupportVectorMachine\Kernel; diff --git a/tests/Phpml/Tokenization/WhitespaceTokenizerTest.php b/tests/Phpml/Tokenization/WhitespaceTokenizerTest.php index f9d7c73..b9e40c0 100644 --- a/tests/Phpml/Tokenization/WhitespaceTokenizerTest.php +++ b/tests/Phpml/Tokenization/WhitespaceTokenizerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Tokenization; +namespace Phpml\Tests\Tokenization; use Phpml\Tokenization\WhitespaceTokenizer; use PHPUnit\Framework\TestCase; diff --git a/tests/Phpml/Tokenization/WordTokenizerTest.php b/tests/Phpml/Tokenization/WordTokenizerTest.php index 607c327..d18edb6 100644 --- a/tests/Phpml/Tokenization/WordTokenizerTest.php +++ b/tests/Phpml/Tokenization/WordTokenizerTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\Phpml\Tokenization; +namespace Phpml\Tests\Tokenization; use Phpml\Tokenization\WordTokenizer; use PHPUnit\Framework\TestCase;