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
This commit is contained in:
Tomáš Votruba 2018-01-06 13:09:33 +01:00 committed by Arkadiusz Kondas
parent fbbe5c5761
commit a348111e97
103 changed files with 365 additions and 284 deletions

32
.php_cs
View File

@ -1,32 +0,0 @@
<?php
return PhpCsFixer\Config::create()
->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);

View File

@ -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:
- |

View File

@ -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

View File

@ -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"
}
}
}

184
composer.lock generated
View File

@ -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,

View File

@ -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

View File

@ -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

19
phpstan.neon Normal file
View File

@ -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#'

View File

@ -244,6 +244,7 @@ class Apriori implements Associator
foreach ((array) $this->samples as $sample) {
if ($this->subset($sample, $candidate)) {
$candidates[] = $candidate;
continue 2;
}
}

View File

@ -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)
{

View File

@ -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;

View File

@ -31,7 +31,7 @@ class Bagging implements Classifier
protected $numClassifier;
/**
* @var Classifier
* @var string
*/
protected $classifier = DecisionTree::class;

View File

@ -21,7 +21,7 @@ class Adaline extends Perceptron
/**
* Training type may be either 'Batch' or 'Online' learning
*
* @var string
* @var string|int
*/
protected $trainingType;

View File

@ -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,

View File

@ -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);
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -30,7 +30,7 @@ class KernelPCA extends PCA
/**
* Gamma value used by the kernel
*
* @var float
* @var float|null
*/
protected $gamma;

View File

@ -15,7 +15,7 @@ class TokenCountVectorizer implements Transformer
private $tokenizer;
/**
* @var StopWords
* @var StopWords|null
*/
private $stopWords;

View File

@ -33,7 +33,7 @@ trait OneVsRest
// Clears previous stuff.
$this->reset();
$this->trainBylabel($samples, $targets);
$this->trainByLabel($samples, $targets);
}
/**

View File

@ -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
{

View File

@ -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;
}
/**

View File

@ -88,6 +88,8 @@ class EigenvalueDecomposition
private $cdivi;
private $A;
/**
* Constructor: Check for symmetry, then construct the eigenvalue decomposition
*/

View File

@ -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) {

View File

@ -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
{

View File

@ -91,6 +91,7 @@ class ClassificationReport
$values = array_filter($this->{$metric});
if (empty($values)) {
$this->average[$metric] = 0.0;
continue;
}

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -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 = [])
{

View File

@ -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);
}

View File

@ -37,7 +37,7 @@ class SupportVectorMachine
private $degree;
/**
* @var float
* @var float|null
*/
private $gamma;

View File

@ -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
*/

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Classification;
namespace Phpml\Tests\Classification;
use Phpml\Classification\DecisionTree;
use Phpml\ModelManager;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Classification;
namespace Phpml\Tests\Classification;
use Phpml\Classification\MLPClassifier;
use Phpml\Exception\InvalidArgumentException;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Classification;
namespace Phpml\Tests\Classification;
use Phpml\Classification\NaiveBayes;
use Phpml\ModelManager;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Classification;
namespace Phpml\Tests\Classification;
use Phpml\Classification\SVC;
use Phpml\ModelManager;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Clustering;
namespace Phpml\Tests\Clustering;
use Phpml\Clustering\DBSCAN;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Clustering;
namespace Phpml\Tests\Clustering;
use Phpml\Clustering\FuzzyCMeans;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Clustering;
namespace Phpml\Tests\Clustering;
use Phpml\Clustering\KMeans;
use Phpml\Exception\InvalidArgumentException;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\CrossValidation;
namespace Phpml\Tests\CrossValidation;
use Phpml\CrossValidation\RandomSplit;
use Phpml\Dataset\ArrayDataset;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\CrossValidation;
namespace Phpml\Tests\CrossValidation;
use Phpml\CrossValidation\StratifiedRandomSplit;
use Phpml\Dataset\ArrayDataset;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Dataset;
namespace Phpml\Tests\Dataset;
use Phpml\Dataset\ArrayDataset;
use Phpml\Exception\InvalidArgumentException;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Dataset;
namespace Phpml\Tests\Dataset;
use Phpml\Dataset\CsvDataset;
use Phpml\Exception\FileException;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Dataset;
namespace Phpml\Tests\Dataset;
use Phpml\Dataset\FilesDataset;
use Phpml\Exception\DatasetException;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\DimensionReduction;
namespace Phpml\Tests\DimensionReduction;
use Phpml\DimensionReduction\KernelPCA;
use PHPUnit\Framework\TestCase;

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\DimensionReduction;
namespace Phpml\Tests\DimensionReduction;
use Phpml\DimensionReduction\PCA;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\FeatureExtraction;
namespace Phpml\Tests\FeatureExtraction;
use Phpml\Exception\InvalidArgumentException;
use Phpml\FeatureExtraction\StopWords;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\FeatureExtraction;
namespace Phpml\Tests\FeatureExtraction;
use Phpml\FeatureExtraction\TfIdfTransformer;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\FeatureExtraction;
namespace Phpml\Tests\FeatureExtraction;
use Phpml\FeatureExtraction\StopWords;
use Phpml\FeatureExtraction\TokenCountVectorizer;

View File

@ -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
*/

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Math;
namespace Phpml\Tests\Math;
use Phpml\Exception\InvalidArgumentException;
use Phpml\Exception\MatrixException;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Math;
namespace Phpml\Tests\Math;
use Phpml\Math\Product;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Math;
namespace Phpml\Tests\Math;
use Phpml\Math\Set;
use PHPUnit\Framework\TestCase;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Metric;
namespace Phpml\Tests\Metric;
use Phpml\Classification\SVC;
use Phpml\CrossValidation\RandomSplit;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Metric;
namespace Phpml\Tests\Metric;
use Phpml\Metric\ClassificationReport;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Metric;
namespace Phpml\Tests\Metric;
use Phpml\Metric\ConfusionMatrix;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests;
namespace Phpml\Tests;
use Phpml\Exception\FileException;
use Phpml\ModelManager;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\NeuralNetwork;
namespace Phpml\Tests\NeuralNetwork;
use Phpml\Exception\InvalidArgumentException;
use Phpml\NeuralNetwork\Layer;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests;
namespace Phpml\Tests;
use Phpml\Classification\SVC;
use Phpml\FeatureExtraction\TfIdfTransformer;

View File

@ -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;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Preprocessing;
namespace Phpml\Tests\Preprocessing;
use Phpml\Exception\NormalizerException;
use Phpml\Preprocessing\Normalizer;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Regression;
namespace Phpml\Tests\Regression;
use Phpml\ModelManager;
use Phpml\Regression\LeastSquares;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\Regression;
namespace Phpml\Tests\Regression;
use Phpml\ModelManager;
use Phpml\Regression\SVR;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace tests\Phpml\SupportVectorMachine;
namespace Phpml\Tests\SupportVectorMachine;
use Phpml\SupportVectorMachine\DataTransformer;
use PHPUnit\Framework\TestCase;

Some files were not shown because too many files have changed in this diff Show More