@@ -2,10 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Context; |
4 | 4 | |
5 | -use Samsara\Fermat\Context\Base\BaseContext; |
|
6 | -use Samsara\Fermat\Numbers; |
|
7 | -use Samsara\Fermat\Provider\BCProvider; |
|
8 | -use Samsara\Fermat\Provider\GaussianProvider; |
|
5 | +use Samsara\Fermat\Context\Base\BaseContext; |
|
6 | +use Samsara\Fermat\Numbers; |
|
7 | +use Samsara\Fermat\Provider\BCProvider; |
|
8 | +use Samsara\Fermat\Provider\GaussianProvider; |
|
9 | 9 | use Samsara\Fermat\Values\Base\NumberInterface; |
10 | 10 | |
11 | 11 | /** |
@@ -85,6 +85,9 @@ |
||
85 | 85 | return $this->PDFByValue($value); |
86 | 86 | } |
87 | 87 | |
88 | + /** |
|
89 | + * @param NumberInterface $value |
|
90 | + */ |
|
88 | 91 | public function PDFByValue($value) |
89 | 92 | { |
90 | 93 | $value = Numbers::makeOrDont($this->numberType, $value); |
@@ -2,12 +2,12 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Context; |
4 | 4 | |
5 | -use RandomLib\Factory; |
|
6 | -use Samsara\Fermat\Context\Base\BaseContext; |
|
7 | -use Samsara\Fermat\Context\Base\ContextInterface; |
|
8 | -use Samsara\Fermat\Numbers; |
|
9 | -use Samsara\Fermat\Provider\BCProvider; |
|
10 | -use Samsara\Fermat\Values\ImmutableNumber; |
|
5 | +use RandomLib\Factory; |
|
6 | +use Samsara\Fermat\Context\Base\BaseContext; |
|
7 | +use Samsara\Fermat\Context\Base\ContextInterface; |
|
8 | +use Samsara\Fermat\Numbers; |
|
9 | +use Samsara\Fermat\Provider\BCProvider; |
|
10 | +use Samsara\Fermat\Values\ImmutableNumber; |
|
11 | 11 | use Samsara\Fermat\Values\Base\NumberInterface; |
12 | 12 | |
13 | 13 | class UniformContext extends BaseContext implements ContextInterface |
@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat; |
4 | 4 | |
5 | -use Samsara\Fermat\Values\ImmutableFraction; |
|
6 | -use Samsara\Fermat\Values\ImmutableNumber; |
|
7 | -use Samsara\Fermat\Values\MutableNumber; |
|
5 | +use Samsara\Fermat\Values\ImmutableFraction; |
|
6 | +use Samsara\Fermat\Values\ImmutableNumber; |
|
7 | +use Samsara\Fermat\Values\MutableNumber; |
|
8 | 8 | use Samsara\Fermat\Values\Base\NumberInterface; |
9 | 9 | |
10 | 10 | class Numbers |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Provider\Stats\Distribution; |
4 | 4 | |
5 | -use Samsara\Fermat\Numbers; |
|
6 | -use Samsara\Fermat\Provider\Stats\Stats; |
|
5 | +use Samsara\Fermat\Numbers; |
|
6 | +use Samsara\Fermat\Provider\Stats\Stats; |
|
7 | 7 | use Samsara\Fermat\Values\Base\NumberInterface; |
8 | 8 | |
9 | 9 | class Normal |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Types; |
4 | 4 | |
5 | -use Samsara\Fermat\Numbers; |
|
5 | +use Samsara\Fermat\Numbers; |
|
6 | 6 | use Samsara\Fermat\Values\ImmutableNumber; |
7 | 7 | |
8 | 8 | class Tuple |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $cumulative = Numbers::makeZero(); |
34 | 34 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
35 | 35 | |
36 | - for ($i = 0;$x->greaterThanOrEqualTo($i);$i++) { |
|
36 | + for ($i = 0; $x->greaterThanOrEqualTo($i); $i++) { |
|
37 | 37 | $cumulative = $cumulative->add($this->pmf($i)); |
38 | 38 | } |
39 | 39 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | $cumulative = Numbers::makeZero(); |
64 | 64 | |
65 | - for (;$larger->greaterThanOrEqualTo($smaller);$smaller->add(1)) { |
|
65 | + for (;$larger->greaterThanOrEqualTo($smaller); $smaller->add(1)) { |
|
66 | 66 | $cumulative = $cumulative->add($this->pmf($smaller)); |
67 | 67 | } |
68 | 68 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | while ($p->lessThan($L)) { |
98 | 98 | $k = $k->add(1); |
99 | - $u = $randFactory->getMediumStrengthGenerator()->generateInt() / PHP_INT_MAX; |
|
99 | + $u = $randFactory->getMediumStrengthGenerator()->generateInt()/PHP_INT_MAX; |
|
100 | 100 | $p = $p->multiply($u); |
101 | 101 | } |
102 | 102 |
@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Provider\Stats\Distribution; |
4 | 4 | |
5 | -use RandomLib\Factory; |
|
6 | -use Samsara\Fermat\Numbers; |
|
7 | -use Samsara\Fermat\Provider\Stats\Distribution\Base\DistributionInterface; |
|
5 | +use RandomLib\Factory; |
|
6 | +use Samsara\Fermat\Numbers; |
|
7 | +use Samsara\Fermat\Provider\Stats\Distribution\Base\DistributionInterface; |
|
8 | 8 | use Samsara\Fermat\Values\Base\NumberInterface; |
9 | 9 | |
10 | 10 | class Poisson implements DistributionInterface |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | ->multiply($e->pow($eExponent)) |
33 | 33 | ->multiply(SeriesProvider::maclaurinSeries( |
34 | 34 | $x, |
35 | - function ($n) { |
|
35 | + function($n) { |
|
36 | 36 | return Numbers::makeOne(); |
37 | 37 | }, |
38 | - function ($n) { |
|
38 | + function($n) { |
|
39 | 39 | return SequenceProvider::nthOddNumber($n); |
40 | 40 | }, |
41 | - function ($n) { |
|
41 | + function($n) { |
|
42 | 42 | return SequenceProvider::nthOddNumber($n)->doubleFactorial(); |
43 | 43 | } |
44 | 44 | )) |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | $answer = $answer->multiply( |
69 | 69 | SeriesProvider::maclaurinSeries( |
70 | 70 | $x, |
71 | - function ($n) { |
|
71 | + function($n) { |
|
72 | 72 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1); |
73 | 73 | |
74 | 74 | return $negOne->pow($n); |
75 | 75 | }, |
76 | - function ($n) { |
|
76 | + function($n) { |
|
77 | 77 | return SequenceProvider::nthOddNumber($n); |
78 | 78 | }, |
79 | - function ($n) { |
|
79 | + function($n) { |
|
80 | 80 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
81 | 81 | |
82 | 82 | return $n->factorial()->multiply(SequenceProvider::nthOddNumber($n)); |
@@ -88,6 +88,9 @@ |
||
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | + /** |
|
92 | + * @param NumberInterface $p |
|
93 | + */ |
|
91 | 94 | public static function inverseNormalCDF($p, $precision = 10) |
92 | 95 | { |
93 | 96 | $pi = Numbers::makePi(); |
@@ -69,7 +69,7 @@ |
||
69 | 69 | |
70 | 70 | $t = Numbers::makeZero(); |
71 | 71 | |
72 | - for ($k = 0;$m->greaterThanOrEqualTo($k);$k++) { |
|
72 | + for ($k = 0; $m->greaterThanOrEqualTo($k); $k++) { |
|
73 | 73 | $kNum = Numbers::make(Numbers::IMMUTABLE, $k); |
74 | 74 | $combination = $m->factorial()->divide($kNum->factorial()->multiply($m->subtract($k)->factorial())); |
75 | 75 | $t = $t->add($combination->multiply(self::nthBernoulliNumber($k, $n))->divide($m->subtract($k)->add(1))); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | public function __construct($value, $precision = null, $base = 10) |
24 | 24 | { |
25 | 25 | $this->base = $base; |
26 | - $this->value = (string)$value; |
|
26 | + $this->value = (string) $value; |
|
27 | 27 | |
28 | 28 | if (!is_null($precision)) { |
29 | 29 | $this->precision = $precision; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $curVal = $this->getValue(); |
133 | 133 | $calcVal = Numbers::make(Numbers::IMMUTABLE, 1); |
134 | 134 | |
135 | - for ($i = 1;$i <= $curVal;$i++) { |
|
135 | + for ($i = 1; $i <= $curVal; $i++) { |
|
136 | 136 | $calcVal = $calcVal->multiply($i); |
137 | 137 | } |
138 | 138 | |
@@ -147,19 +147,19 @@ discard block |
||
147 | 147 | |
148 | 148 | if ($val->modulo(2)->equals(1)) { |
149 | 149 | $m = Numbers::make(Numbers::IMMUTABLE, $val->add(1)->divide(2)); |
150 | - $term = function ($n) { |
|
150 | + $term = function($n) { |
|
151 | 151 | return Numbers::make(Numbers::IMMUTABLE, 2)->multiply($n); |
152 | 152 | }; |
153 | 153 | } else { |
154 | 154 | $m = Numbers::make(Numbers::IMMUTABLE, $val->divide(2)); |
155 | - $term = function ($n) { |
|
155 | + $term = function($n) { |
|
156 | 156 | return Numbers::make(Numbers::IMMUTABLE, 2)->multiply($n)->subtract(1); |
157 | 157 | }; |
158 | 158 | } |
159 | 159 | |
160 | 160 | $newVal = Numbers::makeOne(); |
161 | 161 | |
162 | - for ($i = 1;$m->greaterThanOrEqualTo($i);$i++) { |
|
162 | + for ($i = 1; $m->greaterThanOrEqualTo($i); $i++) { |
|
163 | 163 | $newVal = $newVal->multiply($term($i)); |
164 | 164 | } |
165 | 165 | |
@@ -222,15 +222,15 @@ discard block |
||
222 | 222 | return $this->setValue( |
223 | 223 | SeriesProvider::maclaurinSeries( |
224 | 224 | Numbers::make(Numbers::IMMUTABLE, $value), |
225 | - function ($n) { |
|
225 | + function($n) { |
|
226 | 226 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1); |
227 | 227 | |
228 | 228 | return $negOne->pow($n); |
229 | 229 | }, |
230 | - function ($n) { |
|
230 | + function($n) { |
|
231 | 231 | return SequenceProvider::nthOddNumber($n); |
232 | 232 | }, |
233 | - function ($n) { |
|
233 | + function($n) { |
|
234 | 234 | return SequenceProvider::nthOddNumber($n)->factorial(); |
235 | 235 | }, |
236 | 236 | 0, |
@@ -266,13 +266,13 @@ discard block |
||
266 | 266 | return $this->setValue( |
267 | 267 | SeriesProvider::maclaurinSeries( |
268 | 268 | Numbers::make(Numbers::IMMUTABLE, $value), |
269 | - function ($n) { |
|
269 | + function($n) { |
|
270 | 270 | return SequenceProvider::nthPowerNegativeOne($n); |
271 | 271 | }, |
272 | - function ($n) { |
|
272 | + function($n) { |
|
273 | 273 | return SequenceProvider::nthEvenNumber($n); |
274 | 274 | }, |
275 | - function ($n) { |
|
275 | + function($n) { |
|
276 | 276 | return SequenceProvider::nthEvenNumber($n)->factorial(); |
277 | 277 | }, |
278 | 278 | 0, |
@@ -304,18 +304,18 @@ discard block |
||
304 | 304 | return $this->setValue( |
305 | 305 | SeriesProvider::maclaurinSeries( |
306 | 306 | Numbers::make(Numbers::IMMUTABLE, $value), |
307 | - function ($n) { |
|
307 | + function($n) { |
|
308 | 308 | $four = Numbers::make(Numbers::IMMUTABLE, 4); |
309 | 309 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
310 | 310 | |
311 | 311 | return SequenceProvider::nthBernoulliNumber($n->multiply(2)->getValue(), -4)->pow($n)->multiply(Numbers::makeOne()->subtract($four->pow($n))); |
312 | 312 | }, |
313 | - function ($n) { |
|
313 | + function($n) { |
|
314 | 314 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
315 | 315 | |
316 | 316 | return $n->multiply(2)->subtract(1); |
317 | 317 | }, |
318 | - function ($n) { |
|
318 | + function($n) { |
|
319 | 319 | return SequenceProvider::nthEvenNumber($n)->factorial(); |
320 | 320 | }, |
321 | 321 | 1, |
@@ -2,11 +2,11 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Types; |
4 | 4 | |
5 | -use Samsara\Fermat\Numbers; |
|
6 | -use Samsara\Fermat\Provider\BCProvider; |
|
7 | -use Riimu\Kit\BaseConversion\BaseConverter; |
|
8 | -use Samsara\Fermat\Provider\SequenceProvider; |
|
9 | -use Samsara\Fermat\Provider\SeriesProvider; |
|
5 | +use Samsara\Fermat\Numbers; |
|
6 | +use Samsara\Fermat\Provider\BCProvider; |
|
7 | +use Riimu\Kit\BaseConversion\BaseConverter; |
|
8 | +use Samsara\Fermat\Provider\SequenceProvider; |
|
9 | +use Samsara\Fermat\Provider\SeriesProvider; |
|
10 | 10 | use Samsara\Fermat\Values\Base\NumberInterface; |
11 | 11 | |
12 | 12 | abstract class Number |
@@ -20,6 +20,9 @@ discard block |
||
20 | 20 | |
21 | 21 | protected $base; |
22 | 22 | |
23 | + /** |
|
24 | + * @param integer $precision |
|
25 | + */ |
|
23 | 26 | public function __construct($value, $precision = null, $base = 10) |
24 | 27 | { |
25 | 28 | $this->base = $base; |
@@ -96,7 +99,7 @@ discard block |
||
96 | 99 | * Note about precision: it uses the smaller of the two precisions (significant figures). |
97 | 100 | * |
98 | 101 | * @param $num |
99 | - * @return mixed |
|
102 | + * @return NumberInterface |
|
100 | 103 | */ |
101 | 104 | public function divide($num) |
102 | 105 | { |
@@ -486,6 +489,9 @@ discard block |
||
486 | 489 | return $comparison; |
487 | 490 | } |
488 | 491 | |
492 | + /** |
|
493 | + * @param integer $value |
|
494 | + */ |
|
489 | 495 | public function equals($value) |
490 | 496 | { |
491 | 497 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |
@@ -497,6 +503,9 @@ discard block |
||
497 | 503 | } |
498 | 504 | } |
499 | 505 | |
506 | + /** |
|
507 | + * @param integer $value |
|
508 | + */ |
|
500 | 509 | public function greaterThan($value) |
501 | 510 | { |
502 | 511 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |
@@ -529,6 +538,9 @@ discard block |
||
529 | 538 | } |
530 | 539 | } |
531 | 540 | |
541 | + /** |
|
542 | + * @param integer $value |
|
543 | + */ |
|
532 | 544 | public function lessThanOrEqualTo($value) |
533 | 545 | { |
534 | 546 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |