Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2388 jpm 1
<?php
2
/**
3
 * PHPExcel
4
 *
5
 * Copyright (c) 2006 - 2013 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 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
25
 * @version    ##VERSION##, ##DATE##
26
 */
27
 
28
 
29
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
30
 
31
 
32
/**
33
 * PHPExcel_Logarithmic_Best_Fit
34
 *
35
 * @category   PHPExcel
36
 * @package    PHPExcel_Shared_Trend
37
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
38
 */
39
class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
40
{
41
	/**
42
	 * Algorithm type to use for best-fit
43
	 * (Name of this trend class)
44
	 *
45
	 * @var	string
46
	 **/
47
	protected $_bestFitType		= 'logarithmic';
48
 
49
 
50
	/**
51
	 * Return the Y-Value for a specified value of X
52
	 *
53
	 * @param	 float		$xValue			X-Value
54
	 * @return	 float						Y-Value
55
	 **/
56
	public function getValueOfYForX($xValue) {
57
		return $this->getIntersect() + $this->getSlope() * log($xValue - $this->_Xoffset);
58
	}	//	function getValueOfYForX()
59
 
60
 
61
	/**
62
	 * Return the X-Value for a specified value of Y
63
	 *
64
	 * @param	 float		$yValue			Y-Value
65
	 * @return	 float						X-Value
66
	 **/
67
	public function getValueOfXForY($yValue) {
68
		return exp(($yValue - $this->getIntersect()) / $this->getSlope());
69
	}	//	function getValueOfXForY()
70
 
71
 
72
	/**
73
	 * Return the Equation of the best-fit line
74
	 *
75
	 * @param	 int		$dp		Number of places of decimal precision to display
76
	 * @return	 string
77
	 **/
78
	public function getEquation($dp=0) {
79
		$slope = $this->getSlope($dp);
80
		$intersect = $this->getIntersect($dp);
81
 
82
		return 'Y = '.$intersect.' + '.$slope.' * log(X)';
83
	}	//	function getEquation()
84
 
85
 
86
	/**
87
	 * Execute the regression and calculate the goodness of fit for a set of X and Y data values
88
	 *
89
	 * @param	 float[]	$yValues	The set of Y-values for this regression
90
	 * @param	 float[]	$xValues	The set of X-values for this regression
91
	 * @param	 boolean	$const
92
	 */
93
	private function _logarithmic_regression($yValues, $xValues, $const) {
94
		foreach($xValues as &$value) {
95
			if ($value < 0.0) {
96
				$value = 0 - log(abs($value));
97
			} elseif ($value > 0.0) {
98
				$value = log($value);
99
			}
100
		}
101
		unset($value);
102
 
103
		$this->_leastSquareFit($yValues, $xValues, $const);
104
	}	//	function _logarithmic_regression()
105
 
106
 
107
	/**
108
	 * Define the regression and calculate the goodness of fit for a set of X and Y data values
109
	 *
110
	 * @param	float[]		$yValues	The set of Y-values for this regression
111
	 * @param	float[]		$xValues	The set of X-values for this regression
112
	 * @param	boolean		$const
113
	 */
114
	function __construct($yValues, $xValues=array(), $const=True) {
115
		if (parent::__construct($yValues, $xValues) !== False) {
116
			$this->_logarithmic_regression($yValues, $xValues, $const);
117
		}
118
	}	//	function __construct()
119
 
120
}	//	class logarithmicBestFit