PageRenderTime 57ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/application/libraries/PHPExcel/Classes/PHPExcel/Shared/trend/exponentialBestFitClass.php

https://bitbucket.org/dipendrapkrl/excelapi
PHP | 148 lines | 45 code | 21 blank | 82 comment | 6 complexity | b30206f06c658d67b6f48d0a6db9a303 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2012 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Shared_Trend
  23. * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.7, 2012-05-19
  26. */
  27. require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
  28. /**
  29. * PHPExcel_Exponential_Best_Fit
  30. *
  31. * @category PHPExcel
  32. * @package PHPExcel_Shared_Trend
  33. * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  34. */
  35. class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
  36. {
  37. /**
  38. * Algorithm type to use for best-fit
  39. * (Name of this trend class)
  40. *
  41. * @var string
  42. **/
  43. protected $_bestFitType = 'exponential';
  44. /**
  45. * Return the Y-Value for a specified value of X
  46. *
  47. * @param float $xValue X-Value
  48. * @return float Y-Value
  49. **/
  50. public function getValueOfYForX($xValue) {
  51. return $this->getIntersect() * pow($this->getSlope(),($xValue - $this->_Xoffset));
  52. } // function getValueOfYForX()
  53. /**
  54. * Return the X-Value for a specified value of Y
  55. *
  56. * @param float $yValue Y-Value
  57. * @return float X-Value
  58. **/
  59. public function getValueOfXForY($yValue) {
  60. return log(($yValue + $this->_Yoffset) / $this->getIntersect()) / log($this->getSlope());
  61. } // function getValueOfXForY()
  62. /**
  63. * Return the Equation of the best-fit line
  64. *
  65. * @param int $dp Number of places of decimal precision to display
  66. * @return string
  67. **/
  68. public function getEquation($dp=0) {
  69. $slope = $this->getSlope($dp);
  70. $intersect = $this->getIntersect($dp);
  71. return 'Y = '.$intersect.' * '.$slope.'^X';
  72. } // function getEquation()
  73. /**
  74. * Return the Slope of the line
  75. *
  76. * @param int $dp Number of places of decimal precision to display
  77. * @return string
  78. **/
  79. public function getSlope($dp=0) {
  80. if ($dp != 0) {
  81. return round(exp($this->_slope),$dp);
  82. }
  83. return exp($this->_slope);
  84. } // function getSlope()
  85. /**
  86. * Return the Value of X where it intersects Y = 0
  87. *
  88. * @param int $dp Number of places of decimal precision to display
  89. * @return string
  90. **/
  91. public function getIntersect($dp=0) {
  92. if ($dp != 0) {
  93. return round(exp($this->_intersect),$dp);
  94. }
  95. return exp($this->_intersect);
  96. } // function getIntersect()
  97. /**
  98. * Execute the regression and calculate the goodness of fit for a set of X and Y data values
  99. *
  100. * @param float[] $yValues The set of Y-values for this regression
  101. * @param float[] $xValues The set of X-values for this regression
  102. * @param boolean $const
  103. */
  104. private function _exponential_regression($yValues, $xValues, $const) {
  105. foreach($yValues as &$value) {
  106. if ($value < 0.0) {
  107. $value = 0 - log(abs($value));
  108. } elseif ($value > 0.0) {
  109. $value = log($value);
  110. }
  111. }
  112. unset($value);
  113. $this->_leastSquareFit($yValues, $xValues, $const);
  114. } // function _exponential_regression()
  115. /**
  116. * Define the regression and calculate the goodness of fit for a set of X and Y data values
  117. *
  118. * @param float[] $yValues The set of Y-values for this regression
  119. * @param float[] $xValues The set of X-values for this regression
  120. * @param boolean $const
  121. */
  122. function __construct($yValues, $xValues=array(), $const=True) {
  123. if (parent::__construct($yValues, $xValues) !== False) {
  124. $this->_exponential_regression($yValues, $xValues, $const);
  125. }
  126. } // function __construct()
  127. } // class exponentialBestFit