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