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