ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ExponentialBestFit.php
Go to the documentation of this file.
1<?php
2
4
6{
13 protected $bestFitType = 'exponential';
14
22 public function getValueOfYForX($xValue)
23 {
24 return $this->getIntersect() * $this->getSlope() ** ($xValue - $this->xOffset);
25 }
26
34 public function getValueOfXForY($yValue)
35 {
36 return log(($yValue + $this->yOffset) / $this->getIntersect()) / log($this->getSlope());
37 }
38
46 public function getEquation($dp = 0)
47 {
48 $slope = $this->getSlope($dp);
49 $intersect = $this->getIntersect($dp);
50
51 return 'Y = ' . $intersect . ' * ' . $slope . '^X';
52 }
53
61 public function getSlope($dp = 0)
62 {
63 if ($dp != 0) {
64 return round(exp($this->slope), $dp);
65 }
66
67 return exp($this->slope);
68 }
69
77 public function getIntersect($dp = 0)
78 {
79 if ($dp != 0) {
80 return round(exp($this->intersect), $dp);
81 }
82
83 return exp($this->intersect);
84 }
85
92 private function exponentialRegression(array $yValues, array $xValues, bool $const): void
93 {
94 $adjustedYValues = array_map(
95 function ($value) {
96 return ($value < 0.0) ? 0 - log(abs($value)) : log($value);
97 },
99 );
100
101 $this->leastSquareFit($adjustedYValues, $xValues, $const);
102 }
103
111 public function __construct($yValues, $xValues = [], $const = true)
112 {
113 parent::__construct($yValues, $xValues);
114
115 if (!$this->error) {
116 $this->exponentialRegression($yValues, $xValues, (bool) $const);
117 }
118 }
119}
An exception for terminatinating execution or to throw for unit testing.
leastSquareFit(array $yValues, array $xValues, bool $const)
Definition: BestFit.php:405
exponentialRegression(array $yValues, array $xValues, bool $const)
Execute the regression and calculate the goodness of fit for a set of X and Y data values.
getEquation($dp=0)
Return the Equation of the best-fit line.
getValueOfYForX($xValue)
Return the Y-Value for a specified value of X.
__construct($yValues, $xValues=[], $const=true)
Define the regression and calculate the goodness of fit for a set of X and Y data values.
getValueOfXForY($yValue)
Return the X-Value for a specified value of Y.
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
error($a_errmsg)
set error message @access public