Read 1335 times | Created 2017-01-03 23:52:56 | Updated 2017-01-04 00:07:57 | | |
<?php /* -- ---------------------------- -- DEMPSTER SHAFER -- CREATED BY : CAHYA DSN -- CREATED ON : 2017-01-02 -- UPDATED ON : 2017-01-03 -- ---------------------------- DROP TABLE IF EXISTS ds_problems; CREATE TABLE IF NOT EXISTS ds_problems( id INT AUTO_INCREMENT, code VARCHAR(3), name VARCHAR(30), PRIMARY KEY (id) ) ENGINE=MyISAM CHARSET=utf8; DROP TABLE IF EXISTS ds_symptoms; CREATE TABLE IF NOT EXISTS ds_symptoms( id INT AUTO_INCREMENT, code VARCHAR(3), name VARCHAR(30), PRIMARY KEY (id) ) ENGINE=MyISAM CHARSET=utf8; DROP TABLE IF EXISTS ds_rules; CREATE TABLE IF NOT EXISTS ds_rules( id INT AUTO_INCREMENT, id_problem INT, id_symptom INT, cf float, PRIMARY KEY (id) ) ENGINE=MyISAM CHARSET=utf8; ******************************** DATA FOR SIMULATION ONLY ******************************** */ $data=array( array('B,D,F',0.4), array('A,F',0.5), array('B',0.4), array('A,D,F',0.3) ); $all=array(); foreach($data as $d) $all[]=$d[0]; $unique=array_unique(explode(',',implode(',',$all))); $fod=implode(',',$unique); echo "<pre>"; echo $fod; $rst=array(); while(!empty($data)){ $result=array(); $symptom[0]=array_shift($data); $symptom[1]=array($fod,1-$symptom[0][1]); if(empty($rst)) $result[0]=array_shift($data); else foreach($rst as $k=>$r) if($k!="θ") $result[]=array($k,$r); $theta=1; foreach($result as $r) $theta-=$r[1]; $result[]=array($fod,$theta); $m=count($result); $rst=array(); for($x=0;$x<$m;$x++){ for($y=0;$y<2;$y++){ if(!($x==$m-1 && $y==1)){ $v=explode(',',$symptom[$y][0]); $w=explode(',',$result[$x][0]); sort($v);sort($w); $vw=array_intersect($v,$w); if(empty($vw)) $v="θ";else $v=implode(',',$vw); if(!isset($rst[$v])) $rst[$v]=$result[$x][1]*$symptom[$y][1]; else $rst[$v]+=$result[$x][1]*$symptom[$y][1]; } } } foreach($rst as $k=>$r) if($k!="θ") $rst[$k]=$r/(1-(isset($rst["θ"])?$rst["θ"]:0)); print_r($rst); } unset($rst["θ"]); arsort($rst); print_r($rst); ?> demo at <a href='http://cahyadsn.dev.php.or.id/extra/dst.php'> http://cahyadsn.dev.php.or.id/extra/dst.php </a> © 2017 cahyadsn