@@ -25,6 +25,6 @@ |
||
| 25 | 25 | return $sample; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - abstract public function rangeRandom($min = 0, $max = PHP_INT_MAX, int $maxIterations = 20): ImmutableDecimal; |
|
| 28 | + abstract public function rangeRandom($min = 0, $max = PHP_INT_MAX, int $maxIterations = 20): ImmutableDecimal; |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | { |
| 19 | 19 | $sample = new NumberCollection(); |
| 20 | 20 | |
| 21 | - for ($i = 1;$i < $sampleSize;$i++) { |
|
| 21 | + for ($i = 1; $i < $sampleSize; $i++) { |
|
| 22 | 22 | $sample->push($this->random()); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | ->multiply($e->pow($eExponent)) |
| 50 | 50 | ->multiply(SeriesProvider::maclaurinSeries( |
| 51 | 51 | $x, |
| 52 | - function ($n) { |
|
| 52 | + function($n) { |
|
| 53 | 53 | return Numbers::makeOne(); |
| 54 | 54 | }, |
| 55 | - function ($n) { |
|
| 55 | + function($n) { |
|
| 56 | 56 | return SequenceProvider::nthOddNumber($n); |
| 57 | 57 | }, |
| 58 | - function ($n) { |
|
| 58 | + function($n) { |
|
| 59 | 59 | return SequenceProvider::nthOddNumber($n)->doubleFactorial(); |
| 60 | 60 | }, |
| 61 | 61 | 0, |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
| 96 | 96 | |
| 97 | 97 | $scale = $x->getScale(); |
| 98 | - $internalScale = $scale + 2; |
|
| 98 | + $internalScale = $scale+2; |
|
| 99 | 99 | |
| 100 | 100 | $answer = Numbers::makeOne($internalScale); |
| 101 | 101 | $pi = Numbers::makePi($internalScale); |
@@ -105,15 +105,15 @@ discard block |
||
| 105 | 105 | $answer = $answer->multiply( |
| 106 | 106 | SeriesProvider::maclaurinSeries( |
| 107 | 107 | $x, |
| 108 | - function ($n) { |
|
| 108 | + function($n) { |
|
| 109 | 109 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1); |
| 110 | 110 | |
| 111 | 111 | return $negOne->pow($n); |
| 112 | 112 | }, |
| 113 | - function ($n) { |
|
| 113 | + function($n) { |
|
| 114 | 114 | return SequenceProvider::nthOddNumber($n); |
| 115 | 115 | }, |
| 116 | - function ($n) { |
|
| 116 | + function($n) { |
|
| 117 | 117 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
| 118 | 118 | |
| 119 | 119 | return $n->factorial()->multiply(SequenceProvider::nthOddNumber($n->asInt())); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $p = Numbers::makeOrDont(Numbers::IMMUTABLE, $p); |
| 141 | 141 | |
| 142 | 142 | $scale = $scale ?? $p->getScale(); |
| 143 | - $internalScale = $scale + 2; |
|
| 143 | + $internalScale = $scale+2; |
|
| 144 | 144 | |
| 145 | 145 | $two = Numbers::make(Numbers::IMMUTABLE, 2, $internalScale); |
| 146 | 146 | $invErfArg = $two->multiply($p)->subtract(1); |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | public static function inverseErrorCoefficients(int $termIndex): ImmutableFraction |
| 186 | 186 | { |
| 187 | 187 | |
| 188 | - $terms =& static::$inverseErrorCoefs; |
|
| 188 | + $terms = & static::$inverseErrorCoefs; |
|
| 189 | 189 | |
| 190 | 190 | if (is_null(static::$inverseErrorCoefs)) { |
| 191 | 191 | $terms = new Vector(); |
@@ -199,13 +199,13 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $nextTerm = $terms->count(); |
| 201 | 201 | |
| 202 | - for ($k = $nextTerm;$k <= $termIndex;$k++) { |
|
| 202 | + for ($k = $nextTerm; $k <= $termIndex; $k++) { |
|
| 203 | 203 | $termValue = new ImmutableFraction(new ImmutableDecimal('0'), new ImmutableDecimal('1')); |
| 204 | - for ($m = 0;$m <= ($k - 1);$m++) { |
|
| 204 | + for ($m = 0; $m <= ($k-1); $m++) { |
|
| 205 | 205 | $part1 = $terms->get($m); |
| 206 | - $part2 = $terms->get($k - 1 - $m); |
|
| 206 | + $part2 = $terms->get($k-1-$m); |
|
| 207 | 207 | $part3 = $part1->multiply($part2); |
| 208 | - $part4 = ($m + 1)*($m*2 + 1); |
|
| 208 | + $part4 = ($m+1)*($m*2+1); |
|
| 209 | 209 | $part5 = $part3->divide($part4); |
| 210 | 210 | $termValue = $termValue->add($part5); |
| 211 | 211 | } |
@@ -234,23 +234,23 @@ discard block |
||
| 234 | 234 | $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $z); |
| 235 | 235 | |
| 236 | 236 | $scale = $scale ?? $z->getScale(); |
| 237 | - $internalScale = $scale + 1; |
|
| 237 | + $internalScale = $scale+1; |
|
| 238 | 238 | |
| 239 | 239 | $pi = Numbers::makePi($internalScale); |
| 240 | 240 | |
| 241 | 241 | $answer = SeriesProvider::maclaurinSeries( |
| 242 | 242 | $z, |
| 243 | - static function ($n) use ($pi) { |
|
| 243 | + static function($n) use ($pi) { |
|
| 244 | 244 | if ($n > 0) { |
| 245 | 245 | return $pi->pow($n)->multiply(StatsProvider::inverseErrorCoefficients($n)); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | return Numbers::makeOne(); |
| 249 | 249 | }, |
| 250 | - static function ($n) { |
|
| 250 | + static function($n) { |
|
| 251 | 251 | return SequenceProvider::nthOddNumber($n); |
| 252 | 252 | }, |
| 253 | - static function ($n) { |
|
| 253 | + static function($n) { |
|
| 254 | 254 | if ($n > 0) { |
| 255 | 255 | $extra = Numbers::make(Numbers::IMMUTABLE, 2)->pow(SequenceProvider::nthEvenNumber($n)); |
| 256 | 256 | } else { |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | ); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $internalScale = $scale + 2; |
|
| 79 | + $internalScale = $scale+2; |
|
| 80 | 80 | |
| 81 | 81 | $cumulative = Numbers::makeZero(); |
| 82 | 82 | |
| 83 | - for ($i = 0;$x->isGreaterThanOrEqualTo($i);$i++) {
|
|
| 83 | + for ($i = 0; $x->isGreaterThanOrEqualTo($i); $i++) {
|
|
| 84 | 84 | $cumulative = $cumulative->add($this->pmf($i, $internalScale))->truncateToScale($scale); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @throws IntegrityConstraint |
| 96 | 96 | * @throws IncompatibleObjectState |
| 97 | 97 | */ |
| 98 | - public function pmf(float|int|DecimalInterface $x, int $scale = 10): ImmutableDecimal |
|
| 98 | + public function pmf(float | int | DecimalInterface $x, int $scale = 10): ImmutableDecimal |
|
| 99 | 99 | {
|
| 100 | 100 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
| 101 | 101 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | ); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $internalScale = $scale + 2; |
|
| 110 | + $internalScale = $scale+2; |
|
| 111 | 111 | |
| 112 | 112 | $e = Numbers::makeE($internalScale); |
| 113 | 113 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | $cumulative = Numbers::makeZero(); |
| 151 | 151 | |
| 152 | - for (;$larger->isGreaterThanOrEqualTo($smaller);$smaller = $smaller->add(1)) {
|
|
| 152 | + for (;$larger->isGreaterThanOrEqualTo($smaller); $smaller = $smaller->add(1)) {
|
|
| 153 | 153 | $cumulative = $cumulative->add($this->pmf($smaller)); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | while (true) {
|
| 239 | 239 | /** @var ImmutableDecimal $u */ |
| 240 | - $u = PolyfillProvider::randomInt(0, PHP_INT_MAX) / PHP_INT_MAX; |
|
| 240 | + $u = PolyfillProvider::randomInt(0, PHP_INT_MAX)/PHP_INT_MAX; |
|
| 241 | 241 | /** @var ImmutableDecimal $x */ |
| 242 | 242 | $x = $alpha->subtract($one->subtract($u)->divide($u)->ln(20)->divide($beta)); |
| 243 | 243 | /** @var ImmutableDecimal $n */ |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | do {
|
| 292 | 292 | $k = $k->add(1); |
| 293 | 293 | /** @var ImmutableDecimal $u */ |
| 294 | - $u = PolyfillProvider::randomInt(0, PHP_INT_MAX) / PHP_INT_MAX; |
|
| 294 | + $u = PolyfillProvider::randomInt(0, PHP_INT_MAX)/PHP_INT_MAX; |
|
| 295 | 295 | $p = $p->multiply($u); |
| 296 | 296 | } while ($p->isGreaterThan($L)); |
| 297 | 297 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $internalScale = $scale + 2; |
|
| 64 | + $internalScale = $scale+2; |
|
| 65 | 65 | |
| 66 | 66 | /** @var ImmutableDecimal $e */ |
| 67 | 67 | $e = Numbers::makeE($internalScale); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | ); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $internalScale = $scale + 2; |
|
| 95 | + $internalScale = $scale+2; |
|
| 96 | 96 | |
| 97 | 97 | /** @var ImmutableDecimal $e */ |
| 98 | 98 | $e = Numbers::makeE($internalScale); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | ); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - $internalScale = $scale + 2; |
|
| 127 | + $internalScale = $scale+2; |
|
| 128 | 128 | |
| 129 | 129 | /** @var ImmutableDecimal $rangePdf */ |
| 130 | 130 | $rangePdf = $this->pdf($x2, $internalScale)->subtract($this->pdf($x1, $internalScale))->abs()->truncateToScale($scale); |
@@ -80,7 +80,7 @@ |
||
| 80 | 80 | $e = Numbers::makeE($scale); |
| 81 | 81 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
| 82 | 82 | |
| 83 | - $internalScale = (new NumberCollection([$scale, $x]))->selectScale() + 2; |
|
| 83 | + $internalScale = (new NumberCollection([$scale, $x]))->selectScale()+2; |
|
| 84 | 84 | |
| 85 | 85 | // $left = 1 / ( sqrt(2pi * SD^2) ) |
| 86 | 86 | $left = $one->divide($twoPi->multiply($this->getSD()->pow(2))->sqrt($internalScale), $internalScale); |