Switch to normalized autoconstructive hypervariation; reformat
This commit is contained in:
parent
adf039195c
commit
37df3432fb
@ -23,7 +23,7 @@
|
||||
[evaluations pop generation argmap training-data]
|
||||
(let [best (first pop)]
|
||||
(clojure.pprint/pprint
|
||||
(merge {:generation generation
|
||||
{:generation generation
|
||||
:best-plushy (:plushy best)
|
||||
:best-program (genome/plushy->push (:plushy best) argmap)
|
||||
:best-total-error (:total-error best)
|
||||
@ -34,18 +34,7 @@
|
||||
:genotypic-diversity (float (/ (count (distinct (map :plushy pop))) (count pop)))
|
||||
:behavioral-diversity (float (/ (count (distinct (map :behaviors pop))) (count pop)))
|
||||
:average-genome-length (float (/ (reduce + (map count (map :plushy pop))) (count pop)))
|
||||
:average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))}
|
||||
(if (> (or (:ah-umad (:variation argmap)) 0) 0) ;; using autoconstructive hypervariability
|
||||
{:average-hypervariability
|
||||
(let [variabilities (map (fn [i]
|
||||
(let [p (:plushy i)]
|
||||
(if (empty? p)
|
||||
0
|
||||
(/ (reduce + (variation/ah-rates p 0 1))
|
||||
(count p)))))
|
||||
pop)]
|
||||
(float (/ (reduce + variabilities) (count variabilities))))}
|
||||
{})))
|
||||
:average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))})
|
||||
(println)))
|
||||
|
||||
(defn gp
|
||||
|
@ -303,21 +303,20 @@
|
||||
:training-data (:train train-and-test-data)
|
||||
:testing-data (:test train-and-test-data)
|
||||
:max-generations 1000
|
||||
:population-size 100
|
||||
:population-size 1000
|
||||
:max-initial-plushy-size 100
|
||||
:step-limit 1000
|
||||
:step-limit 10000
|
||||
:parent-selection :lexicase
|
||||
:downsample? true
|
||||
:ds-function :case-rand
|
||||
:downsample-rate 0.1
|
||||
:downsample-rate 0.5
|
||||
;:parent-selection :tournament
|
||||
;:parent-selection :motley-batch-lexicase
|
||||
;:max-batch-size [1 2 4 8 16 32 64 128 256]
|
||||
;:tournament-size 5
|
||||
;:umad-rate 0.09
|
||||
:ah-umad-protect-rate 0.001 ;; ah-umad
|
||||
:ah-umad-vary-rate 0.1 ;; ah-umad
|
||||
:ah-umad-tournament-size 1 ;; ah-umad
|
||||
:ah-umad-protection 10 ;; ah-umad
|
||||
:ah-umad-rate 0.1 ;; ah-umad
|
||||
;:umad-rate [1/2
|
||||
; 1/4 1/4
|
||||
; 1/8 1/8 1/8
|
||||
|
@ -202,16 +202,24 @@ The function `new-individual` returns a new individual produced by selection and
|
||||
%)
|
||||
(partition 2 plushy))))
|
||||
|
||||
(defn with-mean
|
||||
"Returns numeric vector v scaled so that the mean value is m"
|
||||
[m v]
|
||||
(if (empty? v)
|
||||
v
|
||||
(let [initial-mean (/ (reduce + v) (count v))]
|
||||
(map #(* m (/ % initial-mean)) v))))
|
||||
|
||||
(defn ah-rates
|
||||
"Returns the sequence of rates with which each element of plushy should
|
||||
be mutated when using autoconstructive hypervariability."
|
||||
[plushy protect-rate hypervariable-rate]
|
||||
[plushy protection rate]
|
||||
(loop [i 0
|
||||
protected true
|
||||
rates []
|
||||
remainder plushy]
|
||||
(if (empty? remainder)
|
||||
rates
|
||||
(with-mean rate rates)
|
||||
(if (and (not protected)
|
||||
(= (first remainder) :protect))
|
||||
(recur i
|
||||
@ -222,33 +230,33 @@ The function `new-individual` returns a new individual produced by selection and
|
||||
(if protected
|
||||
(not= (first remainder) :vary)
|
||||
false)
|
||||
(conj rates (if protected protect-rate hypervariable-rate))
|
||||
(conj rates (if protected (/ 1 protection) 1))
|
||||
(rest remainder))))))
|
||||
|
||||
(defn ah-uniform-addition
|
||||
"Returns plushy with new instructions possibly added before or after each
|
||||
existing instruction. Rates are autoconstructively hypervariable."
|
||||
[plushy instructions protect-rate hypervariable-rate]
|
||||
[plushy instructions protection rate]
|
||||
(apply concat
|
||||
(map #(if (< (rand) %2)
|
||||
(mapv #(if (< (rand) %2)
|
||||
(shuffle [%1 (utils/random-instruction instructions)])
|
||||
[%1])
|
||||
plushy
|
||||
(ah-rates plushy protect-rate hypervariable-rate))))
|
||||
(ah-rates plushy protection rate))))
|
||||
|
||||
(defn ah-uniform-deletion
|
||||
"Randomly deletes instructions from plushy at some rate.
|
||||
Rates are autoconstructively hypervariable."
|
||||
[plushy protect-rate hypervariable-rate]
|
||||
(map first
|
||||
[plushy protection rate]
|
||||
(mapv first
|
||||
(remove (fn [[_ rate]]
|
||||
(< (rand)
|
||||
(if (zero? rate)
|
||||
0
|
||||
(/ 1 (+ 1 (/ 1 rate))))))
|
||||
(map vector
|
||||
(mapv vector
|
||||
plushy
|
||||
(ah-rates plushy protect-rate hypervariable-rate)))))
|
||||
(ah-rates plushy protection rate)))))
|
||||
|
||||
(defn new-individual
|
||||
"Returns a new individual produced by selection and variation of
|
||||
@ -305,17 +313,12 @@ The function `new-individual` returns a new individual produced by selection and
|
||||
(uniform-deletion rate)))
|
||||
;
|
||||
:ah-umad ;; autoconstructive hypervariability UMAD
|
||||
(let [protect-rate (utils/onenum (:ah-umad-protect-rate argmap))
|
||||
vary-rate (utils/onenum (:ah-umad-vary-rate argmap))
|
||||
tourn-size (utils/onenum (:ah-umad-tournament-size argmap))
|
||||
parent-genome (:plushy (selection/select-parent pop argmap))
|
||||
offspring (repeatedly
|
||||
tourn-size
|
||||
#(-> parent-genome
|
||||
(ah-uniform-addition (:instructions argmap) protect-rate vary-rate)
|
||||
(ah-uniform-deletion protect-rate vary-rate)))
|
||||
hypervariabilities (map #(reduce + (ah-rates % 0 1)) offspring)]
|
||||
(second (last (sort-by first (map vector hypervariabilities offspring)))))
|
||||
(let [protection (utils/onenum (:ah-umad-protection argmap))
|
||||
rate (utils/onenum (:ah-umad-rate argmap))
|
||||
parent-genome (:plushy (selection/select-parent pop argmap))]
|
||||
(-> parent-genome
|
||||
(ah-uniform-addition (:instructions argmap) protection rate)
|
||||
(ah-uniform-deletion protection rate)))
|
||||
;
|
||||
:uniform-addition
|
||||
(-> (:plushy (selection/select-parent pop argmap))
|
||||
|
Loading…
x
Reference in New Issue
Block a user