diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 6d93bd6..a905ae8 100644 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -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 diff --git a/src/propeller/selection.cljc b/src/propeller/selection.cljc index 68724df..e3b11c9 100644 --- a/src/propeller/selection.cljc +++ b/src/propeller/selection.cljc @@ -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)))))))