From 816b443658845b97147b841f41950c39f19d256f Mon Sep 17 00:00:00 2001 From: Ryan Boldi Date: Wed, 13 Apr 2022 22:54:33 -0400 Subject: [PATCH] retested max-min, and added some new logging to judge case proportions --- src/propeller/downsample.cljc | 1 + src/propeller/gp.cljc | 5 ++--- src/propeller/problems/simple_classification.cljc | 5 ++++- src/propeller/utils.cljc | 3 +-- test/propeller/utils_test.cljc | 12 +++++++++++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/propeller/downsample.cljc b/src/propeller/downsample.cljc index 283761f..52897e3 100644 --- a/src/propeller/downsample.cljc +++ b/src/propeller/downsample.cljc @@ -58,6 +58,7 @@ (utils/filter-by-index distance-list (map #(:index %) tournament))) (map #(:distances %) new-downsample))) selected-case-index (metrics/argmax min-case-distances)] + (prn {:cases-in-ds (map #(first (:input1 %)) new-downsample) :cases-in-tourn (map #(first (:input1 %)) tournament)}) (prn {:min-case-distances min-case-distances :selected-case-index selected-case-index}) (recur (conj new-downsample (nth tournament selected-case-index)) (shuffle (concat (utils/drop-nth selected-case-index tournament) diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index f76c9d6..89b24eb 100644 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -48,8 +48,7 @@ (fn [_] {:plushy (genome/make-random-plushy instructions max-initial-plushy-size)}) (range population-size)) indexed-training-data (downsample/assign-indices-to-data (downsample/initialize-case-distances argmap))] - ;;TODO: REMOVE THIS IT IS JUST FOR TESTING - (prn {:data (some #(when (zero? (:index %)) %) indexed-training-data)}) + (prn {:first-data (some #(when (zero? (:index %)) %) indexed-training-data)}) (let [training-data (if (= (:parent-selection argmap) :ds-lexicase) (case (:ds-function argmap) :case-avg (downsample/select-downsample-avg indexed-training-data argmap) @@ -68,7 +67,7 @@ best-individual-passes-ds (and (= (:parent-selection argmap) :ds-lexicase) (<= (:total-error best-individual) solution-error-threshold)) ;;best individual on all training-cases tot-best-individual (if best-individual-passes-ds (first full-evaluated-pop) best-individual)] - (prn (first training-data)) + (prn {:ds-inputs (map #(first (:input1 %)) training-data)}) (if (:custom-report argmap) ((:custom-report argmap) ds-evaluated-pop generation argmap) (report ds-evaluated-pop generation argmap)) diff --git a/src/propeller/problems/simple_classification.cljc b/src/propeller/problems/simple_classification.cljc index 1bd2878..ac575e5 100644 --- a/src/propeller/problems/simple_classification.cljc +++ b/src/propeller/problems/simple_classification.cljc @@ -23,9 +23,12 @@ :boolean_invert_first_then_and :boolean_invert_second_then_and :boolean_from_integer + true + false 'close 0 - 1)) + 1 + 3)) (defn- target-function "If number is divisible by 3 but not 7, leave TRUE on the BOOLEAN stack else leave FALSE on the BOOLEAN stack" diff --git a/src/propeller/utils.cljc b/src/propeller/utils.cljc index c1332f5..2755eff 100755 --- a/src/propeller/utils.cljc +++ b/src/propeller/utils.cljc @@ -5,8 +5,7 @@ "filters a collection by a list of indices" [coll idxs] ;(prn {:func :filter-by-index :coll coll :idxs idxs}) - (keep-indexed #(when ((set idxs) %1) %2) - coll)) + (map (partial nth coll) idxs)) (defn drop-nth "drops the nth element from a collection" diff --git a/test/propeller/utils_test.cljc b/test/propeller/utils_test.cljc index 9029b05..0555c2f 100644 --- a/test/propeller/utils_test.cljc +++ b/test/propeller/utils_test.cljc @@ -155,4 +155,14 @@ '({:index 3 :distances [2 2 2 2 2]} {:index 4 :distances [2 2 2 2 2]}) '({:index 0 :distances [2 2 2 2 2]} {:index 1 :distances [2 2 2 2 2]} {:index 2 :distances [2 2 2 2 2]} {:index 3 :distances [2 2 2 2 2]} {:index 4 :distances [2 2 2 2 2]})) '({:index 0 :distances [2 2 2 2 2]} {:index 1 :distances [2 2 2 2 2]} {:index 2 :distances [2 2 2 2 2]} - {:index 3 :distances [2 2 2 0 0]} {:index 4 :distances [2 2 2 0 0]})))))) \ No newline at end of file + {:index 3 :distances [2 2 2 0 0]} {:index 4 :distances [2 2 2 0 0]})))))) + +(t/deftest case-maxmin-test + (t/testing "case-maxmin selects correct downsample" + (t/is (let [selected (ds/select-downsample-maxmin '({:input1 [0] :output1 [10] :index 0 :distances [0 5 0 0 0]} + {:input1 [1] :output1 [11] :index 1 :distances [0 5 0 0 0]} + {:input1 [2] :output1 [12] :index 2 :distances [5 5 5 5 5]} + {:input1 [3] :output1 [13] :index 3 :distances [0 5 0 0 0]} + {:input1 [4] :output1 [14] :index 4 :distances [0 5 0 0 0]}) + {:downsample-rate 0.4 :case-t-size 5})] + (or (= (:index (first selected)) 1) (= (:index (second selected)) 1)))))) \ No newline at end of file