Completed
Branch master (58de7f)
by Nikita
06:44 queued 03:52
created
src/Regression/InterfaceRegression.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,18 +10,18 @@
 block discarded – undo
10 10
 interface InterfaceRegression
11 11
 {
12 12
 	
13
-	public function calculate();
13
+    public function calculate();
14 14
 
15
-	/**
16
-	 * @param array $data
17
-	 *
18
-	 * @return array
19
-	 */
20
-	public function setSourceSequence(array $data);
15
+    /**
16
+     * @param array $data
17
+     *
18
+     * @return array
19
+     */
20
+    public function setSourceSequence(array $data);
21 21
 
22
-	/**
23
-	 * @return RegressionModel
24
-	 */
25
-	public function getRegressionModel(): RegressionModel;
22
+    /**
23
+     * @return RegressionModel
24
+     */
25
+    public function getRegressionModel(): RegressionModel;
26 26
 
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.
src/Regression/RegressionFactory.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,64 +12,64 @@
 block discarded – undo
12 12
  */
13 13
 class RegressionFactory
14 14
 {
15
-	/**
16
-	 * @param array $data
17
-	 * @return RegressionModel
18
-	 * @throws TypeError
19
-	 */
20
-	public static function Linear(array $data): RegressionModel
21
-	{
22
-		return self::createContainer(LinearRegression::class, $data);
23
-	}
15
+    /**
16
+     * @param array $data
17
+     * @return RegressionModel
18
+     * @throws TypeError
19
+     */
20
+    public static function Linear(array $data): RegressionModel
21
+    {
22
+        return self::createContainer(LinearRegression::class, $data);
23
+    }
24 24
 
25
-	/**
26
-	 * @param array $data
27
-	 * @return RegressionModel
28
-	 * @throws TypeError
29
-	 */
30
-	public static function Exponential(array $data): RegressionModel
31
-	{
32
-		return self::createContainer(ExponentialRegression::class, $data);
33
-	}
25
+    /**
26
+     * @param array $data
27
+     * @return RegressionModel
28
+     * @throws TypeError
29
+     */
30
+    public static function Exponential(array $data): RegressionModel
31
+    {
32
+        return self::createContainer(ExponentialRegression::class, $data);
33
+    }
34 34
 
35
-	/**
36
-	 * @param array $data
37
-	 * @return RegressionModel
38
-	 * @throws TypeError
39
-	 */
40
-	public static function Logarithmic(array $data): RegressionModel
41
-	{
42
-		return self::createContainer(LogarithmicRegression::class, $data);
43
-	}
35
+    /**
36
+     * @param array $data
37
+     * @return RegressionModel
38
+     * @throws TypeError
39
+     */
40
+    public static function Logarithmic(array $data): RegressionModel
41
+    {
42
+        return self::createContainer(LogarithmicRegression::class, $data);
43
+    }
44 44
 
45
-	/**
46
-	 * @param array $data
47
-	 * @return RegressionModel
48
-	 * @throws TypeError
49
-	 */
50
-	public static function Power(array $data): RegressionModel
51
-	{
52
-		return self::createContainer(PowerRegression::class, $data);
53
-	}
45
+    /**
46
+     * @param array $data
47
+     * @return RegressionModel
48
+     * @throws TypeError
49
+     */
50
+    public static function Power(array $data): RegressionModel
51
+    {
52
+        return self::createContainer(PowerRegression::class, $data);
53
+    }
54 54
 
55
-	/**
56
-	 * @param string $className
57
-	 * @param array $data
58
-	 * @return InterfaceRegression
59
-	 * @throws TypeError
60
-	 */
61
-	protected static function createContainer(string $className, array $data): RegressionModel
62
-	{
63
-		/** @var InterfaceRegression $regressionObj */
64
-		$regressionObj = new $className();
55
+    /**
56
+     * @param string $className
57
+     * @param array $data
58
+     * @return InterfaceRegression
59
+     * @throws TypeError
60
+     */
61
+    protected static function createContainer(string $className, array $data): RegressionModel
62
+    {
63
+        /** @var InterfaceRegression $regressionObj */
64
+        $regressionObj = new $className();
65 65
 
66
-		if (!$regressionObj instanceof InterfaceRegression) {
67
-			throw new TypeError('the object' . $className .
68
-				'  is not compatible with the interface ' . InterfaceRegression::class);
69
-		}
66
+        if (!$regressionObj instanceof InterfaceRegression) {
67
+            throw new TypeError('the object' . $className .
68
+                '  is not compatible with the interface ' . InterfaceRegression::class);
69
+        }
70 70
 
71
-		$regressionObj->setSourceSequence($data);
72
-		$regressionObj->calculate();
73
-		return $regressionObj->getRegressionModel();
74
-	}
71
+        $regressionObj->setSourceSequence($data);
72
+        $regressionObj->calculate();
73
+        return $regressionObj->getRegressionModel();
74
+    }
75 75
 }
76 76
\ No newline at end of file
Please login to merge, or discard this patch.
src/autoload.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Regression/LinearRegression.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@
 block discarded – undo
10 10
  */
11 11
 class LinearRegression extends AbstractRegression implements InterfaceRegression
12 12
 {
13
-	/**
14
-	 * LinearRegression constructor.
15
-	 */
16
-	public function __construct()
17
-	{
18
-		$this->sumIndex = [0, 0, 0, 0, 0, 0];
19
-		$this->dimension = count($this->sumIndex);
20
-	}
21
-
22
-	/**
23
-	 * @throws RegressionException
24
-	 */
25
-	public function calculate()
26
-	{
27
-		if ($this->sourceSequence === null) {
28
-			throw new RegressionException('The input sequence is not set');
29
-		}
30
-
31
-		if (count($this->sourceSequence) < $this->dimension) {
32
-			throw new RegressionException('The dimension of the sequence of at least ' . $this->dimension);
33
-		}
34
-
35
-		$k = 0;
36
-
37
-		foreach ($this->sourceSequence as $k => $v) {
38
-			if ($v[1] !== null) {
39
-				$this->sumIndex[0] += $v[0];
40
-				$this->sumIndex[1] += $v[1];
41
-				$this->sumIndex[2] += $v[0] * $v[0];
42
-				$this->sumIndex[3] += $v[0] * $v[1];
43
-				$this->sumIndex[4] += $v[1] * $v[1];
44
-			}
45
-		}
46
-
47
-		$k += 1;
48
-
49
-		$gradient = ($k * $this->sumIndex[3] - $this->sumIndex[0] * $this->sumIndex[1]) /
50
-			($k * $this->sumIndex[2] - $this->sumIndex[0] * $this->sumIndex[0]);
13
+    /**
14
+     * LinearRegression constructor.
15
+     */
16
+    public function __construct()
17
+    {
18
+        $this->sumIndex = [0, 0, 0, 0, 0, 0];
19
+        $this->dimension = count($this->sumIndex);
20
+    }
21
+
22
+    /**
23
+     * @throws RegressionException
24
+     */
25
+    public function calculate()
26
+    {
27
+        if ($this->sourceSequence === null) {
28
+            throw new RegressionException('The input sequence is not set');
29
+        }
30
+
31
+        if (count($this->sourceSequence) < $this->dimension) {
32
+            throw new RegressionException('The dimension of the sequence of at least ' . $this->dimension);
33
+        }
34
+
35
+        $k = 0;
36
+
37
+        foreach ($this->sourceSequence as $k => $v) {
38
+            if ($v[1] !== null) {
39
+                $this->sumIndex[0] += $v[0];
40
+                $this->sumIndex[1] += $v[1];
41
+                $this->sumIndex[2] += $v[0] * $v[0];
42
+                $this->sumIndex[3] += $v[0] * $v[1];
43
+                $this->sumIndex[4] += $v[1] * $v[1];
44
+            }
45
+        }
46
+
47
+        $k += 1;
48
+
49
+        $gradient = ($k * $this->sumIndex[3] - $this->sumIndex[0] * $this->sumIndex[1]) /
50
+            ($k * $this->sumIndex[2] - $this->sumIndex[0] * $this->sumIndex[0]);
51 51
 		
52
-		$intercept = $this->sumIndex[1] / $k - $gradient * $this->sumIndex[0] / $k;
52
+        $intercept = $this->sumIndex[1] / $k - $gradient * $this->sumIndex[0] / $k;
53 53
 
54
-		foreach ($this->sourceSequence as $i => $val) {
55
-			$coordinate = [$val[0], $val[0] * $gradient + $intercept];
56
-			$this->resultSequence[] = $coordinate;
57
-		}
54
+        foreach ($this->sourceSequence as $i => $val) {
55
+            $coordinate = [$val[0], $val[0] * $gradient + $intercept];
56
+            $this->resultSequence[] = $coordinate;
57
+        }
58 58
 
59
-		$this->equation = 'y = ' .  round($gradient, 1) .  'x + ' . round($intercept, 1);
59
+        $this->equation = 'y = ' .  round($gradient, 1) .  'x + ' . round($intercept, 1);
60 60
 
61
-		$this->push();
62
-	}
61
+        $this->push();
62
+    }
63 63
 }
Please login to merge, or discard this patch.