diff --git a/.DS_Store b/.DS_Store index 4c8696c..b9e3ed4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store index 0590414..da17f2d 100644 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/propeller/.DS_Store b/src/propeller/.DS_Store index a193822..306b0a3 100644 Binary files a/src/propeller/.DS_Store and b/src/propeller/.DS_Store differ diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 2a46aeb..0eb0426 100755 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -25,8 +25,12 @@ (println "Best behaviors:" (:behaviors best)) (println "Genotypic diversity:" (float (/ (count (distinct (map :plushy pop))) (count pop)))) + (println "Behavioral diversity:" + (float (/ (count (distinct (map :behaviors pop))) (count pop)))) (println "Average genome length:" (float (/ (reduce + (map count (map :plushy pop))) (count pop)))) + (println "Average total error:" + (float (/ (reduce + (map :total-error pop)) (count pop)))) (println))) (defn gp diff --git a/src/propeller/problems/valiant.cljc b/src/propeller/problems/valiant.cljc index c51e9a4..f51d8b2 100644 --- a/src/propeller/problems/valiant.cljc +++ b/src/propeller/problems/valiant.cljc @@ -3,8 +3,8 @@ [propeller.push.interpreter :as interpreter] [propeller.push.state :as state])) -(def num-vars 100) ;1000) -(def num-inputs 50) ;500) +(def num-vars 100) ;10) ;100) ;1000) +(def num-inputs 50) ;5) ; 50) ;500) (def num-train 500) ;5000) (def num-test 200) @@ -23,10 +23,11 @@ :outputs (map even-parity? test-inputs)}})) (def instructions - (vec (concat (for [i (range num-inputs)] (keyword (str "in" i))) + (vec (concat (for [i (range num-vars)] (keyword (str "in" i))) (take num-inputs (cycle [:boolean_xor :boolean_or + :boolean_and :boolean_not :exec_if 'close diff --git a/src/propeller/session.cljc b/src/propeller/session.cljc index fbca6ec..c9f9e22 100755 --- a/src/propeller/session.cljc +++ b/src/propeller/session.cljc @@ -5,7 +5,6 @@ [propeller.variation :as variation] [propeller.problems.simple-regression :as regression] [propeller.problems.string-classification :as string-classif] - propeller.problems.valiant [propeller.push.core :as push] [propeller.push.interpreter :as interpreter] [propeller.push.state :as state] @@ -154,76 +153,3 @@ ; } ; :elitism false ; :diploid true}) - - -;(gp/gp {:instructions propeller.problems.valiant/instructions -; :error-function propeller.problems.valiant/error-function -; :max-generations 500 -; :population-size 50 -; :max-initial-plushy-size 1000 -; :step-limit 2000 -; :parent-selection :tournament -; :tournament-size 10 -; :umad-rate 0.01 -; :diploid-flip-rate 0.01 -; :variation {:umad 0.9 -; :diploid-flip 0.1 -; } -; :elitism false -; :diploid true}) - -;(gp/gp {:instructions propeller.problems.valiant/instructions -; :error-function propeller.problems.valiant/error-function -; :max-generations 500 -; :population-size 100 -; :max-initial-plushy-size 1000 -; :step-limit 2000 -; :parent-selection :tournament -; :tournament-size 10 -; :umad-rate 0.01 -; :diploid-flip-rate 0.01 -; :variation {:umad 0.9 -; :diploid-flip 0.1 -; } -; :elitism false -; :diploid true}) - -;;; below is when I switched to just xor - -;(gp/gp {:instructions propeller.problems.valiant/instructions -; :error-function propeller.problems.valiant/error-function -; :max-generations 500 -; :population-size 500 -; :max-initial-plushy-size 50 -; :step-limit 2000 -; :parent-selection :lexicase -; :tournament-size 2 -; :umad-rate 0.01 -; :diploid-flip-rate 0.01 -; :variation {:umad 0.5 -; :crossover 0.25 -; :diploid-flip 0.25 -; } -; :elitism false -; :diploid true}) - -;; separated diploid from other operators - -(gp/gp {:instructions propeller.problems.valiant/instructions - :error-function propeller.problems.valiant/error-function - :max-generations 500 - :population-size 1000 - :max-initial-plushy-size 10 - :step-limit 1000 - :parent-selection :lexicase - :tournament-size 2 - :umad-rate 0.01 - :replacement-rate 0.01 - :diploid-flip-rate 0.01 - :variation {:diploid-umad 0.25 - :diploid-crossover 0.25 - :diploid-flip 0.25 - :uniform-replacement 0.25 - } - :elitism false - :diploid true}) diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index d35c452..19578eb 100755 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -16,6 +16,20 @@ shorter-padded longer)))) +(defn tail-aligned-crossover + "Crosses over two individuals using uniform crossover. Pads shorter one on the left." + [plushy-a plushy-b] + (let [shorter (min-key count plushy-a plushy-b) + longer (if (= shorter plushy-a) + plushy-b + plushy-a) + length-diff (- (count longer) (count shorter)) + shorter-padded (concat (repeat length-diff :crossover-padding) shorter)] + (remove #(= % :crossover-padding) + (map #(if (< (rand) 0.5) %1 %2) + shorter-padded + longer)))) + (defn diploid-crossover "Crosses over two individuals using uniform crossover. Pads shorter one." [plushy-a plushy-b] @@ -32,6 +46,22 @@ shorter-padded longer))))) +(defn tail-aligned-diploid-crossover + "Crosses over two individuals using uniform crossover. Pads shorter one on the left." + [plushy-a plushy-b] + (let [plushy-a (partition 2 plushy-a) + plushy-b (partition 2 plushy-b) + shorter (min-key count plushy-a plushy-b) + longer (if (= shorter plushy-a) + plushy-b + plushy-a) + length-diff (- (count longer) (count shorter)) + shorter-padded (concat (repeat length-diff :crossover-padding) shorter)] + (flatten (remove #(= % :crossover-padding) + (map #(if (< (rand) 0.5) %1 %2) + shorter-padded + longer))))) + (defn uniform-addition "Returns plushy with new instructions possibly added before or after each existing instruction." @@ -51,6 +81,16 @@ %) plushy)) +(defn diploid-uniform-silent-replacement + "Returns plushy with new instructions possibly replacing existing + instructions, but only among the silent member of each pair." + [plushy instructions replacement-rate] + (interleave (map first (partition 2 plushy)) + (map #(if (< (rand) replacement-rate) + (utils/random-instruction instructions) + %) + (map second (partition 2 plushy))))) + (defn diploid-uniform-addition "Returns plushy with new instructions possibly added before or after each existing instruction." @@ -105,6 +145,11 @@ (:plushy (selection/select-parent pop argmap)) (:plushy (selection/select-parent pop argmap))) ; + :tail-aligned-crossover + (tail-aligned-crossover + (:plushy (selection/select-parent pop argmap)) + (:plushy (selection/select-parent pop argmap))) + ; :umad (-> (:plushy (selection/select-parent pop argmap)) (uniform-addition (:instructions argmap) (:umad-rate argmap)) @@ -118,6 +163,10 @@ (-> (:plushy (selection/select-parent pop argmap)) (uniform-replacement (:instructions argmap) (:replacement-rate argmap))) ; + :diploid-uniform-silent-replacement + (-> (:plushy (selection/select-parent pop argmap)) + (diploid-uniform-silent-replacement (:instructions argmap) (:replacement-rate argmap))) + ; :uniform-deletion (-> (:plushy (selection/select-parent pop argmap)) (uniform-deletion (:umad-rate argmap))) @@ -127,6 +176,11 @@ (:plushy (selection/select-parent pop argmap)) (:plushy (selection/select-parent pop argmap))) ; + :tail-aligned-diploid-crossover + (tail-aligned-diploid-crossover + (:plushy (selection/select-parent pop argmap)) + (:plushy (selection/select-parent pop argmap))) + ; :diploid-umad (-> (:plushy (selection/select-parent pop argmap)) (diploid-uniform-addition (:instructions argmap) (:umad-rate argmap))