ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
LogarithmicBestFit.php
Go to the documentation of this file.
1<?php
2
4
6{
13 protected $bestFitType = 'logarithmic';
14
22 public function getValueOfYForX($xValue)
23 {
24 return $this->getIntersect() + $this->getSlope() * log($xValue - $this->xOffset);
25 }
26
34 public function getValueOfXForY($yValue)
35 {
36 return exp(($yValue - $this->getIntersect()) / $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 = ' . $slope . ' * log(' . $intersect . ' * X)';
52 }
53
60 private function logarithmicRegression(array $yValues, array $xValues, bool $const): void
61 {
62 $adjustedYValues = array_map(
63 function ($value) {
64 return ($value < 0.0) ? 0 - log(abs($value)) : log($value);
65 },
67 );
68
69 $this->leastSquareFit($adjustedYValues, $xValues, $const);
70 }
71
79 public function __construct($yValues, $xValues = [], $const = true)
80 {
81 parent::__construct($yValues, $xValues);
82
83 if (!$this->error) {
84 $this->logarithmicRegression($yValues, $xValues, (bool) $const);
85 }
86 }
87}
An exception for terminatinating execution or to throw for unit testing.
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
Definition: BestFit.php:170
leastSquareFit(array $yValues, array $xValues, bool $const)
Definition: BestFit.php:405
getSlope($dp=0)
Return the Slope of the line.
Definition: BestFit.php:138
__construct($yValues, $xValues=[], $const=true)
Define the regression and calculate the goodness of fit for a set of X and Y data values.
getValueOfYForX($xValue)
Return the Y-Value for a specified value of X.
logarithmicRegression(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.
getValueOfXForY($yValue)
Return the X-Value for a specified value of Y.
error($a_errmsg)
set error message @access public