Make lexicase-selection use provided :initial-cases and return :selection-cases, both via argmap

This commit is contained in:
Lee Spector 2023-12-02 17:35:14 -05:00
parent d0d0427dcf
commit 30a87a2688

View File

@ -19,16 +19,18 @@
eliminating any individuals with errors for the current case that are worse than the best error in the selection pool, eliminating any individuals with errors for the current case that are worse than the best error in the selection pool,
until a single individual remains." until a single individual remains."
[pop argmap] [pop argmap]
(loop [survivors (map rand-nth (vals (group-by :errors pop))) (let [initial-cases (or (:initial-cases argmap)
cases (shuffle (range (count (:errors (first pop)))))] (shuffle (range (count (:errors (first pop))))))]
(if (or (empty? cases) (loop [survivors (map rand-nth (vals (group-by :errors pop)))
(empty? (rest survivors))) cases initial-cases]
(rand-nth survivors) (if (or (empty? cases)
(let [min-err-for-case (apply min (map #(nth % (first cases)) (empty? (rest survivors)))
(map :errors survivors)))] (assoc (rand-nth survivors) :selection-cases initial-cases)
(recur (filter #(= (nth (:errors %) (first cases)) min-err-for-case) (let [min-err-for-case (apply min (map #(nth % (first cases))
survivors) (map :errors survivors)))]
(rest cases)))))) (recur (filter #(= (nth (:errors %) (first cases)) min-err-for-case)
survivors)
(rest cases)))))))
(defn fitness-proportionate-selection (defn fitness-proportionate-selection
"Selects an individual from the population using a fitness proportionate selection." "Selects an individual from the population using a fitness proportionate selection."