[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  
   3  require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
   4  
   5  /**
   6   * PHPExcel_Power_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_Power_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        = 'power';
  39  
  40  
  41      /**
  42       * Return the Y-Value for a specified value of X
  43       *
  44       * @param     float        $xValue            X-Value
  45       * @return     float                        Y-Value
  46       **/
  47      public function getValueOfYForX($xValue)
  48      {
  49          return $this->getIntersect() * pow(($xValue - $this->xOffset), $this->getSlope());
  50      }
  51  
  52  
  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      {
  61          return pow((($yValue + $this->yOffset) / $this->getIntersect()), (1 / $this->getSlope()));
  62      }
  63  
  64  
  65      /**
  66       * Return the Equation of the best-fit line
  67       *
  68       * @param     int        $dp        Number of places of decimal precision to display
  69       * @return     string
  70       **/
  71      public function getEquation($dp = 0)
  72      {
  73          $slope = $this->getSlope($dp);
  74          $intersect = $this->getIntersect($dp);
  75  
  76          return 'Y = ' . $intersect . ' * X^' . $slope;
  77      }
  78  
  79  
  80      /**
  81       * Return the Value of X where it intersects Y = 0
  82       *
  83       * @param     int        $dp        Number of places of decimal precision to display
  84       * @return     string
  85       **/
  86      public function getIntersect($dp = 0)
  87      {
  88          if ($dp != 0) {
  89              return round(exp($this->intersect), $dp);
  90          }
  91          return exp($this->intersect);
  92      }
  93  
  94  
  95      /**
  96       * Execute the regression and calculate the goodness of fit for a set of X and Y data values
  97       *
  98       * @param     float[]    $yValues    The set of Y-values for this regression
  99       * @param     float[]    $xValues    The set of X-values for this regression
 100       * @param     boolean    $const
 101       */
 102      private function powerRegression($yValues, $xValues, $const)
 103      {
 104          foreach ($xValues as &$value) {
 105              if ($value < 0.0) {
 106                  $value = 0 - log(abs($value));
 107              } elseif ($value > 0.0) {
 108                  $value = log($value);
 109              }
 110          }
 111          unset($value);
 112          foreach ($yValues as &$value) {
 113              if ($value < 0.0) {
 114                  $value = 0 - log(abs($value));
 115              } elseif ($value > 0.0) {
 116                  $value = log($value);
 117              }
 118          }
 119          unset($value);
 120  
 121          $this->leastSquareFit($yValues, $xValues, $const);
 122      }
 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->powerRegression($yValues, $xValues, $const);
 136          }
 137      }
 138  }


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