(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 (list)) ;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 `( ,(ar3) ,(ar4) ,(ar5) ,(CM1) ,(jm1) ,(kc1) ,(kc2) ,(kc3) ,(mc2) ,(mw1) ,(PC1) )))) ;Adds the Crush data sets to be run (setf itterations 4))) ;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) ;(if (not (probe-file (format nil "makecharts/data/WrapperDone-~A.dat" (table-name currentData)))) (if (not (probe-file (format nil "makecharts/data/WrapperResults-~A.dat" (table-name currentData)))) (with-open-file (out (format nil "makecharts/data/WrapperResults-~A.dat" (table-name currentData)) :direction :output :if-does-not-exist :create :if-exists :rename) ;(format out "(~%") (sh "/bin/bash" "-c" (format nil "rm makecharts/data/WhitneyData-~A.dat" (table-name currentData))) (let ((1ps (list t nil)) (globals (list t nil)) (fmods (list nil)) (patchpolicy '(GenerateRuleMatchFrequency GenerateRuleMatchMinusAvoidFrequency GenerateRuleMatchWeightedRandom GenerateRuleMatchMinusAvoidWeightedRandom GenerateRuleMatchRandom GenerateRuleMatchMinusAvoidRandom)) ;patch policys (patchname '(Freq Minus-Avoid-Freq Weighted-Random Avoid-Weighted-Random Hyperpipes-Random Minus-Avoid-Hyperpipes-Random)) ; NB-1p Minus-Avoid-NB1p Weighted-Random1p Avoid-Weighted-Random1p 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) ;(print "Here1") (dotimes (n itterations) (makeWhitney (table-name currentData) 'ICCLE_NB n (newNaiveBayes 5 currentData :verbose nil))) ;(print "Here 2") (dolist (fmod fmods) (dolist (global globals) (dolist (1p 1ps) (let ((nnn 0)) (dolist (currentPatch patchpolicy) (let ((treesize 0)) (dotimes (n itterations) (let ((streesize 0)) (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 (rdr tempTable :n 5 :rulegenerator currentPatch :noiselevel .2 :1p 1p :fmod fmod :global global)) ;(print 1) (setf results (mapcar #'(lambda (x) (incf treesize (car (last x))) (append (list (car x)) (reverse (rest (reverse (rest x)))))) results)) ;(incf treesize (last results)) ;(print results) ;(print 2) ;(setf results (reverse (rest (reverse results)))) ;(print 3) (setf results (append results (makeWhitney (table-name currentData) currentPatch n results))) ;(print 4) (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) (concatenate 'string (format nil "~A" (nth nnn patchname)) (if global "-global" "-local") (if 1p "-1p" "-xp") (if fmod "-freq" "-prob"))) (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 Rules)~%~A~%~%~%" (table-name currentData) (concatenate 'string (format nil "~A" (nth nnn patchname)) (if global "-global" "-local") (if 1p "-1p" "-xp") (if fmod "-freq" "-prob")) runTimes (* (/ treesize itterations) 5) results) ;(makedatafiles results baseline statfunc (table-name currentData) (car patchname)) (setf results nil) (setf runTimes nil) ;(pop patchname) (incf nnn) )))))) ;close dolist on patch policies ;(format t "All Results = ~A~%" allresults) (makedatafiles allresults baseline statfunc (table-name currentData) patchname))) (with-open-file (out2 (format nil "makecharts/data/WrapperDone-~A.dat" (table-name currentData)) :direction :output :if-does-not-exist :create :if-exists :rename) (format out2 "Done")))))))))) (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 (z (cdr x)) (dolist (y z) (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 (abcdsa (cdr x)) (dolist (abcds abcdsa) (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)) stats)