diff --git a/Classes/PHPExcel/Shared/trend/bestFitClass.php b/Classes/PHPExcel/Shared/trend/bestFitClass.php index 1e547b2f..2de029f9 100644 --- a/Classes/PHPExcel/Shared/trend/bestFitClass.php +++ b/Classes/PHPExcel/Shared/trend/bestFitClass.php @@ -1,6 +1,7 @@ _error; - } // function getBestFitType() + return $this->error; + } public function getBestFitType() { - return $this->_bestFitType; - } // function getBestFitType() + return $this->bestFitType; + } /** * Return the Y-Value for a specified value of X @@ -132,7 +125,7 @@ class PHPExcel_Best_Fit public function getValueOfYForX($xValue) { return false; - } // function getValueOfYForX() + } /** * Return the X-Value for a specified value of Y @@ -143,7 +136,7 @@ class PHPExcel_Best_Fit public function getValueOfXForY($yValue) { return false; - } // function getValueOfXForY() + } /** * Return the original set of X-Values @@ -152,8 +145,8 @@ class PHPExcel_Best_Fit */ public function getXValues() { - return $this->_xValues; - } // function getValueOfXForY() + return $this->xValues; + } /** * Return the Equation of the best-fit line @@ -164,7 +157,7 @@ class PHPExcel_Best_Fit public function getEquation($dp = 0) { return false; - } // function getEquation() + } /** * Return the Slope of the line @@ -175,10 +168,10 @@ class PHPExcel_Best_Fit public function getSlope($dp = 0) { if ($dp != 0) { - return round($this->_slope, $dp); + return round($this->slope, $dp); } - return $this->_slope; - } // function getSlope() + return $this->slope; + } /** * Return the standard error of the Slope @@ -189,10 +182,10 @@ class PHPExcel_Best_Fit public function getSlopeSE($dp = 0) { if ($dp != 0) { - return round($this->_slopeSE, $dp); + return round($this->slopeSE, $dp); } - return $this->_slopeSE; - } // function getSlopeSE() + return $this->slopeSE; + } /** * Return the Value of X where it intersects Y = 0 @@ -203,10 +196,10 @@ class PHPExcel_Best_Fit public function getIntersect($dp = 0) { if ($dp != 0) { - return round($this->_intersect, $dp); + return round($this->intersect, $dp); } - return $this->_intersect; - } // function getIntersect() + return $this->intersect; + } /** * Return the standard error of the Intersect @@ -217,10 +210,10 @@ class PHPExcel_Best_Fit public function getIntersectSE($dp = 0) { if ($dp != 0) { - return round($this->_intersectSE, $dp); + return round($this->intersectSE, $dp); } - return $this->_intersectSE; - } // function getIntersectSE() + return $this->intersectSE; + } /** * Return the goodness of fit for this regression @@ -231,18 +224,18 @@ class PHPExcel_Best_Fit public function getGoodnessOfFit($dp = 0) { if ($dp != 0) { - return round($this->_goodnessOfFit, $dp); + return round($this->goodnessOfFit, $dp); } - return $this->_goodnessOfFit; - } // function getGoodnessOfFit() + return $this->goodnessOfFit; + } public function getGoodnessOfFitPercent($dp = 0) { if ($dp != 0) { - return round($this->_goodnessOfFit * 100, $dp); + return round($this->goodnessOfFit * 100, $dp); } - return $this->_goodnessOfFit * 100; - } // function getGoodnessOfFitPercent() + return $this->goodnessOfFit * 100; + } /** * Return the standard deviation of the residuals for this regression @@ -253,127 +246,127 @@ class PHPExcel_Best_Fit public function getStdevOfResiduals($dp = 0) { if ($dp != 0) { - return round($this->_stdevOfResiduals, $dp); + return round($this->stdevOfResiduals, $dp); } - return $this->_stdevOfResiduals; - } // function getStdevOfResiduals() + return $this->stdevOfResiduals; + } public function getSSRegression($dp = 0) { if ($dp != 0) { - return round($this->_SSRegression, $dp); + return round($this->SSRegression, $dp); } - return $this->_SSRegression; - } // function getSSRegression() + return $this->SSRegression; + } public function getSSResiduals($dp = 0) { if ($dp != 0) { - return round($this->_SSResiduals, $dp); + return round($this->SSResiduals, $dp); } - return $this->_SSResiduals; - } // function getSSResiduals() + return $this->SSResiduals; + } public function getDFResiduals($dp = 0) { if ($dp != 0) { - return round($this->_DFResiduals, $dp); + return round($this->DFResiduals, $dp); } - return $this->_DFResiduals; - } // function getDFResiduals() + return $this->DFResiduals; + } public function getF($dp = 0) { if ($dp != 0) { - return round($this->_F, $dp); + return round($this->f, $dp); } - return $this->_F; - } // function getF() + return $this->f; + } public function getCovariance($dp = 0) { if ($dp != 0) { - return round($this->_covariance, $dp); + return round($this->covariance, $dp); } - return $this->_covariance; - } // function getCovariance() + return $this->covariance; + } public function getCorrelation($dp = 0) { if ($dp != 0) { - return round($this->_correlation, $dp); + return round($this->correlation, $dp); } - return $this->_correlation; - } // function getCorrelation() + return $this->correlation; + } public function getYBestFitValues() { - return $this->_yBestFitValues; - } // function getYBestFitValues() + return $this->yBestFitValues; + } - protected function _calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const) + protected function calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const) { $SSres = $SScov = $SScor = $SStot = $SSsex = 0.0; - foreach ($this->_xValues as $xKey => $xValue) { - $bestFitY = $this->_yBestFitValues[$xKey] = $this->getValueOfYForX($xValue); + foreach ($this->xValues as $xKey => $xValue) { + $bestFitY = $this->yBestFitValues[$xKey] = $this->getValueOfYForX($xValue); - $SSres += ($this->_yValues[$xKey] - $bestFitY) * ($this->_yValues[$xKey] - $bestFitY); + $SSres += ($this->yValues[$xKey] - $bestFitY) * ($this->yValues[$xKey] - $bestFitY); if ($const) { - $SStot += ($this->_yValues[$xKey] - $meanY) * ($this->_yValues[$xKey] - $meanY); + $SStot += ($this->yValues[$xKey] - $meanY) * ($this->yValues[$xKey] - $meanY); } else { - $SStot += $this->_yValues[$xKey] * $this->_yValues[$xKey]; + $SStot += $this->yValues[$xKey] * $this->yValues[$xKey]; } - $SScov += ($this->_xValues[$xKey] - $meanX) * ($this->_yValues[$xKey] - $meanY); + $SScov += ($this->xValues[$xKey] - $meanX) * ($this->yValues[$xKey] - $meanY); if ($const) { - $SSsex += ($this->_xValues[$xKey] - $meanX) * ($this->_xValues[$xKey] - $meanX); + $SSsex += ($this->xValues[$xKey] - $meanX) * ($this->xValues[$xKey] - $meanX); } else { - $SSsex += $this->_xValues[$xKey] * $this->_xValues[$xKey]; + $SSsex += $this->xValues[$xKey] * $this->xValues[$xKey]; } } - $this->_SSResiduals = $SSres; - $this->_DFResiduals = $this->_valueCount - 1 - $const; + $this->SSResiduals = $SSres; + $this->DFResiduals = $this->valueCount - 1 - $const; - if ($this->_DFResiduals == 0.0) { - $this->_stdevOfResiduals = 0.0; + if ($this->DFResiduals == 0.0) { + $this->stdevOfResiduals = 0.0; } else { - $this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals); + $this->stdevOfResiduals = sqrt($SSres / $this->DFResiduals); } if (($SStot == 0.0) || ($SSres == $SStot)) { - $this->_goodnessOfFit = 1; + $this->goodnessOfFit = 1; } else { - $this->_goodnessOfFit = 1 - ($SSres / $SStot); + $this->goodnessOfFit = 1 - ($SSres / $SStot); } - $this->_SSRegression = $this->_goodnessOfFit * $SStot; - $this->_covariance = $SScov / $this->_valueCount; - $this->_correlation = ($this->_valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->_valueCount * $sumX2 - pow($sumX, 2)) * ($this->_valueCount * $sumY2 - pow($sumY, 2))); - $this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex); - $this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2)); - if ($this->_SSResiduals != 0.0) { - if ($this->_DFResiduals == 0.0) { - $this->_F = 0.0; + $this->SSRegression = $this->goodnessOfFit * $SStot; + $this->covariance = $SScov / $this->valueCount; + $this->correlation = ($this->valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->valueCount * $sumX2 - pow($sumX, 2)) * ($this->valueCount * $sumY2 - pow($sumY, 2))); + $this->slopeSE = $this->stdevOfResiduals / sqrt($SSsex); + $this->intersectSE = $this->stdevOfResiduals * sqrt(1 / ($this->valueCount - ($sumX * $sumX) / $sumX2)); + if ($this->SSResiduals != 0.0) { + if ($this->DFResiduals == 0.0) { + $this->f = 0.0; } else { - $this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals); + $this->f = $this->SSRegression / ($this->SSResiduals / $this->DFResiduals); } } else { - if ($this->_DFResiduals == 0.0) { - $this->_F = 0.0; + if ($this->DFResiduals == 0.0) { + $this->f = 0.0; } else { - $this->_F = $this->_SSRegression / $this->_DFResiduals; + $this->f = $this->SSRegression / $this->DFResiduals; } } - } // function _calculateGoodnessOfFit() + } - protected function _leastSquareFit($yValues, $xValues, $const) + protected function leastSquareFit($yValues, $xValues, $const) { // calculate sums $x_sum = array_sum($xValues); $y_sum = array_sum($yValues); - $meanX = $x_sum / $this->_valueCount; - $meanY = $y_sum / $this->_valueCount; + $meanX = $x_sum / $this->valueCount; + $meanY = $y_sum / $this->valueCount; $mBase = $mDivisor = $xx_sum = $xy_sum = $yy_sum = 0.0; - for ($i = 0; $i < $this->_valueCount; ++$i) { + for ($i = 0; $i < $this->valueCount; ++$i) { $xy_sum += $xValues[$i] * $yValues[$i]; $xx_sum += $xValues[$i] * $xValues[$i]; $yy_sum += $yValues[$i] * $yValues[$i]; @@ -388,19 +381,19 @@ class PHPExcel_Best_Fit } // calculate slope -// $this->_slope = (($this->_valueCount * $xy_sum) - ($x_sum * $y_sum)) / (($this->_valueCount * $xx_sum) - ($x_sum * $x_sum)); - $this->_slope = $mBase / $mDivisor; +// $this->slope = (($this->valueCount * $xy_sum) - ($x_sum * $y_sum)) / (($this->valueCount * $xx_sum) - ($x_sum * $x_sum)); + $this->slope = $mBase / $mDivisor; // calculate intersect -// $this->_intersect = ($y_sum - ($this->_slope * $x_sum)) / $this->_valueCount; +// $this->intersect = ($y_sum - ($this->slope * $x_sum)) / $this->valueCount; if ($const) { - $this->_intersect = $meanY - ($this->_slope * $meanX); + $this->intersect = $meanY - ($this->slope * $meanX); } else { - $this->_intersect = 0; + $this->intersect = 0; } - $this->_calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum, $meanX, $meanY, $const); - } // function _leastSquareFit() + $this->calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum, $meanX, $meanY, $const); + } /** * Define the regression @@ -421,12 +414,12 @@ class PHPExcel_Best_Fit $nX = $nY; } elseif ($nY != $nX) { // Ensure both arrays of points are the same size - $this->_error = true; + $this->error = true; return false; } - $this->_valueCount = $nY; - $this->_xValues = $xValues; - $this->_yValues = $yValues; - } // function __construct() + $this->valueCount = $nY; + $this->xValues = $xValues; + $this->yValues = $yValues; + } } diff --git a/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php b/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php index caa1759c..44487352 100644 --- a/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php +++ b/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php @@ -1,6 +1,9 @@ getIntersect() * pow($this->getSlope(), ($xValue - $this->_Xoffset)); - } // function getValueOfYForX() + return $this->getIntersect() * pow($this->getSlope(), ($xValue - $this->xOffset)); + } /** * Return the X-Value for a specified value of Y @@ -65,8 +56,8 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit **/ public function getValueOfXForY($yValue) { - return log(($yValue + $this->_Yoffset) / $this->getIntersect()) / log($this->getSlope()); - } // function getValueOfXForY() + return log(($yValue + $this->yOffset) / $this->getIntersect()) / log($this->getSlope()); + } /** * Return the Equation of the best-fit line @@ -79,8 +70,8 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit $slope = $this->getSlope($dp); $intersect = $this->getIntersect($dp); - return 'Y = '.$intersect.' * '.$slope.'^X'; - } // function getEquation() + return 'Y = ' . $intersect . ' * ' . $slope . '^X'; + } /** * Return the Slope of the line @@ -94,7 +85,7 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit return round(exp($this->_slope), $dp); } return exp($this->_slope); - } // function getSlope() + } /** * Return the Value of X where it intersects Y = 0 @@ -105,10 +96,10 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit public function getIntersect($dp = 0) { if ($dp != 0) { - return round(exp($this->_intersect), $dp); + return round(exp($this->intersect), $dp); } - return exp($this->_intersect); - } // function getIntersect() + return exp($this->intersect); + } /** * Execute the regression and calculate the goodness of fit for a set of X and Y data values @@ -117,7 +108,7 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit * @param float[] $xValues The set of X-values for this regression * @param boolean $const */ - private function _exponential_regression($yValues, $xValues, $const) + private function exponentialRegression($yValues, $xValues, $const) { foreach ($yValues as &$value) { if ($value < 0.0) { @@ -128,8 +119,8 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit } unset($value); - $this->_leastSquareFit($yValues, $xValues, $const); - } // function _exponential_regression() + $this->leastSquareFit($yValues, $xValues, $const); + } /** * Define the regression and calculate the goodness of fit for a set of X and Y data values @@ -141,7 +132,7 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit public function __construct($yValues, $xValues = array(), $const = true) { if (parent::__construct($yValues, $xValues) !== false) { - $this->_exponential_regression($yValues, $xValues, $const); + $this->exponentialRegression($yValues, $xValues, $const); } - } // function __construct() + } } diff --git a/Classes/PHPExcel/Shared/trend/linearBestFitClass.php b/Classes/PHPExcel/Shared/trend/linearBestFitClass.php index c5ed3cf3..76b55b3e 100644 --- a/Classes/PHPExcel/Shared/trend/linearBestFitClass.php +++ b/Classes/PHPExcel/Shared/trend/linearBestFitClass.php @@ -1,6 +1,9 @@ getIntersect() + $this->getSlope() * $xValue; - } // function getValueOfYForX() + } /** * Return the X-Value for a specified value of Y @@ -64,7 +57,7 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit public function getValueOfXForY($yValue) { return ($yValue - $this->getIntersect()) / $this->getSlope(); - } // function getValueOfXForY() + } /** @@ -78,8 +71,8 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit $slope = $this->getSlope($dp); $intersect = $this->getIntersect($dp); - return 'Y = '.$intersect.' + '.$slope.' * X'; - } // function getEquation() + return 'Y = ' . $intersect . ' + ' . $slope . ' * X'; + } /** * Execute the regression and calculate the goodness of fit for a set of X and Y data values @@ -88,10 +81,10 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit * @param float[] $xValues The set of X-values for this regression * @param boolean $const */ - private function _linear_regression($yValues, $xValues, $const) + private function linearRegression($yValues, $xValues, $const) { - $this->_leastSquareFit($yValues, $xValues, $const); - } // function _linear_regression() + $this->leastSquareFit($yValues, $xValues, $const); + } /** * Define the regression and calculate the goodness of fit for a set of X and Y data values @@ -103,7 +96,7 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit public function __construct($yValues, $xValues = array(), $const = true) { if (parent::__construct($yValues, $xValues) !== false) { - $this->_linear_regression($yValues, $xValues, $const); + $this->linearRegression($yValues, $xValues, $const); } - } // function __construct() + } } diff --git a/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php b/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php index 7d561cda..221c5386 100644 --- a/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php +++ b/Classes/PHPExcel/Shared/trend/logarithmicBestFitClass.php @@ -1,6 +1,9 @@ getIntersect() + $this->getSlope() * log($xValue - $this->_Xoffset); - } // function getValueOfYForX() + return $this->getIntersect() + $this->getSlope() * log($xValue - $this->xOffset); + } /** * Return the X-Value for a specified value of Y @@ -64,7 +57,7 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit public function getValueOfXForY($yValue) { return exp(($yValue - $this->getIntersect()) / $this->getSlope()); - } // function getValueOfXForY() + } /** * Return the Equation of the best-fit line @@ -78,7 +71,7 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit $intersect = $this->getIntersect($dp); return 'Y = '.$intersect.' + '.$slope.' * log(X)'; - } // function getEquation() + } /** * Execute the regression and calculate the goodness of fit for a set of X and Y data values @@ -87,7 +80,7 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit * @param float[] $xValues The set of X-values for this regression * @param boolean $const */ - private function _logarithmic_regression($yValues, $xValues, $const) + private function logarithmicRegression($yValues, $xValues, $const) { foreach ($xValues as &$value) { if ($value < 0.0) { @@ -98,8 +91,8 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit } unset($value); - $this->_leastSquareFit($yValues, $xValues, $const); - } // function _logarithmic_regression() + $this->leastSquareFit($yValues, $xValues, $const); + } /** * Define the regression and calculate the goodness of fit for a set of X and Y data values @@ -111,7 +104,7 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit public function __construct($yValues, $xValues = array(), $const = true) { if (parent::__construct($yValues, $xValues) !== false) { - $this->_logarithmic_regression($yValues, $xValues, $const); + $this->logarithmicRegression($yValues, $xValues, $const); } - } // function __construct() + } } diff --git a/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php b/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php index b1b69b0a..8a882b74 100644 --- a/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php +++ b/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php @@ -1,6 +1,10 @@ _order; - } // function getOrder() + return $this->order; + } /** @@ -83,7 +74,7 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit } } return $retVal; - } // function getValueOfYForX() + } /** @@ -95,7 +86,7 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit public function getValueOfXForY($yValue) { return ($yValue - $this->getIntersect()) / $this->getSlope(); - } // function getValueOfXForY() + } /** @@ -109,17 +100,17 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit $slope = $this->getSlope($dp); $intersect = $this->getIntersect($dp); - $equation = 'Y = '.$intersect; + $equation = 'Y = ' . $intersect; foreach ($slope as $key => $value) { if ($value != 0.0) { - $equation .= ' + '.$value.' * X'; + $equation .= ' + ' . $value . ' * X'; if ($key > 0) { - $equation .= '^'.($key + 1); + $equation .= '^' . ($key + 1); } } } return $equation; - } // function getEquation() + } /** @@ -138,13 +129,13 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit return $coefficients; } return $this->_slope; - } // function getSlope() + } public function getCoefficients($dp = 0) { return array_merge(array($this->getIntersect($dp)), $this->getSlope($dp)); - } // function getCoefficients() + } /** @@ -155,13 +146,13 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit * @param float[] $xValues The set of X-values for this regression * @param boolean $const */ - private function _polynomial_regression($order, $yValues, $xValues, $const) + private function polynomialRegression($order, $yValues, $xValues, $const) { // calculate sums $x_sum = array_sum($xValues); $y_sum = array_sum($yValues); $xx_sum = $xy_sum = 0; - for ($i = 0; $i < $this->_valueCount; ++$i) { + for ($i = 0; $i < $this->valueCount; ++$i) { $xy_sum += $xValues[$i] * $yValues[$i]; $xx_sum += $xValues[$i] * $xValues[$i]; $yy_sum += $yValues[$i] * $yValues[$i]; @@ -174,12 +165,12 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit * a series of x-y data points using least squares. * */ - for ($i = 0; $i < $this->_valueCount; ++$i) { + for ($i = 0; $i < $this->valueCount; ++$i) { for ($j = 0; $j <= $order; ++$j) { $A[$i][$j] = pow($xValues[$i], $j); } } - for ($i=0; $i < $this->_valueCount; ++$i) { + for ($i=0; $i < $this->valueCount; ++$i) { $B[$i] = array($yValues[$i]); } $matrixA = new Matrix($A); @@ -195,14 +186,14 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit $coefficients[] = $r; } - $this->_intersect = array_shift($coefficients); + $this->intersect = array_shift($coefficients); $this->_slope = $coefficients; - $this->_calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum); - foreach ($this->_xValues as $xKey => $xValue) { - $this->_yBestFitValues[$xKey] = $this->getValueOfYForX($xValue); + $this->calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum); + foreach ($this->xValues as $xKey => $xValue) { + $this->yBestFitValues[$xKey] = $this->getValueOfYForX($xValue); } - } // function _polynomial_regression() + } /** @@ -216,10 +207,10 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit public function __construct($order, $yValues, $xValues = array(), $const = true) { if (parent::__construct($yValues, $xValues) !== false) { - if ($order < $this->_valueCount) { - $this->_bestFitType .= '_'.$order; - $this->_order = $order; - $this->_polynomial_regression($order, $yValues, $xValues, $const); + if ($order < $this->valueCount) { + $this->bestFitType .= '_'.$order; + $this->order = $order; + $this->polynomialRegression($order, $yValues, $xValues, $const); if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) { $this->_error = true; } @@ -227,5 +218,5 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit $this->_error = true; } } - } // function __construct() + } } diff --git a/Classes/PHPExcel/Shared/trend/powerBestFitClass.php b/Classes/PHPExcel/Shared/trend/powerBestFitClass.php index 38870af8..77c47342 100644 --- a/Classes/PHPExcel/Shared/trend/powerBestFitClass.php +++ b/Classes/PHPExcel/Shared/trend/powerBestFitClass.php @@ -1,6 +1,9 @@ getIntersect() * pow(($xValue - $this->_Xoffset), $this->getSlope()); - } // function getValueOfYForX() + return $this->getIntersect() * pow(($xValue - $this->xOffset), $this->getSlope()); + } /** @@ -67,8 +58,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit **/ public function getValueOfXForY($yValue) { - return pow((($yValue + $this->_Yoffset) / $this->getIntersect()), (1 / $this->getSlope())); - } // function getValueOfXForY() + return pow((($yValue + $this->yOffset) / $this->getIntersect()), (1 / $this->getSlope())); + } /** @@ -82,8 +73,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit $slope = $this->getSlope($dp); $intersect = $this->getIntersect($dp); - return 'Y = '.$intersect.' * X^'.$slope; - } // function getEquation() + return 'Y = ' . $intersect . ' * X^' . $slope; + } /** @@ -95,10 +86,10 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit public function getIntersect($dp = 0) { if ($dp != 0) { - return round(exp($this->_intersect), $dp); + return round(exp($this->intersect), $dp); } - return exp($this->_intersect); - } // function getIntersect() + return exp($this->intersect); + } /** @@ -108,7 +99,7 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit * @param float[] $xValues The set of X-values for this regression * @param boolean $const */ - private function _power_regression($yValues, $xValues, $const) + private function powerRegression($yValues, $xValues, $const) { foreach ($xValues as &$value) { if ($value < 0.0) { @@ -127,8 +118,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit } unset($value); - $this->_leastSquareFit($yValues, $xValues, $const); - } // function _power_regression() + $this->leastSquareFit($yValues, $xValues, $const); + } /** @@ -141,7 +132,7 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit public function __construct($yValues, $xValues = array(), $const = true) { if (parent::__construct($yValues, $xValues) !== false) { - $this->_power_regression($yValues, $xValues, $const); + $this->powerRegression($yValues, $xValues, $const); } } } diff --git a/Classes/PHPExcel/Shared/trend/trendClass.php b/Classes/PHPExcel/Shared/trend/trendClass.php index a7b34ed9..715cd412 100644 --- a/Classes/PHPExcel/Shared/trend/trendClass.php +++ b/Classes/PHPExcel/Shared/trend/trendClass.php @@ -1,6 +1,13 @@ getGoodnessOfFit(); } if ($trendType != self::TREND_BEST_FIT_NO_POLY) { - foreach (self::$_trendTypePolyOrders as $trendMethod) { + foreach (self::$trendTypePolynomialOrders as $trendMethod) { $order = substr($trendMethod, -1); $bestFit[$trendMethod] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const); if ($bestFit[$trendMethod]->getError()) { @@ -148,9 +140,8 @@ class trendClass arsort($bestFitValue); $bestFitType = key($bestFitValue); return $bestFit[$bestFitType]; - break; default: return false; } - } // function calculate() + } }