cvs: pear /Math_Histogram AbstractHistogram.php Histogram.php Histogram3D.php

From: Date: Sun, 19 May 2002 19:21:38 +0000
Subject: cvs: pear /Math_Histogram AbstractHistogram.php Histogram.php Histogram3D.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3937@lists.php.net to get a copy of this message
jmcastagnetto Sun May 19 15:21:38 2002 EDT Added files: /pear/Math_Histogram Histogram3D.php Modified files: /pear/Math_Histogram AbstractHistogram.php Histogram.php Log: Added (incomplete) Histogram3D. More refactoring between Histogram and AbstractHistogram Index: pear/Math_Histogram/AbstractHistogram.php diff -u pear/Math_Histogram/AbstractHistogram.php:1.2 pear/Math_Histogram/AbstractHistogram.php:1.3 --- pear/Math_Histogram/AbstractHistogram.php:1.2 Fri May 17 21:57:31 2002 +++ pear/Math_Histogram/AbstractHistogram.php Sun May 19 15:21:38 2002 @@ -16,7 +16,7 @@ // | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // -// $Id: AbstractHistogram.php,v 1.2 2002/05/18 01:57:31 jmcastagnetto Exp $ +// $Id: AbstractHistogram.php,v 1.3 2002/05/19 19:21:38 jmcastagnetto Exp $ // include_once "Math/Stats.php"; @@ -171,6 +171,22 @@ return $this->_data; }/*}}}*/ + /** + * Returns the array of data used to calculate the histogram, + * i.e. the data that was inside the range specified for the + * histogram bins + * + * @access public + * @return mixed a numerical array on success, a PEAR_Error object otherwise + * + * @see setData() + */ + function getHistogramData() {/*{{{*/ + if (is_null($this->_data)) + return PEAR::raiseError("data has not been set"); + else + return $this->_histogramData(); + }/*}}}*/ /** * Utility function to check that a value is in the given range @@ -210,6 +226,18 @@ $this->_bins = array(); }/*}}}*/ + /** + * Abstract method that returns an array of data contained within the + * range for the histogram calculation + * Each subclass must implement this method + * + * @access private + * @return array + */ + function _histogramData() {/*{{{*/ + return array(); + }/*}}}*/ + }/*}}}*/ Index: pear/Math_Histogram/Histogram.php diff -u pear/Math_Histogram/Histogram.php:1.4 pear/Math_Histogram/Histogram.php:1.5 --- pear/Math_Histogram/Histogram.php:1.4 Fri May 17 21:57:31 2002 +++ pear/Math_Histogram/Histogram.php Sun May 19 15:21:38 2002 @@ -16,7 +16,7 @@ // | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Histogram.php,v 1.4 2002/05/18 01:57:31 jmcastagnetto Exp $ +// $Id: Histogram.php,v 1.5 2002/05/19 19:21:38 jmcastagnetto Exp $ // //include_once "Math/AbstractHistogram.php"; @@ -142,23 +142,6 @@ }/*}}}*/ /** - * Returns the array of data used to calculate the histogram, - * i.e. the data that was inside the range specified for the - * histogram bins - * - * @access public - * @return mixed a numerical array on success, a PEAR_Error object otherwise - * - * @see setData() - */ - function getHistogramData() {/*{{{*/ - if (is_null($this->_data)) - return PEAR::raiseError("data has not been set"); - else - return $this->_histogramData(); - }/*}}}*/ - - /** * Calculates the histogram bins and frequencies * * @access public @@ -347,8 +330,9 @@ }/*}}}*/ /** - * Returns an array of data contained within the range for - * the histogram calculation + * Returns an array of data contained within the range for the + * histogram calculation. Overrides the empty implementation in + * Math_AbstractHistogram::_histogramData() * * @access private * @return array Index: pear/Math_Histogram/Histogram3D.php +++ pear/Math_Histogram/Histogram3D.php <?php class Math_Histogram3D extends Math_AbstractHistogram {/*{{{*/ function Math_Histogram3D($type=HISTOGRAM_SIMPLE,$binOptions="") {/*{{{*/ $this->setType($type); $this->setBinOptions($binOptions); }/*}}}*/ function setBinOptions($binOptions) {/*{{{*/ if ( $this->_validBinOptions($binOptions) ) return parent::setBinOptions($binOptions); else return PEAR::raiseError("incorrect options array"); }/*}}}*/ function setData($data) {/*{{{*/ $this->_clear(); if (!$this->_validData($data)) return PEAR::raiseError("array of numeric coordinates expected"); $this->_data = $data; list($xMin, $xMax) = $this->_getMinMax('x'); list($yMin, $yMax) = $this->_getMinMax('y'); if (is_null($this->_rangeLow)) $this->_rangeLow = array('x'=>$xMin, 'y'=>$yMin); if (is_null($this->_rangeHigh)) $this->_rangeHigh = array('x'=>$xMax, 'y'=>$yMax); if (is_null($this->_nbins)) $this->_nbins = array('x'=>10, 'y'=>10); return true; }/*}}}*/ function calculate() { } function _getMinMax($elem) { return array(min($this->_data[$elem]), max($this->_data[$elem])); } function _validBinOptions($binOptions) { $barray = ( is_array($binOptions) && is_array($binOptions['low']) && is_array($binOptions['high']) && is_array($binOptions['nbins']) ); $low = $binOptions['low']; $high = $binOptions['high']; $nbins = $binOptions['nbins']; $blow = ( isset($low['x']) && isset($low['y']) && is_numeric($low['x']) && is_numeric($low['y']) ); $bhigh = ( isset($high['x']) && isset($high['y']) && is_numeric($high['x']) && is_numeric($high['y']) ); $bnbins = ( isset($nbins['x']) && isset($nbins['y']) && is_numeric($nbins['x']) && is_numeric($nbins['y']) ); return ($barray && $blow && $bhigh && $bnbins); } function _validData($data) { if (is_array($data) && is_array($data['x']) && is_array($data['y'])) { $n = count($data['x']) if (count($data) == 2 && $n == count($data['y'])) for ($i=0; $i < $n; $i++) if (!is_numeric($data['x'][$i]) || !is_numeric($data['y'][$i])) return false; // if everything checks out return true; else return false; } else { return false; } } }/*}}}*/ // vim: ts=4:sw=4:et: // vim6: fdl=1: ?>

« previous php.pear.cvs (#3937) next »