simplified simplification.cljc

This commit is contained in:
Ryan Boldi 2022-01-13 20:31:17 -05:00
parent e25dab4798
commit f369d23ad5

View File

@ -20,18 +20,15 @@
(delete-at-indices (choose-random-k k (range (count plushy))) plushy))
(defn auto-simplify-plushy
"naive auto-simplification with simple k annealing"
[argmap plushy steps error-function training-data start-k decrease-k-on-failure-prob verbose?]
(if verbose? (prn "Starting Auto-Simplification" {:current-plushy-length (count plushy) :k start-k :decrease-k-on-failure-prob decrease-k-on-failure-prob}))
"naive auto-simplification"
[argmap plushy steps error-function training-data k verbose?]
(if verbose? (prn {:start-plushy-length (count plushy) :k k}))
(let [initial-errors (:errors (error-function argmap training-data {:plushy plushy}))]
(loop [step 0 curr-plushy plushy k start-k]
(if (and verbose? (= (mod step 50) 0)) (pr {:step step :k k} " "))
(loop [step 0 curr-plushy plushy]
(if (< steps step)
(do (if verbose? (prn "Finished Auto-Simplification" {:final-plushy-length (count curr-plushy) :final-plushy curr-plushy})) curr-plushy)
(let [new-plushy (delete-k-random k curr-plushy)
(do (if verbose? (prn {:final-plushy-length (count curr-plushy) :final-plushy curr-plushy})) curr-plushy)
(let [new-plushy (delete-k-random (rand-int k) curr-plushy)
new-plushy-errors (:errors (error-function argmap training-data {:plushy new-plushy}))
new-equal? (= new-plushy-errors initial-errors)]
(print-str new-plushy new-plushy-errors new-equal?)
(recur (inc step)
(if new-equal? new-plushy curr-plushy)
(if new-equal? k (if (and (> k 1) (< (rand) decrease-k-on-failure-prob)) (dec k) k))))))))
(if new-equal? new-plushy curr-plushy)))))))