[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  
   3  require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
   4  
   5  /**
   6   * PHPExcel_Linear_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_Linear_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        = 'linear';
  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() + $this->getSlope() * $xValue;
  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 ($yValue - $this->getIntersect()) / $this->getSlope();
  60      }
  61  
  62  
  63      /**
  64       * Return the Equation of the best-fit line
  65       *
  66       * @param     int        $dp        Number of places of decimal precision to display
  67       * @return     string
  68       **/
  69      public function getEquation($dp = 0)
  70      {
  71          $slope = $this->getSlope($dp);
  72          $intersect = $this->getIntersect($dp);
  73  
  74          return 'Y = ' . $intersect . ' + ' . $slope . ' * X';
  75      }
  76  
  77      /**
  78       * Execute the regression and calculate the goodness of fit for a set of X and Y data values
  79       *
  80       * @param     float[]    $yValues    The set of Y-values for this regression
  81       * @param     float[]    $xValues    The set of X-values for this regression
  82       * @param     boolean    $const
  83       */
  84      private function linearRegression($yValues, $xValues, $const)
  85      {
  86          $this->leastSquareFit($yValues, $xValues, $const);
  87      }
  88  
  89      /**
  90       * Define the regression and calculate the goodness of fit for a set of X and Y data values
  91       *
  92       * @param    float[]        $yValues    The set of Y-values for this regression
  93       * @param    float[]        $xValues    The set of X-values for this regression
  94       * @param    boolean        $const
  95       */
  96      public function __construct($yValues, $xValues = array(), $const = true)
  97      {
  98          if (parent::__construct($yValues, $xValues) !== false) {
  99              $this->linearRegression($yValues, $xValues, $const);
 100          }
 101      }
 102  }


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