Minor performance boost

This commit is contained in:
Jens True 2024-03-19 12:49:14 +00:00
parent 7b09658c25
commit fd91e9b0c1
2 changed files with 47 additions and 40 deletions

70
composer.lock generated

@ -822,21 +822,21 @@
},
{
"name": "nikic/php-parser",
"version": "v4.18.0",
"version": "v4.19.1",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999"
"reference": "4e1b88d21c69391150ace211e9eaf05810858d0b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1bcbb2179f97633e98bbbc87044ee2611c7d7999",
"reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4e1b88d21c69391150ace211e9eaf05810858d0b",
"reference": "4e1b88d21c69391150ace211e9eaf05810858d0b",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=7.0"
"php": ">=7.1"
},
"require-dev": {
"ircmaxell/php-yacc": "^0.0.7",
@ -872,9 +872,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.18.0"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.19.1"
},
"time": "2023-12-10T21:03:43+00:00"
"time": "2024-03-17T08:10:35+00:00"
},
{
"name": "phar-io/manifest",
@ -1287,16 +1287,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.10.60",
"version": "1.10.63",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe"
"reference": "ad12836d9ca227301f5fb9960979574ed8628339"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/95dcea7d6c628a3f2f56d091d8a0219485a86bbe",
"reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/ad12836d9ca227301f5fb9960979574ed8628339",
"reference": "ad12836d9ca227301f5fb9960979574ed8628339",
"shasum": ""
},
"require": {
@ -1345,20 +1345,20 @@
"type": "tidelift"
}
],
"time": "2024-03-07T13:30:19+00:00"
"time": "2024-03-18T16:53:53+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "10.1.13",
"version": "10.1.14",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "d51c3aec14896d5e80b354fad58e998d1980f8f8"
"reference": "e3f51450ebffe8e0efdf7346ae966a656f7d5e5b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d51c3aec14896d5e80b354fad58e998d1980f8f8",
"reference": "d51c3aec14896d5e80b354fad58e998d1980f8f8",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/e3f51450ebffe8e0efdf7346ae966a656f7d5e5b",
"reference": "e3f51450ebffe8e0efdf7346ae966a656f7d5e5b",
"shasum": ""
},
"require": {
@ -1415,7 +1415,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.13"
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.14"
},
"funding": [
{
@ -1423,7 +1423,7 @@
"type": "github"
}
],
"time": "2024-03-09T16:54:15+00:00"
"time": "2024-03-12T15:33:41+00:00"
},
{
"name": "phpunit/php-file-iterator",
@ -1670,16 +1670,16 @@
},
{
"name": "phpunit/phpunit",
"version": "10.5.12",
"version": "10.5.13",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "41a9886b85ac7bf3929853baf96b95361cd69d2b"
"reference": "20a63fc1c6db29b15da3bd02d4b6cf59900088a7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/41a9886b85ac7bf3929853baf96b95361cd69d2b",
"reference": "41a9886b85ac7bf3929853baf96b95361cd69d2b",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/20a63fc1c6db29b15da3bd02d4b6cf59900088a7",
"reference": "20a63fc1c6db29b15da3bd02d4b6cf59900088a7",
"shasum": ""
},
"require": {
@ -1751,7 +1751,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.12"
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.13"
},
"funding": [
{
@ -1767,7 +1767,7 @@
"type": "tidelift"
}
],
"time": "2024-03-09T12:04:07+00:00"
"time": "2024-03-12T15:37:41+00:00"
},
{
"name": "psalm/plugin-phpunit",
@ -1934,16 +1934,16 @@
},
{
"name": "rector/rector",
"version": "1.0.2",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/rectorphp/rector.git",
"reference": "7596fa6da06c6a20c012efe6bb3d9188a9113b11"
"reference": "c59507a9090b465d65e1aceed91e5b81986e375b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/rectorphp/rector/zipball/7596fa6da06c6a20c012efe6bb3d9188a9113b11",
"reference": "7596fa6da06c6a20c012efe6bb3d9188a9113b11",
"url": "https://api.github.com/repos/rectorphp/rector/zipball/c59507a9090b465d65e1aceed91e5b81986e375b",
"reference": "c59507a9090b465d65e1aceed91e5b81986e375b",
"shasum": ""
},
"require": {
@ -1978,7 +1978,7 @@
],
"support": {
"issues": "https://github.com/rectorphp/rector/issues",
"source": "https://github.com/rectorphp/rector/tree/1.0.2"
"source": "https://github.com/rectorphp/rector/tree/1.0.3"
},
"funding": [
{
@ -1986,7 +1986,7 @@
"type": "github"
}
],
"time": "2024-03-03T12:32:31+00:00"
"time": "2024-03-14T15:04:18+00:00"
},
{
"name": "sebastian/cli-parser",
@ -3661,16 +3661,16 @@
},
{
"name": "vimeo/psalm",
"version": "5.23.0",
"version": "5.23.1",
"source": {
"type": "git",
"url": "https://github.com/vimeo/psalm.git",
"reference": "005e3184fb6de4350a873b9b8c4dc3cede9db762"
"reference": "8471a896ccea3526b26d082f4461eeea467f10a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/005e3184fb6de4350a873b9b8c4dc3cede9db762",
"reference": "005e3184fb6de4350a873b9b8c4dc3cede9db762",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/8471a896ccea3526b26d082f4461eeea467f10a4",
"reference": "8471a896ccea3526b26d082f4461eeea467f10a4",
"shasum": ""
},
"require": {
@ -3767,7 +3767,7 @@
"issues": "https://github.com/vimeo/psalm/issues",
"source": "https://github.com/vimeo/psalm"
},
"time": "2024-03-09T19:39:11+00:00"
"time": "2024-03-11T20:33:46+00:00"
},
{
"name": "webmozart/assert",

@ -12,6 +12,8 @@ namespace DNW\Skills\Numerics;
*/
class GaussianDistribution implements \Stringable
{
private const DEFAULT_STANDARD_DEVIATION = 1.0;
private const DEFAULT_MEAN = 0.0;
/**
* Square Root 2π.
* Precalculated constant for performance reasons
@ -32,16 +34,21 @@ class GaussianDistribution implements \Stringable
// precision and precisionMean are used because they make multiplying and dividing simpler
// (the the accompanying math paper for more details)
private float $precision;
private float $precision = 1.0;
private float $precisionMean;
private float $precisionMean = 0.0;
private float $variance;
private float $variance = 1.0;
public function __construct(private float $mean = 0.0, private float $standardDeviation = 1.0)
public function __construct(private float $mean = self::DEFAULT_MEAN, private float $standardDeviation = self::DEFAULT_STANDARD_DEVIATION)
{
$this->variance = BasicMath::square($standardDeviation);
if($mean == self::DEFAULT_MEAN && $standardDeviation == self::DEFAULT_STANDARD_DEVIATION)
{
//Use all the defaults
return;
}
$this->variance = BasicMath::square($standardDeviation);
if ($this->variance != 0) {
$this->precision = 1.0 / $this->variance;
$this->precisionMean = $this->precision * $this->mean;