Location: PHPKode > projects > Finasystem > fs_ta/fulogic.php
<?php
/**
* Finasystem version 0.4 Lin Hai - Technical Analysis Library in PHP
 *Release: 14/10/2006
 *Copyright (C) 2006 Rudy Zuck
 *mailto:rudy[-at-]zuck.fr
 *web:http://sourceforge.net/projects/finasystem
 *
 *This program is free software; you can redistribute it and/or
 *modify it under the terms of the GNU General Public License
 *as published by the Free Software Foundation; either version 2
 *of the License, or any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program; if not, write to the Free Software
 *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA  
 */

/**
 * Fuzzy Logic (fulogic)
 *
 *<p>Fuzzy logic is an extension of Boolean logic dealing with the concept of partial truth. 
 *Whereas classical logic holds that everything can be expressed in binary terms 
 *(0 or 1, black or white, yes or no), fuzzy logic replaces boolean truth values 
 *with degrees of truth. </p>

 *<p>This class implements the fuzzification with three fuzzy sets : low, medium, and high. 
 *Each variable contains a degree of thruth considering the inpur data.</p>
 *
 *
 *<p>Formula:</p>
 *
 * - to complete
 *
 * @author Rudy Zuck <rudy[-at-]zuck.fr>
 * @copyright Copyright, 2006, Rudy Zuck
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version 0.4
 * @package fs_ta
 */

class fulogic{

	/**
	 * @var double[]
	 */
	private $low;
	/**
	 * @var double[]
	 */
	private $medium;
	/**
	 * @var double[]
	 */
	private $high;

	/**
     * @param double[] $data
	 * @return void
     */
	function set($data){
		$counter=0;
		$size_data = count($data); 
		
		for($i=0;$i<$size_data;$i++){
			
			if ($data[$i] <= 0.5){
				$this->low[$i] = (-2 * $data[$i]) + 1;
				$this->medium[$i] = 2 * $data[$i];
				$this->hight[$i] = 0;
			}
			
			if ($data[$i] > 0.5){
				$this->low[$i] = 0;
				$this->medium[$i] = (-2 * $data[$i]) + 2;
				$this->high[$i] = (2 * $data[$i]) - 1;
			}
		}
	}
	
	/** 
     * @return double[]
     */
	function get_low(){
		return $this->low;
	}
	
	/** 
     * @return double[]
     */
	function get_medium(){
		return $this->medium;
	}
	
	/** 
     * @return double[]
     */
	function get_high(){
		return $this->high;
	}
}
?>
Return current item: Finasystem