option to sort by max rather than min
Some checks are pending
CI / test-clj (push) Waiting to run
CI / test-cljs (push) Waiting to run

This commit is contained in:
Rowan Torbitzky-Lane 2025-03-11 14:06:22 -05:00
parent 2261b57445
commit c107363d40
2 changed files with 7 additions and 5 deletions

View File

@ -92,6 +92,8 @@
:training-data [] ; must be provided
:umad-rate 0.1 ; addition rate (from which deletion rate will be derived) for UMAD
:variation {:umad 1} ; genetic operators and probabilities for their use, which should sum to 1
:tournament-comp-op min-key ; individual error comparison operator for tournament selection
:lexicase-comp-op min ; individual error comparison operator for lexicase selection
}
defaulted (merge defaults argmap)]
(merge defaulted ; use the map below to include derived values in argmap

View File

@ -11,7 +11,7 @@
[pop argmap]
(let [tournament-size (:tournament-size argmap)
tournament-set (take tournament-size (shuffle pop))]
(apply min-key :total-error tournament-set)))
(apply (:tournament-comp-op argmap) :total-error tournament-set)))
(defn lexicase-selection
"Selects an individual from the population using lexicase selection.
@ -26,9 +26,9 @@
(if (or (empty? cases)
(empty? (rest survivors)))
(assoc (rand-nth survivors) :selection-cases initial-cases)
(let [min-err-for-case (apply min (map #(nth % (first cases))
(let [err-for-case (apply (:lexicase-comp-op argmap) (map #(nth % (first cases))
(map :errors survivors)))]
(recur (filter #(= (nth (:errors %) (first cases)) min-err-for-case)
(recur (filter #(= (nth (:errors %) (first cases)) err-for-case)
survivors)
(rest cases)))))))
@ -94,12 +94,12 @@
(if (or (empty? cases)
(empty? (rest survivors)))
(rand-nth survivors)
(let [min-err-for-case (apply min (map #(nth % (first cases))
(let [err-for-case (apply (:lexicase-comp-op argmap) (map #(nth % (first cases))
(map :errors survivors)))
epsilon (nth epsilons (first cases))]
(recur (filter #(<= (Math/abs (- (nth (:errors %)
(first cases))
min-err-for-case))
err-for-case))
epsilon)
survivors)
(rest cases)))))))