Print behavioral diversity and avg total error; add tail-aligned crossover and diploid operators; fix valiant problem
This commit is contained in:
parent
2f4adfde7a
commit
864c8fb8ee
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
BIN
src/propeller/.DS_Store
vendored
BIN
src/propeller/.DS_Store
vendored
Binary file not shown.
@ -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
|
||||
|
@ -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
|
||||
|
@ -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})
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user