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]
(let [initial-cases (or (:initial-cases argmap)
(shuffle (range (count (:errors (first pop))))))]
(loop [survivors (map rand-nth (vals (group-by :errors pop))) (loop [survivors (map rand-nth (vals (group-by :errors pop)))
cases (shuffle (range (count (:errors (first pop)))))] cases initial-cases]
(if (or (empty? cases) (if (or (empty? cases)
(empty? (rest survivors))) (empty? (rest survivors)))
(rand-nth survivors) (assoc (rand-nth survivors) :selection-cases initial-cases)
(let [min-err-for-case (apply min (map #(nth % (first cases)) (let [min-err-for-case (apply min (map #(nth % (first cases))
(map :errors survivors)))] (map :errors survivors)))]
(recur (filter #(= (nth (:errors %) (first cases)) min-err-for-case) (recur (filter #(= (nth (:errors %) (first cases)) min-err-for-case)
survivors) survivors)
(rest cases)))))) (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."