#!/bin/sh #----------------------------------------------------------------------- # File : djc_poss # Contents: possibilistic network induction on Danish Jersey Cattle data # on real world data # Author : Christian Borgelt # History : 17.12.1999 file created # 16.01.2000 simulated annealing added # 09.03.2002 shell changed from csh to sh # 10.04.2002 all induction loops moved into functions #----------------------------------------------------------------------- function collect () { gawk ' /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 } /minimum/ { minimum = $NF } /average/ { average = $NF } /maximum/ { maximum = $NF } /additional conditions/ { addcnt = $NF } /missing conditions/ { miscnt = $NF } END { printf("%-12s", network); printf(" %3d %5d", concnt, parcnt); printf(" %10g %10g %10g\n", minimum, average, maximum); }' } #----------------------------------------------------------------------- function average () { gawk ' function output() { if (NR > 0) { printf("%-10s", network); printf(" %6.1f %7.1f", concnt/n, parcnt/n); printf(" %10.3f %10.3f %10.3f\n", minimum/n, average/n, maximum/n); } } BEGIN { network = ""; } ($1 == network) { concnt += $2; parcnt += $3; minimum += $4; average += $5; maximum += $6; n++; } ($1 != network) { if (n > 0) output(); network = $1; n = 1; concnt = $2; parcnt = $3; minimum = $4; average = $5; maximum = $6; } END { if (n > 0) output(); }' poss.tmp } #----------------------------------------------------------------------- function induce () { # --- induce and evaluate networks ines -u'*' -mx -s$1 -e$2 djc.dom djc.tab $2 2> /dev/null neval -u'*' $2 djc.tab 2> /dev/null | collect > poss.tmp average | tee -a poss.res rm -f $2 } # induce() #----------------------------------------------------------------------- function fixed () { # --- evaluate empty/original network if [[ $1 == indep ]]; then in="djc.dom"; else in="djc.pnt"; fi ines -u'*' -mx $in djc.tab $1 2> /dev/null neval -u'*' $1 djc.tab 2> /dev/null | collect > poss.tmp average | tee -a poss.res rm -f $1 } # fixed() #----------------------------------------------------------------------- function owst () { # --- optimum weight spanning tree cons. echo "---owst---------------------------------------------------" \ | tee -a poss.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 poss.res for m in spcgain spcsgr1 chi2 mutspc; do induce extst $m done } # owst() #----------------------------------------------------------------------- function topord () { # --- selection on topological order echo "---topord-------------------------------------------------" \ | tee -a poss.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 poss.res for m in spcgain spcsgr1 chi2 mutspc; do ines -u'*' -mx -snoloop -e$m djc.dom djc.tab $m 2> /dev/null neval -u'*' $m djc.tab 2> /dev/null | collect > poss.tmp rm -f $m average | tee -a poss.res done } # noloop() #----------------------------------------------------------------------- function simul () { # --- hypertree simulated annealing echo "---sian---------------------------------------------------" \ | tee -a poss.res for p in 0 001; do # 0005 if (( p == 0 )); then out="sian_no"; else out="sian_yes"; fi rm -f poss.tmp for (( i = 0; i < 10; i++ )); do ines -u'*' -max -ssian -w0.$p -S1$i djc.dom djc.tab $out \ 2> /dev/null neval -u'*' $out djc.tab 2> /dev/null | collect >> poss.tmp rm -f $out done average | tee -a poss.res done } # simul() #----------------------------------------------------------------------- echo "network cond params minimum average maximum" \ | tee poss.res echo "----------------------------------------------------------" \ | tee -a poss.res fixed indep # evaluate empty network fixed orig # evaluate original network owst # optimum weight spanning tree construction #extst # optimum weight spanning tree extension topord # condition selection on topological order #noloop # condition selection avoiding directed loops simul # hypertree simulated annealing rm -f poss.tmp # clean up temporary file