From b5763dcc5a11d175bb9194e6d7e1559aa37d1e95 Mon Sep 17 00:00:00 2001 From: Ryan Boldi Date: Tue, 7 Jun 2022 09:42:55 -0400 Subject: [PATCH] added boolean flag to not end runs on success --- src/propeller/gp.cljc | 26 +++++++++++++--------- src/propeller/problems/PSB2/fuel_cost.cljc | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 536f292..34eb740 100644 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -34,8 +34,11 @@ (defn gp "Main GP loop." [{:keys [population-size max-generations error-function instructions - max-initial-plushy-size solution-error-threshold mapper ds-parent-rate ds-parent-gens] + max-initial-plushy-size solution-error-threshold mapper ds-parent-rate ds-parent-gens dont-end] :or {solution-error-threshold 0.0 + dont-end false + ds-parent-rate 0 + ds-parent-gens 1 ;; The `mapper` will perform a `map`-like operation to apply a function to every individual ;; in the population. The default is `map` but other options include `mapv`, or `pmap`. mapper #?(:clj pmap :cljs map)} @@ -80,15 +83,18 @@ (prn {:semi-success-generation generation})) (cond ;; Success on training cases is verified on testing cases - (or (and best-individual-passes-ds (<= (:total-error (error-function argmap indexed-training-data best-individual)) solution-error-threshold)) - (and (not= (:parent-selection argmap) :ds-lexicase) - (<= (:total-error best-individual) solution-error-threshold))) - (do (prn {:success-generation generation}) - (prn {:total-test-error - (:total-error (error-function argmap (:testing-data argmap) best-individual))}) - (when (:simplification? argmap) - (let [simplified-plushy (simplification/auto-simplify-plushy (:plushy best-individual) error-function argmap)] - (prn {:total-test-error-simplified (:total-error (error-function argmap (:testing-data argmap) (hash-map :plushy simplified-plushy)))})))) + (if (or (and best-individual-passes-ds (<= (:total-error (error-function argmap indexed-training-data best-individual)) solution-error-threshold)) + (and (not= (:parent-selection argmap) :ds-lexicase) + (<= (:total-error best-individual) solution-error-threshold))) + (do (prn {:success-generation generation}) + (prn {:total-test-error + (:total-error (error-function argmap (:testing-data argmap) best-individual))}) + (when (:simplification? argmap) + (let [simplified-plushy (simplification/auto-simplify-plushy (:plushy best-individual) error-function argmap)] + (prn {:total-test-error-simplified (:total-error (error-function argmap (:testing-data argmap) (hash-map :plushy simplified-plushy)))}))) + (if dont-end false true)) + false) + nil ;; (>= generation max-generations) nil diff --git a/src/propeller/problems/PSB2/fuel_cost.cljc b/src/propeller/problems/PSB2/fuel_cost.cljc index e5e5fdd..071bf99 100644 --- a/src/propeller/problems/PSB2/fuel_cost.cljc +++ b/src/propeller/problems/PSB2/fuel_cost.cljc @@ -73,8 +73,8 @@ :training-data train-data :testing-data test-data :case-t-size (count train-data) - :case-parent-rate 0 - :case-parent-gens 1 + :ds-parent-rate 0 + :ds-parent-gens 1 :max-generations 300 :population-size 1000 :max-initial-plushy-size 250