PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.11
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.11
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Shared / Trend / PowerBestFit.php

PowerBestFit.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.7.11, at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/Trend/PowerBestFit.php

115 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Shared\Trend;
4
5 class PowerBestFit extends BestFit
6 {
7 /**
8 * Algorithm type to use for best-fit
9 * (Name of this Trend class).
10 *
11 * @var string
12 */
13 protected $bestFitType = 'power';
14
15 /**
16 * Return the Y-Value for a specified value of X.
17 *
18 * @param float $xValue X-Value
19 *
20 * @return float Y-Value
21 */
22 public function getValueOfYForX($xValue)
23 {
24 return $this->getIntersect() * pow(($xValue - $this->xOffset), $this->getSlope());
25 }
26
27 /**
28 * Return the X-Value for a specified value of Y.
29 *
30 * @param float $yValue Y-Value
31 *
32 * @return float X-Value
33 */
34 public function getValueOfXForY($yValue)
35 {
36 return pow((($yValue + $this->yOffset) / $this->getIntersect()), (1 / $this->getSlope()));
37 }
38
39 /**
40 * Return the Equation of the best-fit line.
41 *
42 * @param int $dp Number of places of decimal precision to display
43 *
44 * @return string
45 */
46 public function getEquation($dp = 0)
47 {
48 $slope = $this->getSlope($dp);
49 $intersect = $this->getIntersect($dp);
50
51 return 'Y = ' . $intersect . ' * X^' . $slope;
52 }
53
54 /**
55 * Return the Value of X where it intersects Y = 0.
56 *
57 * @param int $dp Number of places of decimal precision to display
58 *
59 * @return float
60 */
61 public function getIntersect($dp = 0)
62 {
63 if ($dp != 0) {
64 return round(exp($this->intersect), $dp);
65 }
66
67 return exp($this->intersect);
68 }
69
70 /**
71 * Execute the regression and calculate the goodness of fit for a set of X and Y data values.
72 *
73 * @param float[] $yValues The set of Y-values for this regression
74 * @param float[] $xValues The set of X-values for this regression
75 * @param bool $const
76 */
77 private function powerRegression($yValues, $xValues, $const)
78 {
79 foreach ($xValues as &$value) {
80 if ($value < 0.0) {
81 $value = 0 - log(abs($value));
82 } elseif ($value > 0.0) {
83 $value = log($value);
84 }
85 }
86 unset($value);
87 foreach ($yValues as &$value) {
88 if ($value < 0.0) {
89 $value = 0 - log(abs($value));
90 } elseif ($value > 0.0) {
91 $value = log($value);
92 }
93 }
94 unset($value);
95
96 $this->leastSquareFit($yValues, $xValues, $const);
97 }
98
99 /**
100 * Define the regression and calculate the goodness of fit for a set of X and Y data values.
101 *
102 * @param float[] $yValues The set of Y-values for this regression
103 * @param float[] $xValues The set of X-values for this regression
104 * @param bool $const
105 */
106 public function __construct($yValues, $xValues = [], $const = true)
107 {
108 parent::__construct($yValues, $xValues);
109
110 if (!$this->error) {
111 $this->powerRegression($yValues, $xValues, $const);
112 }
113 }
114 }
115