(defparameter *histBest* (make-hash-table)) (defparameter *histRest* (make-hash-table)) (defun make-k-vs-score(file number) (let ((tnum (* 2 number))) (if (equal "vh" file) (incf tnum)) (dotimes (x tnum) (setf *seed* (* (* (random 1000) (random 1000)) tnum)))) (if (equal file "vh") (setf (dist9-min (gethash 'DYNAMISIM *dists*)) 40 (dist9-max (gethash 'DYNAMISIM *dists*)) 50)) (if (equal file "sh") (setf (dist9-min (gethash 'DYNAMISIM *dists*)) 30 (dist9-max (gethash 'DYNAMISIM *dists*)) 40)) (if (equal file "mi") (setf (dist9-min (gethash 'DYNAMISIM *dists*)) 20 (dist9-max (gethash 'DYNAMISIM *dists*)) 30)) (if (equal file "sl") (setf (dist9-min (gethash 'DYNAMISIM *dists*)) 10 (dist9-max (gethash 'DYNAMISIM *dists*)) 20)) (if (equal file "vl") (setf (dist9-min (gethash 'DYNAMISIM *dists*)) 1 (dist9-max (gethash 'DYNAMISIM *dists*)) 10)) (dotimes (x 1000) (demo-search5 (format nil "data5/k-vs-score-~A-~A.csv" file (+ (* number 1000) x)) (format nil "data5/4-corners-~A-~A.csv" file (+ (* number 1000) x))) (format t "KEYS RUN# ~A~%" x))) (defun demo-search5(filename filename2) (with-open-file (out filename :direction :output :if-exists :supersede :if-does-not-exist :create) ;(let (out2) (with-open-file (out2 filename2 :direction :output :if-exists :supersede :if-does-not-exist :create) ;(format t "************************************************~% This is Keys talking to you~%**********************************************~%") ;(format t "I'm now running Keys with Agile~%") ;(keys 'AG 2000 out out2) ;(format t "~%~%------------------------------------------~%") (format t "I'm now running Keys with Agile2~%") (keys 'AG2 2000 out out2) ;(format t "~%~%------------------------------------------~%") (format t "I'm now running Keys with Planbased~%") (keys 'PB 2000 out out2) ;(format t "~%~%------------------------------------------~%") ;(format t "I'm now running Keys with Hybrid~%") ;(keys 'HY 1000 out out2)))) ))) (defun keys(type testIterations out out2) ;(format out "#~A~%" type) (let ((scoresTreatments nil) (totalScore 0) (pAvgScore 0) (allow t) (bins 10) (Completed nil) (best nil) (probBest 0.1) (probRest 0.9) (rankedMembers) counter (thestuff (make-hash-table))) (reset-all-sample) (storeDists *dists*) (dotimes (x 7) (if allow (progn (setf totalScore 0) (resetHists bins) (dotimes (iteration testIterations) (progn (push (list (runPom2 type) (completeallbut (getStatic))) scoresTreatments) (format out "~A, ~A, ~A, ~A, ~A, ~A, ~A, ~A, ~A, ~A, ~A, ~A~%" type x (+ (* x testIterations) iteration) (floor (* 100 (first (first scoresTreatments)))) (get-static 'SIZE) (get-static 'DYNAMISIM) (get-static 'CRITICALITY) (get-static 'CRITICALITYMODIFIER) (get-static 'CULTURE) (get-static 'INITIALKNOWN) (get-static 'INTERDEPENDANCY) (get-static 'TEAMSIZE)) (incf totalScore (floor (* 100 (first (first scoresTreatments))))) )) (setf allow (if (and (> (/ totalScore testIterations) (+ pAvgScore (* .05 (- 100 pAvgScore)))) allow) t nil)) (setf scoresTreatments (sort scoresTreatments #'> :key #'(lambda (x) (car x)))) (setf counter 0) (dolist (run scoresTreatments) (dolist (values (cdr run)) (dolist (value values) (if (< counter (ceiling (* probBest testIterations))) (update (second value) (first value) *histBest*) (update (second value) (first value) *histRest*))) (incf counter))) (histTolike *histBest* (ceiling (* probBest testIterations)) probBest) (histTolike *histRest* (ceiling (* probRest testIterations)) probRest) (likeToRank *histBest* *histRest*) (setf rankedMembers (sortedParam *histBest*)) (setf rankedMembers (remove-if #'(lambda (x) (find x Completed)) rankedMembers :key #'car)) (let ((bin 0) (array (make-array bins))) (while (not (= (cdr (first rankedMembers)) (aref (dist9-distribution (gethash (car (first rankedMembers)) *histBest*)) bin))) (incf bin)) (push (car (pop rankedMembers)) Completed) (format t "Locks paramater: ~A into bin number: ~A increase?: ~A~%" (first Completed) bin allow) (format out2 "~A, ~A, ~A, ~A, ~A, ~A, ~A~%" type (first Completed) x bin (float (/ totalScore testIterations)) pAvgScore (if allow "include" "exclude")) (setf pAvgScore (float (/ totalScore testIterations))) (setf (aref array bin) 1) (setf (dist9-distribution (gethash (first Completed) *dists*)) array)))))) (restoreDists *dists*)) (let ((origdist (make-hash-table))) (defun restoreDists(dist) (copyDist dist origdist)) (defun storeDists (dist) (copyDist origdist dist)) (defun copyDist (to from) (maphash #'(lambda(k v) (setf (gethash k to) (make-dist9 :name (dist9-name v) :max (dist9-max v) :min (dist9-min v) :distribution (make-array (length (dist9-distribution v)) :initial-contents (coerce (dist9-distribution v) 'list))))) from))) ;Stores the resutl in the best (defun likeToRank (best rest) (maphash #'(lambda(k v) (setf (dist9-distribution v) (map 'vector #'(lambda (first second) (if (= first 0) 0 (/ (* first first) (+ first second)))) (dist9-distribution v) (dist9-distribution (gethash k rest))))) best)) (defun sortedParam (star1) (sort (mapcar #'(lambda (x) (cons (dist9-name x) (first (sort (coerce (dist9-distribution x) 'list) #'>)))) (ht2lst star1)) #'> :key #'cdr)) (defun histTolike (hist N prob) (maphash #'(lambda (k v) (setf (dist9-distribution v) (arrayMath (arrayMath (dist9-distribution v) N #'/) prob #'*))) hist)) ;Takes a historgram and changes it to normalized freq (defun arrayMath (array value func) (let ((size (length array)) (temparray)) (setf temparray (make-array size)) (dotimes (pos size temparray) (setf (aref temparray pos) (funcall func (aref array pos) value))))) (defun resetHists(size) (maphash #'(lambda (k v) (setf (gethash k *histBest*) (make-dist9 :name (dist9-name v) :max (dist9-max v) :min (dist9-min v) :distribution (make-array size)))) *dists*) (maphash #'(lambda (k v) (setf (gethash k *histRest*) (make-dist9 :name (dist9-name v) :max (dist9-max v) :min (dist9-min v) :distribution (make-array size)))) *dists*))