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_Exponential_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_Exponential_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		= 'exponential';
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() * pow($this->getSlope(),($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 log(($yValue + $this->_Yoffset) / $this->getIntersect()) / log($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.'^X';
83
	}	//	function getEquation()
84
 
85
 
86
	/**
87
	 * Return the Slope of the line
88
	 *
89
	 * @param	 int		$dp		Number of places of decimal precision to display
90
	 * @return	 string
91
	 **/
92
	public function getSlope($dp=0) {
93
		if ($dp != 0) {
94
			return round(exp($this->_slope),$dp);
95
		}
96
		return exp($this->_slope);
97
	}	//	function getSlope()
98
 
99
 
100
	/**
101
	 * Return the Value of X where it intersects Y = 0
102
	 *
103
	 * @param	 int		$dp		Number of places of decimal precision to display
104
	 * @return	 string
105
	 **/
106
	public function getIntersect($dp=0) {
107
		if ($dp != 0) {
108
			return round(exp($this->_intersect),$dp);
109
		}
110
		return exp($this->_intersect);
111
	}	//	function getIntersect()
112
 
113
 
114
	/**
115
	 * Execute the regression and calculate the goodness of fit for a set of X and Y data values
116
	 *
117
	 * @param	 float[]	$yValues	The set of Y-values for this regression
118
	 * @param	 float[]	$xValues	The set of X-values for this regression
119
	 * @param	 boolean	$const
120
	 */
121
	private function _exponential_regression($yValues, $xValues, $const) {
122
		foreach($yValues as &$value) {
123
			if ($value < 0.0) {
124
				$value = 0 - log(abs($value));
125
			} elseif ($value > 0.0) {
126
				$value = log($value);
127
			}
128
		}
129
		unset($value);
130
 
131
		$this->_leastSquareFit($yValues, $xValues, $const);
132
	}	//	function _exponential_regression()
133
 
134
 
135
	/**
136
	 * Define the regression and calculate the goodness of fit for a set of X and Y data values
137
	 *
138
	 * @param	float[]		$yValues	The set of Y-values for this regression
139
	 * @param	float[]		$xValues	The set of X-values for this regression
140
	 * @param	boolean		$const
141
	 */
142
	function __construct($yValues, $xValues=array(), $const=True) {
143
		if (parent::__construct($yValues, $xValues) !== False) {
144
			$this->_exponential_regression($yValues, $xValues, $const);
145
		}
146
	}	//	function __construct()
147
 
148
}	//	class exponentialBestFit