Skip to content

Commit

Permalink
Update to phpunit 8 and bump min php to 7.2 (#367)
Browse files Browse the repository at this point in the history
* Update to phpunit 8

* Require at least PHP 7.2
  • Loading branch information
marmichalski authored and akondas committed Apr 10, 2019
1 parent cefb4fc commit db82afa
Show file tree
Hide file tree
Showing 43 changed files with 176 additions and 179 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
.php_cs.cache
/build
/tests/Performance/Data/*.csv
.php_cs.cache
.phpunit.result.cache
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ matrix:
fast_finish: true

include:
- os: linux
php: '7.1'
env: DISABLE_XDEBUG="true" STATIC_ANALYSIS="true"

- os: linux
php: '7.2'
env: PHPUNIT_FLAGS="--coverage-clover build/logs/clover.xml"
env: PHPUNIT_FLAGS="--coverage-clover build/logs/clover.xml" DISABLE_XDEBUG="true" STATIC_ANALYSIS="true"

- os: linux
php: '7.3'

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PHP-ML - Machine Learning library for PHP

[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
[![Latest Stable Version](https://img.shields.io/packagist/v/php-ai/php-ml.svg)](https://packagist.org/packages/php-ai/php-ml)
[![Build Status](https://travis-ci.org/php-ai/php-ml.svg?branch=master)](https://travis-ci.org/php-ai/php-ml)
[![Documentation Status](https://readthedocs.org/projects/php-ml/badge/?version=master)](http://php-ml.readthedocs.org/)
Expand All @@ -15,7 +15,7 @@

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.1.
PHP-ML requires PHP >= 7.2.

Simple example of classification:
```php
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.2"
},
"require-dev": {
"phpbench/phpbench": "^0.14.0",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11",
"phpunit/phpunit": "^7.0.0",
"phpunit/phpunit": "^8.0",
"symplify/coding-standard": "^5.1",
"symplify/easy-coding-standard": "^5.1"
},
Expand Down
71 changes: 36 additions & 35 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PHP-ML - Machine Learning library for PHP

[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
[![Latest Stable Version](https://img.shields.io/packagist/v/php-ai/php-ml.svg)](https://packagist.org/packages/php-ai/php-ml)
[![Build Status](https://travis-ci.org/php-ai/php-ml.svg?branch=master)](https://travis-ci.org/php-ai/php-ml)
[![Documentation Status](https://readthedocs.org/projects/php-ml/badge/?version=master)](http://php-ml.readthedocs.org/)
Expand All @@ -15,7 +15,7 @@

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.1.
PHP-ML requires PHP >= 7.2.

Simple example of classification:
```php
Expand Down
10 changes: 5 additions & 5 deletions tests/Classification/Linear/LogisticRegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ public function testPredictProbabilitySingleSample(): void

$zero = $method->invoke($predictor, [0.1, 0.1], 0);
$one = $method->invoke($predictor, [0.1, 0.1], 1);
self::assertEquals(1, $zero + $one, '', 1e-6);
self::assertEqualsWithDelta(1, $zero + $one, 1e-6);
self::assertTrue($zero > $one);

$zero = $method->invoke($predictor, [0.9, 0.9], 0);
$one = $method->invoke($predictor, [0.9, 0.9], 1);
self::assertEquals(1, $zero + $one, '', 1e-6);
self::assertEqualsWithDelta(1, $zero + $one, 1e-6);
self::assertTrue($zero < $one);
}

Expand Down Expand Up @@ -213,9 +213,9 @@ public function testPredictProbabilityMultiClassSample(): void
$two = $method->invoke($predictor, [3.0, 9.5], 2);
$not_two = $method->invoke($predictor, [3.0, 9.5], 'not_2');

self::assertEquals(1, $zero + $not_zero, '', 1e-6);
self::assertEquals(1, $one + $not_one, '', 1e-6);
self::assertEquals(1, $two + $not_two, '', 1e-6);
self::assertEqualsWithDelta(1, $zero + $not_zero, 1e-6);
self::assertEqualsWithDelta(1, $one + $not_one, 1e-6);
self::assertEqualsWithDelta(1, $two + $not_two, 1e-6);
self::assertTrue($zero < $two);
self::assertTrue($one < $two);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/DimensionReduction/KernelPCATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ public function testKernelPCA(): void
[-0.13128352866095], [-0.20865959471756], [-0.17531601535848], [0.4240660966961],
[0.36351946685163], [-0.14334173054136], [0.22454914091011], [0.15035027480881], ];

$kpca = new KernelPCA(KernelPCA::KERNEL_RBF, null, 1, 15);
$kpca = new KernelPCA(KernelPCA::KERNEL_RBF, null, 1, 15.);
$reducedData = $kpca->fit($data);

// Due to the fact that the sign of values can be flipped
// during the calculation of eigenValues, we have to compare
// absolute value of the values
array_map(function ($val1, $val2) use ($epsilon): void {
self::assertEquals(abs($val1), abs($val2), '', $epsilon);
self::assertEqualsWithDelta(abs($val1), abs($val2), $epsilon);
}, $transformed, $reducedData);

// Fitted KernelPCA object can also transform an arbitrary sample of the
// same dimensionality with the original dataset
$newData = [1.25, 2.25];
$newTransformed = [0.18956227539216];
$newTransformed2 = $kpca->transform($newData);
self::assertEquals(abs($newTransformed[0]), abs($newTransformed2[0]), '', $epsilon);
self::assertEqualsWithDelta(abs($newTransformed[0]), abs($newTransformed2[0]), $epsilon);
}

public function testKernelPCAThrowWhenKernelInvalid(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/DimensionReduction/LDATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testLDA(): void
// absolute value of the values
$row1 = array_map('abs', $row1);
$row2 = array_map('abs', $row2);
self::assertEquals($row1, $row2, '', $epsilon);
self::assertEqualsWithDelta($row1, $row2, $epsilon);
};
array_map($check, $control, $transformed2);

Expand Down
4 changes: 2 additions & 2 deletions tests/DimensionReduction/PCATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testPCA(): void
// during the calculation of eigenValues, we have to compare
// absolute value of the values
array_map(function ($val1, $val2) use ($epsilon): void {
self::assertEquals(abs($val1), abs($val2), '', $epsilon);
self::assertEqualsWithDelta(abs($val1), abs($val2), $epsilon);
}, $transformed, $reducedData);

// Test fitted PCA object to transform an arbitrary sample of the
Expand All @@ -52,7 +52,7 @@ public function testPCA(): void
$newRow2 = $pca->transform($row);

array_map(function ($val1, $val2) use ($epsilon): void {
self::assertEquals(abs($val1), abs($val2), '', $epsilon);
self::assertEqualsWithDelta(abs($val1), abs($val2), $epsilon);
}, $newRow, $newRow2);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FeatureExtraction/TfIdfTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public function testTfIdfTransformation(): void
$transformer = new TfIdfTransformer($samples);
$transformer->transform($samples);

self::assertEquals($tfIdfSamples, $samples, '', 0.001);
self::assertEqualsWithDelta($tfIdfSamples, $samples, 0.001);
}
}
3 changes: 1 addition & 2 deletions tests/FeatureSelection/ScoringFunction/ANOVAFValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public function testScoreForANOVAFValue(): void
$dataset = new IrisDataset();
$function = new ANOVAFValue();

self::assertEquals(
self::assertEqualsWithDelta(
[119.2645, 47.3644, 1179.0343, 959.3244],
$function->score($dataset->getSamples(), $dataset->getTargets()),
'',
0.0001
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testRegressionScore(): void
$targets = [2000, 2750, 15500, 960, 4400, 8800, 7100, 2550, 1025, 5900, 4600, 4400];

$function = new UnivariateLinearRegression();
self::assertEquals([6.97286, 6.48558], $function->score($samples, $targets), '', 0.0001);
self::assertEqualsWithDelta([6.97286, 6.48558], $function->score($samples, $targets), 0.0001);
}

public function testRegressionScoreWithoutCenter(): void
Expand All @@ -24,6 +24,6 @@ public function testRegressionScoreWithoutCenter(): void
$targets = [2000, 2750, 15500, 960, 4400, 8800, 7100, 2550, 1025, 5900, 4600, 4400];

$function = new UnivariateLinearRegression(false);
self::assertEquals([1.74450, 18.08347], $function->score($samples, $targets), '', 0.0001);
self::assertEqualsWithDelta([1.74450, 18.08347], $function->score($samples, $targets), 0.0001);
}
}
Loading

0 comments on commit db82afa

Please sign in to comment.