📄 djc_possx
字号:
#!/bin/sh#-----------------------------------------------------------------------# File : djc_possx# Contents: possibilistic network induction# on artificial Danish Jersey Cattle data# Author : Christian Borgelt# History : 23.01.2003 file created from djc_prob#-----------------------------------------------------------------------function generate (){ # --- generate random databases for (( i = 0; i < 10; i++ )); do gendb -s$(( $1*(i+1) )) djc.net - 2> /dev/null \ | uvins -p10 -s$(( $1 *(i+1) )) - train$i.tab 2> /dev/null gendb -s$(( $2*(i+1) )) djc.net - 2> /dev/null \ | uvins -p10 -s$(( $2 *(i+1) )) - test$i.tab 2> /dev/null done} # generate()#-----------------------------------------------------------------------function collect (){ # --- collect evaluation resultsgawk '/evaluation of/ { network = $3 }/number of attributes/ { attcnt = $NF }/number of conditions/ { concnt = $NF }/number of parameters/ { parcnt = $NF }/number of tuples/ { tplcnt = $NF }/impossible tuples/ { imptpl = $4 }/average/ { average = $NF }/minimum/ { minimum = $NF }/maximum/ { maximum = $NF }/additional conditions/ { addcnt = $NF }/missing conditions/ { miscnt = $NF }END { printf("%-12s", network); printf(" %3d %3d %3d", concnt, addcnt, miscnt); printf(" %5d %10g %10g %10g", parcnt, average, minimum, maximum);}'} # collect()#-----------------------------------------------------------------------function average (){ # --- average evaluation resultsgawk 'function output() { printf("%-10s", network); printf(" %6.1f %7.1f", concnt/n, parcnt/n); printf(" %6.3f/%5.3f/%5.3f", trn_avg/n, trn_min/n, trn_max/n); printf(" %6.3f/%5.3f/%5.3f\n", tst_avg/n, tst_min/n, tst_max/n);}BEGIN { network = ""; n = 0; }($1 == network) { concnt += $2; addcnt += $3; miscnt += $4; parcnt += $5; trn_avg += $6; trn_min += $7; trn_max += $8; tst_avg += $9; tst_min += $10; tst_max += $11; n++;}($1 != network) { if (n > 0) output(); network = $1; n = 1; concnt = $2; addcnt = $3; miscnt = $4; parcnt = $5; trn_avg = $6; trn_min = $7; trn_max = $8; tst_avg = $9; tst_min = $10; tst_max = $11;}END { if (n > 0) output(); }' possx.tmp} # average()#-----------------------------------------------------------------------function evaluate (){ # --- evaluate a given network neval -sc djc.net $1 train$2.tab 2> /dev/null | \ collect >> possx.tmp neval -s $1 test$2.tab 2> /dev/null | \ gawk '/average/ { printf(" %10g", $NF); } /minimum/ { printf(" %10g", $NF); } /maximum/ { printf(" %10g\n", $NF); }' >> possx.tmp rm -f $1} # evaluate()#-----------------------------------------------------------------------function induce (){ # --- induce and evaluate networks rm -f possx.tmp for (( i = 0; i < 10; i++ )); do ines -m -s$1 -e$m djc.dom train$i.tab $2 $x $3 2> /dev/null evaluate $2 $i done average | tee -a possx.res} # induce()#-----------------------------------------------------------------------function fixed (){ # --- evaluate empty/original network if [[ $1 == indep ]]; then in="djc.dom"; else in="djc.pnt"; fi rm -f possx.tmp for (( i = 0; i < 10; i++ )); do ines -m $in train$i.tab $1 2> /dev/null evaluate $1 $i done average | tee -a possx.res} # fixed()#-----------------------------------------------------------------------function owst (){ # --- optimum weight spanning tree cons. echo "---owst--------------------------------------------------------"\ | tee -a possx.res for m in spcgain spcsgr1 chi2 mutspc; do induce owst $m done} # owst()#-----------------------------------------------------------------------function extst (){ # --- optimum weight spanning tree ext. echo "---extst-------------------------------------------------------"\ | tee -a possx.res for m in spcgain spcsgr1 chi2 mutspc; do induce extst $m done} # extst()#----------------------------------------------------------------------- function topord (){ # --- selection on topological order echo "---topord------------------------------------------------------"\ | tee -a possx.res for m in spcgain spcgr spcsgr1 chi2 mutspc; do induce topord $m done} # topord()#-----------------------------------------------------------------------function noloop (){ # --- selection avoiding directed loops echo "---noloop------------------------------------------------------"\ | tee -a possx.res for m in spcgain spcgr spcsgr1 chi2 mutspc; do induce noloop $m done} # noloop()#-----------------------------------------------------------------------function sian (){ # --- hypertree simulated annealing echo "---sian--------------------------------------------------------"\ | tee -a possx.res for p in 0 1; do if (( p == 0 )); then out="sian_no"; else out="sian_yes"; fi rm -f possx.tmp for (( i = 0; i < 10; i++ )); do ines -m -ssian -w$p -S1$i djc.dom train$i.tab $out 2> /dev/null evaluate $out $i done average | tee -a possx.res done} # sian()#-----------------------------------------------------------------------function cleanup (){ # --- clean up temporary files rm -f possx.tmp rm -f train[0-9].tab rm -f test[0-9].tab} # cleanup()#-----------------------------------------------------------------------echo " train test" \ | tee possx.resecho "network cond params avg min max avg min max"\ | tee -a possx.resecho "---------------------------------------------------------------"\ | tee -a possx.resgenerate 13 17 # generate random databasesfixed indep # evaluate empty networkfixed orig # evaluate original networkowst # optimum weight spanning tree construction#extst # optimum weight spanning tree extensiontopord # condition selection on topological order#noloop # condition selection avoiding directed loops#sian # hypertree simulated annealingcleanup # clean up temporary files
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -