@@ -1,21 +1,21 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | spl_autoload_register( |
4 | - function($className) { |
|
5 | - $className = ltrim($className, '\\'); |
|
6 | - $fileName = ''; |
|
7 | - if ($lastNsPos = strripos($className, '\\')) { |
|
8 | - $namespace = substr($className, 0, $lastNsPos); |
|
9 | - $className = substr($className, $lastNsPos + 1); |
|
10 | - $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; |
|
11 | - } |
|
12 | - $fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php'; |
|
13 | - if (file_exists($fileName)) { |
|
14 | - include $fileName; |
|
15 | - return true; |
|
16 | - } |
|
17 | - return false; |
|
18 | - } |
|
4 | + function($className) { |
|
5 | + $className = ltrim($className, '\\'); |
|
6 | + $fileName = ''; |
|
7 | + if ($lastNsPos = strripos($className, '\\')) { |
|
8 | + $namespace = substr($className, 0, $lastNsPos); |
|
9 | + $className = substr($className, $lastNsPos + 1); |
|
10 | + $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; |
|
11 | + } |
|
12 | + $fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php'; |
|
13 | + if (file_exists($fileName)) { |
|
14 | + include $fileName; |
|
15 | + return true; |
|
16 | + } |
|
17 | + return false; |
|
18 | + } |
|
19 | 19 | ); |
20 | 20 | |
21 | 21 | ?> |
22 | 22 | \ No newline at end of file |
@@ -16,50 +16,50 @@ |
||
16 | 16 | /** |
17 | 17 | * ExponentialRegression constructor. |
18 | 18 | */ |
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->sumIndex = [0, 0, 0, 0, 0, 0]; |
|
22 | - $this->dimension = count($this->sumIndex); |
|
23 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->sumIndex = [0, 0, 0, 0, 0, 0]; |
|
22 | + $this->dimension = count($this->sumIndex); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @throws RegressionException |
|
27 | - */ |
|
28 | - public function calculate() |
|
29 | - { |
|
30 | - if ($this->sourceSequence === null) { |
|
31 | - throw new RegressionException('The input sequence is not set'); |
|
32 | - } |
|
25 | + /** |
|
26 | + * @throws RegressionException |
|
27 | + */ |
|
28 | + public function calculate() |
|
29 | + { |
|
30 | + if ($this->sourceSequence === null) { |
|
31 | + throw new RegressionException('The input sequence is not set'); |
|
32 | + } |
|
33 | 33 | |
34 | - if (count($this->sourceSequence) < $this->dimension) { |
|
35 | - throw new RegressionException('The dimension of the sequence of at least ' . $this->dimension); |
|
36 | - } |
|
34 | + if (count($this->sourceSequence) < $this->dimension) { |
|
35 | + throw new RegressionException('The dimension of the sequence of at least ' . $this->dimension); |
|
36 | + } |
|
37 | 37 | |
38 | - $k = 0; |
|
38 | + $k = 0; |
|
39 | 39 | |
40 | - foreach ($this->sourceSequence as $k => $v) { |
|
41 | - if ($v[1] !== null) { |
|
42 | - $this->sumIndex[0] += $v[0]; |
|
43 | - $this->sumIndex[1] += $v[1]; |
|
44 | - $this->sumIndex[2] += $v[0] * $v[0] * $v[1]; |
|
45 | - $this->sumIndex[3] += $v[1] * log($v[1]); |
|
46 | - $this->sumIndex[4] += $v[0] * $v[1] * log($v[1]); |
|
47 | - $this->sumIndex[5] += $v[0] * $v[1]; |
|
48 | - } |
|
49 | - } |
|
40 | + foreach ($this->sourceSequence as $k => $v) { |
|
41 | + if ($v[1] !== null) { |
|
42 | + $this->sumIndex[0] += $v[0]; |
|
43 | + $this->sumIndex[1] += $v[1]; |
|
44 | + $this->sumIndex[2] += $v[0] * $v[0] * $v[1]; |
|
45 | + $this->sumIndex[3] += $v[1] * log($v[1]); |
|
46 | + $this->sumIndex[4] += $v[0] * $v[1] * log($v[1]); |
|
47 | + $this->sumIndex[5] += $v[0] * $v[1]; |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - $denominator = $this->sumIndex[1] * $this->sumIndex[2] - $this->sumIndex[5] * $this->sumIndex[5]; |
|
51 | + $denominator = $this->sumIndex[1] * $this->sumIndex[2] - $this->sumIndex[5] * $this->sumIndex[5]; |
|
52 | 52 | |
53 | - $A = exp(($this->sumIndex[2] * $this->sumIndex[3] - $this->sumIndex[5] * $this->sumIndex[4]) / $denominator); |
|
54 | - $B = ($this->sumIndex[1] * $this->sumIndex[4] - $this->sumIndex[5] * $this->sumIndex[3]) / $denominator; |
|
53 | + $A = exp(($this->sumIndex[2] * $this->sumIndex[3] - $this->sumIndex[5] * $this->sumIndex[4]) / $denominator); |
|
54 | + $B = ($this->sumIndex[1] * $this->sumIndex[4] - $this->sumIndex[5] * $this->sumIndex[3]) / $denominator; |
|
55 | 55 | |
56 | - foreach ($this->sourceSequence as $i => $val) { |
|
57 | - $coordinate = [$val[0], $A * exp($B * $val[0])]; |
|
58 | - $this->resultSequence[] = $coordinate; |
|
59 | - } |
|
56 | + foreach ($this->sourceSequence as $i => $val) { |
|
57 | + $coordinate = [$val[0], $A * exp($B * $val[0])]; |
|
58 | + $this->resultSequence[] = $coordinate; |
|
59 | + } |
|
60 | 60 | |
61 | - $this->equation = 'y = ' . round($A, 2) . '+ e^(' . round($B, 2) . 'x)'; |
|
61 | + $this->equation = 'y = ' . round($A, 2) . '+ e^(' . round($B, 2) . 'x)'; |
|
62 | 62 | |
63 | - $this->push(); |
|
64 | - } |
|
63 | + $this->push(); |
|
64 | + } |
|
65 | 65 | } |
@@ -54,7 +54,7 @@ |
||
54 | 54 | $this->resultSequence[] = $coordinate; |
55 | 55 | } |
56 | 56 | |
57 | - $this->equation = 'y = ' . round($A, 2) . '+ x^' . round($B, 2); |
|
57 | + $this->equation = 'y = ' . round($A, 2) . '+ x^' . round($B, 2); |
|
58 | 58 | |
59 | 59 | $this->push(); |
60 | 60 | } |