⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 djc_local

📁 数据挖掘中的一算法 ines算法 c下实现的。适合初学习数据挖掘者借鉴
💻
字号:
#!/bin/sh#-----------------------------------------------------------------------# File    : djc_local# Contents: probabilistic network induction with local structure#           on artificial Danish Jersey Cattle data# Author  : Christian Borgelt# History : 17.12.1999 file created#           17.07.2002 all induction loops moved into functions#           23.07.2002 bdeu handling moved to function induce#-----------------------------------------------------------------------function generate (){                               # --- generate random databases  for (( i = 0; i < 10; i++ )); do    gendb -s$(( $1*(i+1) )) djc.net train$i.tab 2> /dev/null    gendb -s$(( $2*(i+1) )) djc.net 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  }/minimum/               { minimum = $NF }/average/               { average = $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", parcnt, average);}'}  # collect()#-----------------------------------------------------------------------function average (){                               # --- average evaluation resultsgawk 'function output() {  if (NR > 0) {    printf("%-10s", network);    printf(" %6.1f %6.1f %6.1f", concnt/n, addcnt/n, miscnt/n);    printf(" %7.1f %10.1f %10.1f\n", parcnt/n, train/n, test/n);  }}BEGIN { network = ""; }($1 == network) {  concnt += $2; addcnt += $3; miscnt += $4;  parcnt += $5; train  += $6; test   += $7; n++;}($1 != network) {  if (n > 0) output();  network = $1; n = 1;  concnt  = $2; addcnt  = $3; miscnt  = $4;  parcnt  = $5; train   = $6; test    = $7;}END { if (n > 0) output(); }' local.tmp}  # average()#-----------------------------------------------------------------------function evaluate (){                               # --- evaluate a given network  neval -L1 -c djc.net $1 train$2.tab 2> /dev/null | \    collect >> local.tmp  neval -L1            $1 test$2.tab  2> /dev/null | \    gawk '/average/ { printf(" %10.1f\n", $NF); }' >> local.tmp  rm -f $1}  # evaluate()#-----------------------------------------------------------------------function induce (){                               # --- induce and evaluate networks  rm -f local.tmp  if [[ $2 == bdeu ]]; then m="bdm" x="-p-20";                       else m=$2    x=""; fi  for (( i = 0; i < 10; i++ )); do    ines -s$1 -e$m djc.dom train$i.tab $2 $x $3 2> /dev/null    evaluate $2 $i  done  average | tee -a local.res}  # induce()#-----------------------------------------------------------------------function indlocal (){                               # --- induce and evaluate networks  rm -f local.tmp  if [[ $2 == bdeu ]]; then m="bdm" x="-p-20";                       else m=$2    x=""; fi  for (( i = 0; i < 10; i++ )); do    ines -c2 -s$1 -e$m djc.dom train$i.tab $2 $x $3 2> /dev/null    ines -c0 -s$1 -e$m -g-1e-12 $2 train$i.tab $2 $x $3 2> /dev/null    evaluate $2 $i  done  average | tee -a local.res}  # indlocal()#-----------------------------------------------------------------------function fixed (){                               # --- evaluate empty/original network  if [[ $1 == indep ]]; then in="djc.dom";                        else in="djc.net"; fi  rm -f local.tmp  for (( i = 0; i < 10; i++ )); do    ines $in train$i.tab $1 2> /dev/null    evaluate $1 $i  done  average | tee -a local.res}  # fixed()#----------------------------------------------------------------------- function topord (){                               # --- greedy condition selection  echo "---topord----------------------------------------------------" \       | tee -a local.res  for m in infgain infgr infsgr1 gini chi2 bdm bdeu rdlrel; do    induce topord $m  done}  # topord()#----------------------------------------------------------------------- function local (){                               # --- local structure learning  echo "---local-----------------------------------------------------" \       | tee -a local.res  for m in infgain infgr infsgr1 gini chi2 bdm bdeu rdlrel; do    induce topord $m -g-1e-12  done}  # local()#----------------------------------------------------------------------- function lwise (){                               # --- levelwise local structure learning  echo "---lwise-----------------------------------------------------" \       | tee -a local.res  for m in infgain infgr infsgr1 gini chi2 bdm bdeu rdlrel; do    induce topord $m -G-1e-12  done}  # lwise()#----------------------------------------------------------------------- function post (){                               # --- local structure learning  echo "---post------------------------------------------------------" \       | tee -a local.res  for m in infgain infgr infsgr1 gini chi2 bdm bdeu rdlrel; do    indlocal topord $m  done}  # post()#-----------------------------------------------------------------------function cleanup (){                               # --- clean up temporary files  rm -f local.tmp  rm -f train[0-9].tab  rm -f test[0-9].tab}  # cleanup()#-----------------------------------------------------------------------echo "network      cond    add   miss  params      train       test" \     | tee local.resecho "-------------------------------------------------------------" \     | tee -a local.resgenerate 13 17          # generate random databasesfixed indep             # evaluate empty    networkfixed orig              # evaluate original networktopord                  # condition selection on topological orderlocal                   # local structure learning (unrestricted)#lwise                   # local structure learning (levelwise)#post                    # local structure learning (preserving global)cleanup                 # clean up temporary files

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -