ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PowerBestFit.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class PowerBestFit extends BestFit
6 {
13  protected $bestFitType = 'power';
14 
22  public function getValueOfYForX($xValue)
23  {
24  return $this->getIntersect() * ($xValue - $this->xOffset) ** $this->getSlope();
25  }
26 
34  public function getValueOfXForY($yValue)
35  {
36  return (($yValue + $this->yOffset) / $this->getIntersect()) ** (1 / $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 . ' * X^' . $slope;
52  }
53 
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 
76  private function powerRegression(array $yValues, array $xValues, bool $const): void
77  {
78  $adjustedYValues = array_map(
79  function ($value) {
80  return ($value < 0.0) ? 0 - log(abs($value)) : log($value);
81  },
82  $yValues
83  );
84  $adjustedXValues = array_map(
85  function ($value) {
86  return ($value < 0.0) ? 0 - log(abs($value)) : log($value);
87  },
88  $xValues
89  );
90 
91  $this->leastSquareFit($adjustedYValues, $adjustedXValues, $const);
92  }
93 
101  public function __construct($yValues, $xValues = [], $const = true)
102  {
103  parent::__construct($yValues, $xValues);
104 
105  if (!$this->error) {
106  $this->powerRegression($yValues, $xValues, (bool) $const);
107  }
108  }
109 }
getValueOfXForY($yValue)
Return the X-Value for a specified value of Y.
getEquation($dp=0)
Return the Equation of the best-fit line.
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
getSlope($dp=0)
Return the Slope of the line.
Definition: BestFit.php:138
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...
powerRegression(array $yValues, array $xValues, bool $const)
Execute the regression and calculate the goodness of fit for a set of X and Y data values...
leastSquareFit(array $yValues, array $xValues, bool $const)
Definition: BestFit.php:405