#! /bin/bash # This version assumes the attributes have already been ranked and saved to $RankingFile # Arguments # ./attr $Filename $Path $Ranker $TestFile $TrainFile $LogFile $Horizon $RankingFile $SortingFile $Eval $Search Filename=$1 Path=$2 Ranker=$3 #TestFile=$4 TrainFile=$4 LogFile=$5 Horizon=$6 RankingFile=$7 SortingFile=$8 Eval=$9 Search=${10} EMstart=1 EMend=15 Stale=$Horizon Subset="" i=$EMstart # Set up the Ranking criteria for evaluating attributes if [ $Ranker = "correlation" ] then SortColumn=2 Reverse=1 fi if [ $Ranker = "variance_high" ] then SortColumn=3 Reverse=1 fi if [ $Ranker = "variance_low" ] then SortColumn=3 Reverse=-1 fi if [ $Ranker = "entropy_high" ] then SortColumn=4 Reverse=1 fi if [ $Ranker = "entropy_low" ] then SortColumn=4 Reverse=-1 fi # Set up the Evaluation criteria for finding improvement if [ $Eval = "mmre" ] then EvalColumn=1 EvalDef=1 fi if [ $Eval = "sd_mre" ] then EvalColumn=2 EvalDef=1 fi if [ $Eval = "pred30" ] then EvalColumn=3 EvalDef=0 fi if [ $Eval = "correlation" ] then EvalColumn=4 EvalDef=0 fi if (($EvalDef==1)) then NewValue=99999 else NewValue=-99999 fi if [ $Search = "backward" ] then Reverse=$((Reverse*-1)) fi if ((Reverse==1)) then sort -t, -nrk$SortColumn $RankingFile > $SortingFile else sort -t, -nk$SortColumn $RankingFile > $SortingFile fi while ((i<=EMend)) do NewSubset=$Subset$(gawk -v x=$i 'BEGIN{FS=","} NR==x{print $1}' $SortingFile) # If this is a backward elimination search then invert the subset. if [ $Search = "backward" ] then tmpSubset=$(./inverse $NewSubset $EMstart $EMend) else tmpSubset=$NewSubset fi # Try Local Calibration using the Subset. #EffortResult=$(./effort $Filename $Path "simpleLC" $TestFile $TrainFile $tmpSubset $LogFile"."$i) EffortResult=$(./effort $Filename $Path "simpleLC" $TrainFile $TrainFile $tmpSubset $LogFile"."$i) OldValue=$NewValue NewValue=$(echo $EffortResult | gawk -v EvalColumn=$EvalColumn 'BEGIN{FS=","} {print $EvalColumn}') # Test the new value and handle Subset Selection Keep=$(gawk -v a=$NewValue -v b=$OldValue 'BEGIN{print a> "test_attr.out" # If things have gotten stale it's time to move on, otherwise continue. if (($Stale<1)) then i=999 else i=$(($i+1)) fi done # Recreate the Final Selection if [ $Search = "backward" ] then tmpSubset=$(./inverse $Subset $EMstart $EMend) else tmpSubset=$Subset fi #./effort $Filename $Path "simpleLC" $TestFile $TrainFile $tmpSubset $LogFile".final" #./effort $Filename $Path "BasicLC" $TestFile $TrainFile $tmpSubset $LogFile".final" #Return the subset and LC will be called again with it. echo $tmpSubset