Merge branch 'psr2' into develop
This commit is contained in:
commit
0f427685bd
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Best_Fit
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,14 +25,6 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPExcel_Best_Fit
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_Trend
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Best_Fit
|
||||
{
|
||||
/**
|
||||
|
@ -39,89 +32,89 @@ class PHPExcel_Best_Fit
|
|||
*
|
||||
* @var boolean
|
||||
**/
|
||||
protected $_error = false;
|
||||
protected $error = false;
|
||||
|
||||
/**
|
||||
* Algorithm type to use for best-fit
|
||||
*
|
||||
* @var string
|
||||
**/
|
||||
protected $_bestFitType = 'undetermined';
|
||||
protected $bestFitType = 'undetermined';
|
||||
|
||||
/**
|
||||
* Number of entries in the sets of x- and y-value arrays
|
||||
*
|
||||
* @var int
|
||||
**/
|
||||
protected $_valueCount = 0;
|
||||
protected $valueCount = 0;
|
||||
|
||||
/**
|
||||
* X-value dataseries of values
|
||||
*
|
||||
* @var float[]
|
||||
**/
|
||||
protected $_xValues = array();
|
||||
protected $xValues = array();
|
||||
|
||||
/**
|
||||
* Y-value dataseries of values
|
||||
*
|
||||
* @var float[]
|
||||
**/
|
||||
protected $_yValues = array();
|
||||
protected $yValues = array();
|
||||
|
||||
/**
|
||||
* Flag indicating whether values should be adjusted to Y=0
|
||||
*
|
||||
* @var boolean
|
||||
**/
|
||||
protected $_adjustToZero = false;
|
||||
protected $adjustToZero = false;
|
||||
|
||||
/**
|
||||
* Y-value series of best-fit values
|
||||
*
|
||||
* @var float[]
|
||||
**/
|
||||
protected $_yBestFitValues = array();
|
||||
protected $yBestFitValues = array();
|
||||
|
||||
protected $_goodnessOfFit = 1;
|
||||
protected $goodnessOfFit = 1;
|
||||
|
||||
protected $_stdevOfResiduals = 0;
|
||||
protected $stdevOfResiduals = 0;
|
||||
|
||||
protected $_covariance = 0;
|
||||
protected $covariance = 0;
|
||||
|
||||
protected $_correlation = 0;
|
||||
protected $correlation = 0;
|
||||
|
||||
protected $_SSRegression = 0;
|
||||
protected $SSRegression = 0;
|
||||
|
||||
protected $_SSResiduals = 0;
|
||||
protected $SSResiduals = 0;
|
||||
|
||||
protected $_DFResiduals = 0;
|
||||
protected $DFResiduals = 0;
|
||||
|
||||
protected $_F = 0;
|
||||
protected $f = 0;
|
||||
|
||||
protected $_slope = 0;
|
||||
protected $slope = 0;
|
||||
|
||||
protected $_slopeSE = 0;
|
||||
protected $slopeSE = 0;
|
||||
|
||||
protected $_intersect = 0;
|
||||
protected $intersect = 0;
|
||||
|
||||
protected $_intersectSE = 0;
|
||||
protected $intersectSE = 0;
|
||||
|
||||
protected $_Xoffset = 0;
|
||||
protected $xOffset = 0;
|
||||
|
||||
protected $_Yoffset = 0;
|
||||
protected $yOffset = 0;
|
||||
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->_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;
|
||||
}
|
||||
return $this->_slope;
|
||||
} // function getSlope()
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return $this->_slopeSE;
|
||||
} // function getSlopeSE()
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return $this->_intersect;
|
||||
} // function getIntersect()
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return $this->_intersectSE;
|
||||
} // function getIntersectSE()
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return $this->_goodnessOfFit;
|
||||
} // function getGoodnessOfFit()
|
||||
|
||||
public function getGoodnessOfFitPercent($dp = 0)
|
||||
{
|
||||
if ($dp != 0) {
|
||||
return round($this->_goodnessOfFit * 100, $dp);
|
||||
return round($this->goodnessOfFit * 100, $dp);
|
||||
}
|
||||
return $this->goodnessOfFit * 100;
|
||||
}
|
||||
return $this->_goodnessOfFit * 100;
|
||||
} // function getGoodnessOfFitPercent()
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return $this->_stdevOfResiduals;
|
||||
} // function getStdevOfResiduals()
|
||||
|
||||
public function getSSRegression($dp = 0)
|
||||
{
|
||||
if ($dp != 0) {
|
||||
return round($this->_SSRegression, $dp);
|
||||
return round($this->SSRegression, $dp);
|
||||
}
|
||||
return $this->SSRegression;
|
||||
}
|
||||
return $this->_SSRegression;
|
||||
} // function getSSRegression()
|
||||
|
||||
public function getSSResiduals($dp = 0)
|
||||
{
|
||||
if ($dp != 0) {
|
||||
return round($this->_SSResiduals, $dp);
|
||||
return round($this->SSResiduals, $dp);
|
||||
}
|
||||
return $this->SSResiduals;
|
||||
}
|
||||
return $this->_SSResiduals;
|
||||
} // function getSSResiduals()
|
||||
|
||||
public function getDFResiduals($dp = 0)
|
||||
{
|
||||
if ($dp != 0) {
|
||||
return round($this->_DFResiduals, $dp);
|
||||
return round($this->DFResiduals, $dp);
|
||||
}
|
||||
return $this->DFResiduals;
|
||||
}
|
||||
return $this->_DFResiduals;
|
||||
} // function getDFResiduals()
|
||||
|
||||
public function getF($dp = 0)
|
||||
{
|
||||
if ($dp != 0) {
|
||||
return round($this->_F, $dp);
|
||||
return round($this->f, $dp);
|
||||
}
|
||||
return $this->f;
|
||||
}
|
||||
return $this->_F;
|
||||
} // function getF()
|
||||
|
||||
public function getCovariance($dp = 0)
|
||||
{
|
||||
if ($dp != 0) {
|
||||
return round($this->_covariance, $dp);
|
||||
return round($this->covariance, $dp);
|
||||
}
|
||||
return $this->covariance;
|
||||
}
|
||||
return $this->_covariance;
|
||||
} // function getCovariance()
|
||||
|
||||
public function getCorrelation($dp = 0)
|
||||
{
|
||||
if ($dp != 0) {
|
||||
return round($this->_correlation, $dp);
|
||||
return round($this->correlation, $dp);
|
||||
}
|
||||
return $this->correlation;
|
||||
}
|
||||
return $this->_correlation;
|
||||
} // function getCorrelation()
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Exponential_Best_Fit
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,18 +27,6 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Exponential_Best_Fit
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_Trend
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
|
||||
{
|
||||
/**
|
||||
|
@ -44,7 +35,7 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
|
|||
*
|
||||
* @var string
|
||||
**/
|
||||
protected $_bestFitType = 'exponential';
|
||||
protected $bestFitType = 'exponential';
|
||||
|
||||
/**
|
||||
* Return the Y-Value for a specified value of X
|
||||
|
@ -54,8 +45,8 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
|
|||
**/
|
||||
public function getValueOfYForX($xValue)
|
||||
{
|
||||
return $this->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);
|
||||
}
|
||||
return exp($this->_intersect);
|
||||
} // function getIntersect()
|
||||
|
||||
/**
|
||||
* 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()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Linear_Best_Fit
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,16 +27,6 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
|
||||
|
||||
/**
|
||||
* PHPExcel_Linear_Best_Fit
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_Trend
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
|
||||
{
|
||||
/**
|
||||
|
@ -42,7 +35,7 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
|
|||
*
|
||||
* @var string
|
||||
**/
|
||||
protected $_bestFitType = 'linear';
|
||||
protected $bestFitType = 'linear';
|
||||
|
||||
/**
|
||||
* Return the Y-Value for a specified value of X
|
||||
|
@ -53,7 +46,7 @@ class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
|
|||
public function getValueOfYForX($xValue)
|
||||
{
|
||||
return $this->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()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Logarithmic_Best_Fit
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,16 +27,6 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
|
||||
|
||||
/**
|
||||
* PHPExcel_Logarithmic_Best_Fit
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_Trend
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
|
||||
{
|
||||
/**
|
||||
|
@ -42,7 +35,7 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
|
|||
*
|
||||
* @var string
|
||||
**/
|
||||
protected $_bestFitType = 'logarithmic';
|
||||
protected $bestFitType = 'logarithmic';
|
||||
|
||||
/**
|
||||
* Return the Y-Value for a specified value of X
|
||||
|
@ -52,8 +45,8 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
|
|||
**/
|
||||
public function getValueOfYForX($xValue)
|
||||
{
|
||||
return $this->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()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
<?php
|
||||
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Polynomial_Best_Fit
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,19 +28,6 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Polynomial_Best_Fit
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_Trend
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
|
||||
{
|
||||
/**
|
||||
|
@ -45,7 +36,7 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
|
|||
*
|
||||
* @var string
|
||||
**/
|
||||
protected $_bestFitType = 'polynomial';
|
||||
protected $bestFitType = 'polynomial';
|
||||
|
||||
/**
|
||||
* Polynomial order
|
||||
|
@ -53,7 +44,7 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
|
|||
* @protected
|
||||
* @var int
|
||||
**/
|
||||
protected $_order = 0;
|
||||
protected $order = 0;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -63,8 +54,8 @@ class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
|
|||
**/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->_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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Power_Best_Fit
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,18 +27,6 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Power_Best_Fit
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_Trend
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
|
||||
{
|
||||
/**
|
||||
|
@ -44,7 +35,7 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
|
|||
*
|
||||
* @var string
|
||||
**/
|
||||
protected $_bestFitType = 'power';
|
||||
protected $bestFitType = 'power';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -55,8 +46,8 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
|
|||
**/
|
||||
public function getValueOfYForX($xValue)
|
||||
{
|
||||
return $this->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);
|
||||
}
|
||||
return exp($this->_intersect);
|
||||
} // function getIntersect()
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<?php
|
||||
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/linearBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/powerBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/polynomialBestFitClass.php';
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_trendClass
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,22 +31,6 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/linearBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/powerBestFitClass.php';
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/polynomialBestFitClass.php';
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_trendClass
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_Trend
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class trendClass
|
||||
{
|
||||
const TREND_LINEAR = 'Linear';
|
||||
|
@ -59,17 +50,20 @@ class trendClass
|
|||
*
|
||||
* @var string[]
|
||||
**/
|
||||
private static $_trendTypes = array( self::TREND_LINEAR,
|
||||
private static $trendTypes = array(
|
||||
self::TREND_LINEAR,
|
||||
self::TREND_LOGARITHMIC,
|
||||
self::TREND_EXPONENTIAL,
|
||||
self::TREND_POWER
|
||||
);
|
||||
|
||||
/**
|
||||
* Names of the best-fit trend polynomial orders
|
||||
*
|
||||
* @var string[]
|
||||
**/
|
||||
private static $_trendTypePolyOrders = array( self::TREND_POLYNOMIAL_2,
|
||||
private static $trendTypePolynomialOrders = array(
|
||||
self::TREND_POLYNOMIAL_2,
|
||||
self::TREND_POLYNOMIAL_3,
|
||||
self::TREND_POLYNOMIAL_4,
|
||||
self::TREND_POLYNOMIAL_5,
|
||||
|
@ -81,7 +75,7 @@ class trendClass
|
|||
*
|
||||
* @var PHPExcel_Best_Fit[]
|
||||
**/
|
||||
private static $_trendCache = array();
|
||||
private static $trendCache = array();
|
||||
|
||||
|
||||
public static function calculate($trendType = self::TREND_BEST_FIT, $yValues, $xValues = array(), $const = true)
|
||||
|
@ -107,34 +101,32 @@ class trendClass
|
|||
case self::TREND_LOGARITHMIC:
|
||||
case self::TREND_EXPONENTIAL:
|
||||
case self::TREND_POWER:
|
||||
if (!isset(self::$_trendCache[$key])) {
|
||||
if (!isset(self::$trendCache[$key])) {
|
||||
$className = 'PHPExcel_'.$trendType.'_Best_Fit';
|
||||
self::$_trendCache[$key] = new $className($yValues, $xValues, $const);
|
||||
self::$trendCache[$key] = new $className($yValues, $xValues, $const);
|
||||
}
|
||||
return self::$_trendCache[$key];
|
||||
break;
|
||||
return self::$trendCache[$key];
|
||||
case self::TREND_POLYNOMIAL_2:
|
||||
case self::TREND_POLYNOMIAL_3:
|
||||
case self::TREND_POLYNOMIAL_4:
|
||||
case self::TREND_POLYNOMIAL_5:
|
||||
case self::TREND_POLYNOMIAL_6:
|
||||
if (!isset(self::$_trendCache[$key])) {
|
||||
if (!isset(self::$trendCache[$key])) {
|
||||
$order = substr($trendType, -1);
|
||||
self::$_trendCache[$key] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
|
||||
self::$trendCache[$key] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
|
||||
}
|
||||
return self::$_trendCache[$key];
|
||||
break;
|
||||
return self::$trendCache[$key];
|
||||
case self::TREND_BEST_FIT:
|
||||
case self::TREND_BEST_FIT_NO_POLY:
|
||||
// If the request is to determine the best fit regression, then we test each trend line in turn
|
||||
// Start by generating an instance of each available trend method
|
||||
foreach (self::$_trendTypes as $trendMethod) {
|
||||
foreach (self::$trendTypes as $trendMethod) {
|
||||
$className = 'PHPExcel_'.$trendMethod.'BestFit';
|
||||
$bestFit[$trendMethod] = new $className($yValues, $xValues, $const);
|
||||
$bestFitValue[$trendMethod] = $bestFit[$trendMethod]->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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue