[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/Shared/trend/ -> exponentialBestFitClass.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1