ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPExcel_Polynomial_Best_Fit Class Reference
+ Inheritance diagram for PHPExcel_Polynomial_Best_Fit:
+ Collaboration diagram for PHPExcel_Polynomial_Best_Fit:

Public Member Functions

 getOrder ()
 Return the order of this polynomial. More...
 
 getValueOfYForX ($xValue)
 Return the Y-Value for a specified value of X. More...
 
 getValueOfXForY ($yValue)
 Return the X-Value for a specified value of Y. More...
 
 getEquation ($dp=0)
 Return the Equation of the best-fit line. More...
 
 getSlope ($dp=0)
 Return the Slope of the line. More...
 
 getCoefficients ($dp=0)
 
 __construct ($order, $yValues, $xValues=array(), $const=True)
 Define the regression and calculate the goodness of fit for a set of X and Y data values. More...
 
- Public Member Functions inherited from PHPExcel_Best_Fit
 getError ()
 
 getBestFitType ()
 
 getValueOfYForX ($xValue)
 Return the Y-Value for a specified value of X. More...
 
 getValueOfXForY ($yValue)
 Return the X-Value for a specified value of Y. More...
 
 getXValues ()
 Return the original set of X-Values. More...
 
 getEquation ($dp=0)
 Return the Equation of the best-fit line. More...
 
 getSlope ($dp=0)
 Return the Slope of the line. More...
 
 getSlopeSE ($dp=0)
 Return the standard error of the Slope. More...
 
 getIntersect ($dp=0)
 Return the Value of X where it intersects Y = 0. More...
 
 getIntersectSE ($dp=0)
 Return the standard error of the Intersect. More...
 
 getGoodnessOfFit ($dp=0)
 Return the goodness of fit for this regression. More...
 
 getGoodnessOfFitPercent ($dp=0)
 
 getStdevOfResiduals ($dp=0)
 Return the standard deviation of the residuals for this regression. More...
 
 getSSRegression ($dp=0)
 
 getSSResiduals ($dp=0)
 
 getDFResiduals ($dp=0)
 
 getF ($dp=0)
 
 getCovariance ($dp=0)
 
 getCorrelation ($dp=0)
 
 getYBestFitValues ()
 
 __construct ($yValues, $xValues=array(), $const=True)
 Define the regression. More...
 

Protected Attributes

 $_bestFitType = 'polynomial'
 
 $_order = 0
 
- Protected Attributes inherited from PHPExcel_Best_Fit
 $_error = False
 
 $_bestFitType = 'undetermined'
 
 $_valueCount = 0
 
 $_xValues = array()
 
 $_yValues = array()
 
 $_adjustToZero = False
 
 $_yBestFitValues = array()
 
 $_goodnessOfFit = 1
 
 $_stdevOfResiduals = 0
 
 $_covariance = 0
 
 $_correlation = 0
 
 $_SSRegression = 0
 
 $_SSResiduals = 0
 
 $_DFResiduals = 0
 
 $_F = 0
 
 $_slope = 0
 
 $_slopeSE = 0
 
 $_intersect = 0
 
 $_intersectSE = 0
 
 $_Xoffset = 0
 
 $_Yoffset = 0
 

Private Member Functions

 _polynomial_regression ($order, $yValues, $xValues, $const)
 Execute the regression and calculate the goodness of fit for a set of X and Y data values. More...
 

Additional Inherited Members

- Protected Member Functions inherited from PHPExcel_Best_Fit
 _calculateGoodnessOfFit ($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
 
 _leastSquareFit ($yValues, $xValues, $const)
 

Detailed Description

Definition at line 40 of file polynomialBestFitClass.php.

Constructor & Destructor Documentation

◆ __construct()

PHPExcel_Polynomial_Best_Fit::__construct (   $order,
  $yValues,
  $xValues = array(),
  $const = True 
)

Define the regression and calculate the goodness of fit for a set of X and Y data values.

Parameters
int$orderOrder of Polynomial for this regression
float[]$yValues The set of Y-values for this regression
float[]$xValues The set of X-values for this regression
boolean$const

Definition at line 209 of file polynomialBestFitClass.php.

References _polynomial_regression(), and PHPExcel_Best_Fit\getGoodnessOfFit().

209  {
210  if (parent::__construct($yValues, $xValues) !== False) {
211  if ($order < $this->_valueCount) {
212  $this->_bestFitType .= '_'.$order;
213  $this->_order = $order;
214  $this->_polynomial_regression($order, $yValues, $xValues, $const);
215  if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) {
216  $this->_error = True;
217  }
218  } else {
219  $this->_error = True;
220  }
221  }
222  } // function __construct()
getGoodnessOfFit($dp=0)
Return the goodness of fit for this regression.
_polynomial_regression($order, $yValues, $xValues, $const)
Execute the regression and calculate the goodness of fit for a set of X and Y data values...
+ Here is the call graph for this function:

Member Function Documentation

◆ _polynomial_regression()

PHPExcel_Polynomial_Best_Fit::_polynomial_regression (   $order,
  $yValues,
  $xValues,
  $const 
)
private

Execute the regression and calculate the goodness of fit for a set of X and Y data values.

Parameters
int$orderOrder of Polynomial for this regression
float[]$yValues The set of Y-values for this regression
float[]$xValues The set of X-values for this regression
boolean$const

Definition at line 152 of file polynomialBestFitClass.php.

References PHPExcel_Best_Fit\$_valueCount, $i, $r, PHPExcel_Best_Fit\_calculateGoodnessOfFit(), array, and getValueOfYForX().

Referenced by __construct().

152  {
153  // calculate sums
154  $x_sum = array_sum($xValues);
155  $y_sum = array_sum($yValues);
156  $xx_sum = $xy_sum = 0;
157  for($i = 0; $i < $this->_valueCount; ++$i) {
158  $xy_sum += $xValues[$i] * $yValues[$i];
159  $xx_sum += $xValues[$i] * $xValues[$i];
160  $yy_sum += $yValues[$i] * $yValues[$i];
161  }
162  /*
163  * This routine uses logic from the PHP port of polyfit version 0.1
164  * written by Michael Bommarito and Paul Meagher
165  *
166  * The function fits a polynomial function of order $order through
167  * a series of x-y data points using least squares.
168  *
169  */
170  for ($i = 0; $i < $this->_valueCount; ++$i) {
171  for ($j = 0; $j <= $order; ++$j) {
172  $A[$i][$j] = pow($xValues[$i], $j);
173  }
174  }
175  for ($i=0; $i < $this->_valueCount; ++$i) {
176  $B[$i] = array($yValues[$i]);
177  }
178  $matrixA = new Matrix($A);
179  $matrixB = new Matrix($B);
180  $C = $matrixA->solve($matrixB);
181 
182  $coefficients = array();
183  for($i = 0; $i < $C->m; ++$i) {
184  $r = $C->get($i, 0);
185  if (abs($r) <= pow(10, -9)) {
186  $r = 0;
187  }
188  $coefficients[] = $r;
189  }
190 
191  $this->_intersect = array_shift($coefficients);
192  $this->_slope = $coefficients;
193 
194  $this->_calculateGoodnessOfFit($x_sum,$y_sum,$xx_sum,$yy_sum,$xy_sum);
195  foreach($this->_xValues as $xKey => $xValue) {
196  $this->_yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
197  }
198  } // function _polynomial_regression()
getValueOfYForX($xValue)
Return the Y-Value for a specified value of X.
$r
Definition: example_031.php:79
_calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCoefficients()

PHPExcel_Polynomial_Best_Fit::getCoefficients (   $dp = 0)

Definition at line 139 of file polynomialBestFitClass.php.

References array, PHPExcel_Best_Fit\getIntersect(), and getSlope().

139  {
140  return array_merge(array($this->getIntersect($dp)),$this->getSlope($dp));
141  } // function getCoefficients()
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
Create styles array
The data for the language used.
getSlope($dp=0)
Return the Slope of the line.
+ Here is the call graph for this function:

◆ getEquation()

PHPExcel_Polynomial_Best_Fit::getEquation (   $dp = 0)

Return the Equation of the best-fit line.

Parameters
int$dpNumber of places of decimal precision to display
Returns
string

Definition at line 104 of file polynomialBestFitClass.php.

References $key, PHPExcel_Best_Fit\getIntersect(), and getSlope().

104  {
105  $slope = $this->getSlope($dp);
106  $intersect = $this->getIntersect($dp);
107 
108  $equation = 'Y = '.$intersect;
109  foreach($slope as $key => $value) {
110  if ($value != 0.0) {
111  $equation .= ' + '.$value.' * X';
112  if ($key > 0) {
113  $equation .= '^'.($key + 1);
114  }
115  }
116  }
117  return $equation;
118  } // function getEquation()
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
getSlope($dp=0)
Return the Slope of the line.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getOrder()

PHPExcel_Polynomial_Best_Fit::getOrder ( )

Return the order of this polynomial.

Returns
int

Definition at line 64 of file polynomialBestFitClass.php.

References $_order.

64  {
65  return $this->_order;
66  } // function getOrder()

◆ getSlope()

PHPExcel_Polynomial_Best_Fit::getSlope (   $dp = 0)

Return the Slope of the line.

Parameters
int$dpNumber of places of decimal precision to display
Returns
string

Definition at line 127 of file polynomialBestFitClass.php.

References PHPExcel_Best_Fit\$_slope, and array.

Referenced by getCoefficients(), getEquation(), getValueOfXForY(), and getValueOfYForX().

127  {
128  if ($dp != 0) {
129  $coefficients = array();
130  foreach($this->_slope as $coefficient) {
131  $coefficients[] = round($coefficient,$dp);
132  }
133  return $coefficients;
134  }
135  return $this->_slope;
136  } // function getSlope()
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getValueOfXForY()

PHPExcel_Polynomial_Best_Fit::getValueOfXForY (   $yValue)

Return the X-Value for a specified value of Y.

Parameters
float$yValueY-Value
Returns
float X-Value

Definition at line 93 of file polynomialBestFitClass.php.

References PHPExcel_Best_Fit\getIntersect(), and getSlope().

93  {
94  return ($yValue - $this->getIntersect()) / $this->getSlope();
95  } // function getValueOfXForY()
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
getSlope($dp=0)
Return the Slope of the line.
+ Here is the call graph for this function:

◆ getValueOfYForX()

PHPExcel_Polynomial_Best_Fit::getValueOfYForX (   $xValue)

Return the Y-Value for a specified value of X.

Parameters
float$xValueX-Value
Returns
float Y-Value

Definition at line 75 of file polynomialBestFitClass.php.

References $key, PHPExcel_Best_Fit\getIntersect(), and getSlope().

Referenced by _polynomial_regression().

75  {
76  $retVal = $this->getIntersect();
77  $slope = $this->getSlope();
78  foreach($slope as $key => $value) {
79  if ($value != 0.0) {
80  $retVal += $value * pow($xValue, $key + 1);
81  }
82  }
83  return $retVal;
84  } // function getValueOfYForX()
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
getSlope($dp=0)
Return the Slope of the line.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $_bestFitType

PHPExcel_Polynomial_Best_Fit::$_bestFitType = 'polynomial'
protected

Definition at line 48 of file polynomialBestFitClass.php.

◆ $_order

PHPExcel_Polynomial_Best_Fit::$_order = 0
protected

Definition at line 56 of file polynomialBestFitClass.php.

Referenced by getOrder().


The documentation for this class was generated from the following file: