\dbsp

\lstset{language=bash}
\lstset{backgroundcolor=\color{listinggray}}
\lstset{frameround=tttt}
\lstset{basicstyle=\tiny}
\lstset{showstringspaces=false, showspaces=false, showtabs=false}
\begin{center}
\ssp
\begin{lstlisting}[frame=trBL]{}
#!/bin/bash
# /* vim: set filetype=sh : */ -*- sh -*- 

DESTDIR=${DESTDIR="/srv/bronze/dj"}
MyHome=${MyHome=${HOME}} #${HOME}}

# Q0: where will the output be stored
Safe=${Safe=${DESTDIR}/var/weka}
BinDir=${BinDir=${MyHome}/bin}

# Q1: where is your data? 
Data=${Data=${MyHome}/var/data/discrete}

# Q2: what data sets will we run?
# A2: only those with discrete classes:
Datums=${Datums="a2b/audiology a2b/auto-mpg
                 a2b/breast-cancer a2b/breast-cancer-wisconsin
                 c2d/credit-a c2d/diabetes e2i/ecoli e2i/flag e2i/hayes-roth 
                 e2i/heart-c e2i/heart-h e2i/hepatitis e2i/imports-85 
                 e2i/iris j2p/kr-vs-kp j2p/letter j2p/mushroom
                 q2s/segment  q2s/splice q2s/soybean t2z/vowel  
                 t2z/wine t2z/wdbc t2z/waveform-5000"}

# Q3: what learners will you try? 
Learners=${Learners="bayes"}
bayes() { wttp $1 $2 $wBayes | gotwant ; } 

[ -f  "$Functions" ] && . $Functions

# Q4 : what pre-processors will you use
Preps=${Preps="cat disctree3 fayyadIrani pkid tbin"}
disctree3() { dtree3 DynTree=1 Pass=1 $1 Pass=2 $1; }
tbin()  { tenbins Pass=1 $1 Pass=2 $1 Pass=3 $1; }
pkid() { wpkid $1;}

# Q5: how many repeats? 
Repeats=${Repeats=10}

# Q6: how many bins? 
Bins=${Bins=10}

# All right then. Lets go! 
mkdir -p $Safe                # ensure safe place exists
Tmp=`mktemp -d`               # make a sandbox where only you will play
trap "rm -rf $Tmp" 0 1 2 3 15 # leave nothing behind when you quit 
cd $Tmp                       # go to the sandbox

main() {
  set -x
  for datum in $Datums
  do
  	echo "#data,learner,prep,train,test,repeats,bin,goal,a,b,c,d,accuracy,pd,pf,precision,bal"
	for prep in $Preps
	do
	  $prep ${Data}/${datum}.arff > data.arff 
          for((repeats=1;repeats<=$Repeats;repeats++))
	  do
	     seed=$RANDOM
      	     for((bin=1;bin<=${Bins};bin++))
      	     do
		cat data.arff | someArff --seed $seed --bins $Bins --bin $bin
		goals=`cat data.arff | classes --brief`
		n1=`instances train.arff`
		n2=`instances test.arff`
                for learn in $Learners
                do
		   $learn train.arff test.arff > results.csv
		   cp results.csv $Safe/results.csv
		   for goal in $goals
		   do
		     b4="$datum,$learn,$prep,$n1,$n2,$repeats,$bin,$goal";
		     cat results.csv | ${BinDir}/abcd -g "$goal" -p "${b4}" -d 1 | tail -n 1
                   #abcd Prefix="${b4}" False="${one}" True="${two}"
		   done
done; done; done; done; done
}

Log=$$
Start=`date +%H:%M:%S%t%m/%d/%Y`
(main | tee $Safe/xval.$Log ) 2> $Safe/xval.err.$Log 
doExtras $Safe/xval.$Log > $Safe/myresults.$Log.csv

echo "Computing acc comparison"
winlosstie --input $Safe/myresults.$Log.csv --fields 18 --perform 13 --key 3 --95 --high > $Safe/crossvalaccmw.$Log.csv
echo "Computing pd comparison"
winlosstie --input $Safe/myresults.$Log.csv --fields 18 --perform 14 --key 3 --95 --high > $Safe/crossvalpdmw.$Log.csv
echo "Computing prec comparison"
winlosstie --input $Safe/myresults.$Log.csv --fields 18 --perform 16 --key 3 --95 --high > $Safe/crossvalprecmw.$Log.csv
echo "Computing bal comparison"
winlosstie --input $Safe/myresults.$Log.csv --fields 18 --perform 17 --key 3 --95 --high > $Safe/crossvalbalmw.$Log.csv
echo "Computing npf comparison"
winlosstie --input $Safe/myresults.$Log.csv --fields 18 --perform 18 --key 3 --95 --high > $Safe/crossvalnpfmw.$Log.csv

End=`date +%H:%M:%S%t%m/%d/%Y`
echo $Start "to" $End 
echo $Start "to" $End >> myresults.$Log.csv
echo $Safe/xval.$Log
\end{lstlisting}
\end{center}

\dbsp

Notes on Support Scripts:
\bi 
\item \textit{instances} counts the number of data instances that occur in the data file provided to it.
\item \textit{someArff} randomly generates the testing and training data sets from the file provided.
\item \textit{classes} returns the classes found in the provided data set.
\item \textit{abcd} computes the A, B, C, and D values for the provided data file and also calculates each instances Accuracy, PD, PF, Balance, and Precision score
\item \textit{doExtras} computes the !PF score for each instance of the results
\item \textit{winlosstie} computers the $U$-test tables for each performance measure provided.
\ei 


\subsection*{WTTP Script}
\lstset{language=bash}
\lstset{backgroundcolor=\color{listinggray}}
\lstset{frameround=tttt}
\lstset{basicstyle=\tiny}
\lstset{showstringspaces=false, showspaces=false, showtabs=false}
\begin{center}
\ssp
\begin{lstlisting}[frame=trBL]{}
#!/bin/bash
t=$1;
T=$2;
shift 2
$wEka $* -p 0 -t $t -T $T
\end{lstlisting}
\end{center}

\ssp
