summaryrefslogtreecommitdiffstats
path: root/src/datasets
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-08-17 11:49:04 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-08-17 11:49:04 +0000
commit24758cba490f1670961042c6470ad7579af1f8c1 (patch)
treef36c9879c84cf7d35fc34d914a35508d7066e021 /src/datasets
parent441e0054ad7b4f38d4596cf3ceda08ec00cc2127 (diff)
downloadzetacomponents-graph-24758cba490f1670961042c6470ad7579af1f8c1.zip
zetacomponents-graph-24758cba490f1670961042c6470ad7579af1f8c1.tar.gz
- Fixed matrices to use parameter order <row>, <column>
- Added dataset which builds polygon of defined order for set of points # Using least squares algorithm - Added method to solve a subset of nonlinear equatations to matrix class # Using Gauss-Newton algorithm
Diffstat (limited to 'src/datasets')
-rw-r--r--src/datasets/average.php79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/datasets/average.php b/src/datasets/average.php
index 3af2094..a964f57 100644
--- a/src/datasets/average.php
+++ b/src/datasets/average.php
@@ -9,11 +9,88 @@
*/
/**
* Extension of basic dataset to represent averation.
+ * Algorithm: http://en.wikipedia.org/wiki/Least_squares
*
* @package Graph
*/
-class ezcGraphDataSetAverage extends ezcGraphDataSet
+class ezcGraphDataSetAveragePolynom extends ezcGraphDataSet
{
+ protected $polynomOrder = 3;
+ protected $source;
+
+ protected $resolution = 5;
+
+ protected $polynom = false;
+
+ public function __construct( ezcGraphDataSet $dataset )
+ {
+ $this->source = $dataset;
+ }
+
+ /**
+ * Options write access
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * If Option could not be found
+ * @throws ezcBaseValueException
+ * If value is out of range
+ * @param mixed $propertyName Option name
+ * @param mixed $propertyValue Option value;
+ * @return mixed
+ */
+ public function __set( $propertyName, $propertyValue )
+ {
+ switch ( $propertyName ) {
+ case 'polynomOrder':
+ $this->polynomOrder = (int) $propertyValue;
+ $this->polynom = false;
+ break;
+ default:
+ throw new ezcBasePropertyNotFoundException( $propertyName );
+ break;
+ }
+ }
+
+ protected function buildPolynom()
+ {
+ $points = array();
+
+ foreach ( $this->source as $key => $value )
+ {
+ $points[] = new ezcGraphCoordinate( (float) $key, (float) $value );
+ }
+
+ // Build transposed and normal Matrix out of coordiantes
+ $a = new ezcGraphMatrix( count( $points ), $this->polynomOrder + 1 );
+ $b = new ezcGraphMatrix( count( $points ), 1 );
+
+ for ( $i = 0; $i <= $this->polynomOrder; ++$i )
+ {
+ foreach ( $points as $nr => $point )
+ {
+ $a->set( $nr, $i, pow( $point->x, $i ) );
+ $b->set( $nr, 0, $point->y );
+ }
+ }
+
+ $at = clone $a;
+ $at->transpose();
+
+ $left = $at->multiply( $a );
+ $right = $at->multiply( $b );
+
+ $this->polynom = $left->solveNonlinearEquatation( $right );
+ }
+
+ public function getPolynom()
+ {
+ if ( $this->polynom === false )
+ {
+ $this->buildPolynom();
+ }
+
+ return $this->polynom;
+ }
}
?>
OpenPOWER on IntegriCloud