(defmacro StartStopMacro (x) ( let ( ;declare gensyms (s (gensym)) (m (gensym)) (h (gensym))) `(multiple-value-bind (,s ,m ,h) (get-decoded-time) (progn (format t "Time Started is ~A:~A:~A~%" ,h ,m ,s) ,x (multiple-value-bind (,s ,m ,h) (get-decoded-time) (format t "Time Stopped is ~A:~A:~A~%" ,h ,m ,s))) ))) (defun rdrWrapper (&key (statfunc #'pd) (verbose nil) (showresults nil) (bins 10) (crush nil)) (let ((datasets `(,(weather) ,(contact-lens) ,(breast-cancer) ,(breastTumor) ,(primary-tumor) ,(meta) ,(soybean) ,(titanic))) ;actual data ; (results) (runTimes) (baseline) (itterations 2)) ;make a key value (progn (if crush (progn (setf datasets (reverse ;puts the crush list first (append datasets `( ,(anneal) ;work ;,(audiology) ,(auto93);work ,(autoHorse) ;work ,(autoMpg);work ,(autoPrice) ;work ,(autos) ;work ,(basketball) ;work ,(bodyfat);work ,(bolts);work ,(boston-housing);work ,(cholesterol) ;work ,(cleveland-14-heart-disease) ;work ,(cleveland) ;work ,(cloud) ;work ,(cpu) ;work ,(credit-rating) ;work ,(detroit) ;work ,(echoMonths) ;work ,(elusage) ;work ,(fishcatch) ;work ,(fruitfly) ;work ,(gascons) ;work ,(horse-colic) ;work ,(housing) ;work ,(hungarian-14-heart-disease) ;work ,(hungarian) ;work ;,(hypothyroid) ;break due to last row being all ? ,(ionosphere) ;work ,(kr-vs-kp) ;work ;,(letter) ;Causes Process to Die ,(lowbwt) ;work ,(mammal-sleep) ;work ,(mbagrade) ;work ,(mushroom) ;work ;,(pbc) ;work ,(pharynx) ;works ,(pima_diabetes) ;works ,(pollution) ;work ,(pwLinear) ;work ,(quake) ;work ,(schlvote) ;works now with the check of an unknown class ;,(segment) ;breaks due to ewd on the 3rd column resulting in a divide by zero ,(sensory) ;work ,(servo) ;work ;,(sick) ;breaks due to the 3rd last column not containing any data to discretize on ,(sonar);works ;,(splice) ;Causes Process to Die ,(strike) ;works ,(vehicle) ;works ,(veteran) ;works ,(vineyard) ;works ;,(vote) ;error in data set caused a break ,(vowel) ;works ; ,(waveform) ;Causes Process to Die ,(weather.nominal) ;works )))) ;Adds the Crush data sets to be run (setf itterations 20))) ;end Crush Check (with-open-file (out (format nil "makecharts/data/WrapperResults.dat") :direction :output :if-does-not-exist :create :if-exists :rename) (progn (sh "/bin/bash" "-c" "rm makecharts/data/WhitneyData.dat") (format out "(~%") (let ((xxxxxx 0)) (dolist (currentData datasets) (incf xxxxxx) (let ((patchpolicy '(GenerateRuleMatchNB GenerateRuleMatchMinusAvoidNB GenerateRuleMatchWeightedRandom GenerateRuleMatchMinusAvoidWeightedRandom GenerateRuleMatchRandom GenerateRuleMatchMinusAvoidRandom)) ;patch policys (patchname '(NB Minus-Avoid-NB Weighted-Random Avoid-Weighted-Random Random Minus-Avoid-Random)) ;policy names (tempTable) (allresults)) ;put the patchpolicy in the same form as the datasets (progn (setf baseline (naivebayes 5 currentData :verbose nil)) ;Produce baseline results (setf currentData (discretize currentData bins)) (setf allresults nil) (dotimes (n itterations) (makeWhitney (table-name currentData) 'ICCLE_NB n (newNaiveBayes 5 currentData :verbose nil))) (dolist (currentPatch patchpolicy) (progn (dotimes (n itterations) (progn (setf tempTable (table-copy currentData (shuffle (table-egs currentData)))) ; copys the shuffled data into a new table for running HACK ;(makeWhitney (table-name currentData) 'ICCLE__NB n (newNaiveBayes 10 currentData :verbose nil)) ; <~ COPY IN THE WHITNEY STATS!! (setf runTimes (append runTimes (list(get-internal-run-time)))) ;add the new run time to the list (setf results (append results (makeWhitney (table-name currentData) currentPatch n (rdr tempTable :n 5 :rulegenerator currentPatch :noiselevel .2)))) (setf runTimes (replace runTimes (list (- (get-internal-run-time) (car (last runTimes)))) :start1 (- (length runTimes) 1)));Produce the difference of the run times )) ;close shuffle and rdr excute (setf results (averageABCDs results)) (setf runTimes (fround (/ (/ (sum runTimes) (length runTimes)) internal-time-units-per-second) 4)) (setf allresults (append allresults (list results))) (if verbose (progn (format t "Finished rdr on shuffled data from ~A(~A of ~A) using policy ~A~%" (table-name currentData) xxxxxx (length datasets) (car patchname)) (format t "~5I Executed in ~A Seconds~%" runTimes))) (if showresults (format t "Average results = ~A~%" results)) (format out "(RDR Results from ~A using policy ~A Executed in ~A Seconds)~%~A~%~%~%" (table-name currentData) (car patchname) runTimes results) ;(makedatafiles results baseline statfunc (table-name currentData) (car patchname)) (setf results nil) (setf runTimes nil) (pop patchname) )) ;close dolist on patch policies ;(format t "All Results = ~A~%" allresults) (makedatafiles allresults baseline statfunc (table-name currentData) patchname))))) ; close dolist on datasets (format out ")~%"))))));close function (defun averageABCDs (stats) (let ((itteration 0) (temp) (count 0) (classes) (abcdSum) (result) (zerolist)) (progn (setf stats (sort stats '< :key #'(lambda (x) (car x)))) ; line to put data in order of itterations (dolist (x stats) (dolist (y (cdr x)) (if (null (position (abcd-for y) classes)) (progn (setf classes (append classes (list(abcd-for y)))) (setf zerolist (append zerolist (list '(0 0 0 0)))))) ; close if )) (dolist (x stats) (progn (if (not (= itteration (car x))) (progn (if (not (null abcdSum)) ; make sure something exists in abcdSum (setf result (append result (list(append `(,itteration) (mapcar #'(lambda (class values) (make-abcd :for class :a (floor (/ (first values) count)) :b (floor (/ (second values) count)) :c (floor (/ (third values) count)) :d (floor (/ (fourth values) count)))) classes abcdSum)))))) (setf itteration (car x)) (setf count 0) (setf abcdSum (copy-list zerolist)))) ; close if (dolist (abcds (cdr x)) (progn (setf temp (position (abcd-for abcds) classes)) (setf abcdSum (replace abcdSum (list (mapcar #'(lambda (x y) (+ x y)) (nth temp abcdSum) `(,(abcd-a abcds) ,(abcd-b abcds) ,(abcd-c abcds) ,(abcd-d abcds)))) :start1 temp)) )) ; close abcds loop (setf count (+ 1 count))));close stats loop (if (not (null abcdSum)) ; get the last values summed (setf result (append result (list(append `(,itteration) (mapcar #'(lambda (class values) (make-abcd :for class :a (floor (/ (first values) count)) :b (floor (/ (second values) count)) :c (floor (/ (third values) count)) :d (floor (/ (fourth values) count)))) classes abcdSum)))))) result)));close main (deftest testAvgABCD () (check (samep (averageABCDs (list (list 1 (make-abcd :for 'a :a 1 :b 1 :c 1 :d 1)) (list 1 (make-abcd :for 'a :a 2 :b 2 :c 2 :d 2)) (list 1 (make-abcd :for 'a :a 3 :b 3 :c 3 :d 3)))) "((1 #(ABCD :FOR A :A 2 :B 2 :C 2 :D 2 :ACC .50 :PD .50 :PF .50 :PREC .50 :F .50 :BAL .50)))"))) (defun makeWhitney (tname treatment snum stats) (with-open-file (out (format nil "makecharts/data/WhitneyData.dat") :direction :output :if-does-not-exist :create :if-exists :append) (if (= (file-length out) 0) (format out "Dataset, Treatment, Class, ShuffleNum, Fold, PD, PF~%")) (dolist (x stats) (dolist (y (cdr x)) (format out "~A, ~A, ~A, ~A, ~A, ~A, ~A~%" tname treatment (abcd-for y) snum (car x) (pd y) (pf y))))stats))