@@ -69,6 +69,9 @@ discard block |
||
69 | 69 | ); |
70 | 70 | } |
71 | 71 | |
72 | + /** |
|
73 | + * @param NumberInterface $standardDev |
|
74 | + */ |
|
72 | 75 | public function SDToValue($standardDev) |
73 | 76 | { |
74 | 77 | $standardDev = Numbers::makeOrDont($this->numberType, $standardDev); |
@@ -85,6 +88,9 @@ discard block |
||
85 | 88 | return $this->PDFByValue($value); |
86 | 89 | } |
87 | 90 | |
91 | + /** |
|
92 | + * @param NumberInterface $value |
|
93 | + */ |
|
88 | 94 | public function PDFByValue($value) |
89 | 95 | { |
90 | 96 | $value = Numbers::makeOrDont($this->numberType, $value); |
@@ -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 | /** |
@@ -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 |
@@ -19,6 +19,10 @@ |
||
19 | 19 | */ |
20 | 20 | private $sd; |
21 | 21 | |
22 | + /** |
|
23 | + * @param NumberInterface $mean |
|
24 | + * @param NumberInterface $sd |
|
25 | + */ |
|
22 | 26 | public function __construct($mean, $sd) |
23 | 27 | { |
24 | 28 | $mean = Numbers::makeOrDont(Numbers::IMMUTABLE, $mean); |
@@ -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 |
@@ -56,6 +56,9 @@ discard block |
||
56 | 56 | return $one->subtract($p); |
57 | 57 | } |
58 | 58 | |
59 | + /** |
|
60 | + * @param NumberInterface $x |
|
61 | + */ |
|
59 | 62 | public static function gaussErrorFunction($x) |
60 | 63 | { |
61 | 64 | |
@@ -68,14 +71,26 @@ discard block |
||
68 | 71 | $answer = $answer->multiply( |
69 | 72 | SeriesProvider::maclaurinSeries( |
70 | 73 | $x, |
74 | + |
|
75 | + /** |
|
76 | + * @param NumberInterface $n |
|
77 | + */ |
|
71 | 78 | function ($n) { |
72 | 79 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1); |
73 | 80 | |
74 | 81 | return $negOne->pow($n); |
75 | 82 | }, |
83 | + |
|
84 | + /** |
|
85 | + * @param NumberInterface $n |
|
86 | + */ |
|
76 | 87 | function ($n) { |
77 | 88 | return SequenceProvider::nthOddNumber($n); |
78 | 89 | }, |
90 | + |
|
91 | + /** |
|
92 | + * @param NumberInterface $n |
|
93 | + */ |
|
79 | 94 | function ($n) { |
80 | 95 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
81 | 96 | |
@@ -88,6 +103,9 @@ discard block |
||
88 | 103 | |
89 | 104 | } |
90 | 105 | |
106 | + /** |
|
107 | + * @param NumberInterface $p |
|
108 | + */ |
|
91 | 109 | public static function inverseNormalCDF($p, $precision = 10) |
92 | 110 | { |
93 | 111 | $pi = Numbers::makePi(); |
@@ -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)); |
@@ -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 |
@@ -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))); |
@@ -52,8 +52,8 @@ |
||
52 | 52 | /** |
53 | 53 | * WARNING: This function is VERY unoptimized. Be careful of large m values. |
54 | 54 | * |
55 | - * @param $m |
|
56 | - * @param $n |
|
55 | + * @param string $m |
|
56 | + * @param integer $n |
|
57 | 57 | * |
58 | 58 | * @return NumberInterface |
59 | 59 | */ |
@@ -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, |
@@ -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; |
@@ -47,6 +50,9 @@ discard block |
||
47 | 50 | return $this->precision; |
48 | 51 | } |
49 | 52 | |
53 | + /** |
|
54 | + * @param NumberInterface $num |
|
55 | + */ |
|
50 | 56 | public function add($num) |
51 | 57 | { |
52 | 58 | $num = Numbers::makeOrDont($this, $num, $this->getPrecision()); |
@@ -77,6 +83,9 @@ discard block |
||
77 | 83 | return $this->setValue($value); |
78 | 84 | } |
79 | 85 | |
86 | + /** |
|
87 | + * @param string $num |
|
88 | + */ |
|
80 | 89 | public function multiply($num) |
81 | 90 | { |
82 | 91 | $num = Numbers::makeOrDont($this, $num, $this->getPrecision()); |
@@ -95,8 +104,8 @@ discard block |
||
95 | 104 | /** |
96 | 105 | * Note about precision: it uses the smaller of the two precisions (significant figures). |
97 | 106 | * |
98 | - * @param $num |
|
99 | - * @return mixed |
|
107 | + * @param NumberInterface $num |
|
108 | + * @return NumberInterface |
|
100 | 109 | */ |
101 | 110 | public function divide($num) |
102 | 111 | { |
@@ -486,6 +495,9 @@ discard block |
||
486 | 495 | return $comparison; |
487 | 496 | } |
488 | 497 | |
498 | + /** |
|
499 | + * @param integer $value |
|
500 | + */ |
|
489 | 501 | public function equals($value) |
490 | 502 | { |
491 | 503 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |
@@ -497,6 +509,9 @@ discard block |
||
497 | 509 | } |
498 | 510 | } |
499 | 511 | |
512 | + /** |
|
513 | + * @param integer $value |
|
514 | + */ |
|
500 | 515 | public function greaterThan($value) |
501 | 516 | { |
502 | 517 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |
@@ -529,6 +544,9 @@ discard block |
||
529 | 544 | } |
530 | 545 | } |
531 | 546 | |
547 | + /** |
|
548 | + * @param integer $value |
|
549 | + */ |
|
532 | 550 | public function lessThanOrEqualTo($value) |
533 | 551 | { |
534 | 552 | $value = Numbers::makeOrDont(Numbers::IMMUTABLE, $value, $this->getPrecision()); |
@@ -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 |