Make crossover, uniform-addition, and uniform-deletion take argmap arguments
This commit is contained in:
parent
aadc28d371
commit
55644a9b6d
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@ pom.xml.asc
|
|||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
out
|
out
|
||||||
|
notes
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
(defn crossover
|
(defn crossover
|
||||||
"Crosses over two individuals using uniform crossover. Pads shorter one."
|
"Crosses over two individuals using uniform crossover. Pads shorter one."
|
||||||
[plushy-a plushy-b]
|
[plushy-a plushy-b argmap]
|
||||||
(let [shorter (min-key count plushy-a plushy-b)
|
(let [shorter (min-key count plushy-a plushy-b)
|
||||||
longer (if (= shorter plushy-a)
|
longer (if (= shorter plushy-a)
|
||||||
plushy-b
|
plushy-b
|
||||||
@ -19,7 +19,7 @@
|
|||||||
(defn uniform-addition
|
(defn uniform-addition
|
||||||
"Returns plushy with new instructions possibly added before or after each
|
"Returns plushy with new instructions possibly added before or after each
|
||||||
existing instruction."
|
existing instruction."
|
||||||
[plushy instructions umad-rate]
|
[plushy instructions umad-rate argmap]
|
||||||
(apply concat
|
(apply concat
|
||||||
(map #(if (< (rand) umad-rate)
|
(map #(if (< (rand) umad-rate)
|
||||||
(shuffle [% (utils/random-instruction instructions)])
|
(shuffle [% (utils/random-instruction instructions)])
|
||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
(defn uniform-deletion
|
(defn uniform-deletion
|
||||||
"Randomly deletes instructions from plushy at some rate."
|
"Randomly deletes instructions from plushy at some rate."
|
||||||
[plushy umad-rate]
|
[plushy umad-rate argmap]
|
||||||
(remove (fn [_] (< (rand)
|
(remove (fn [_] (< (rand)
|
||||||
(/ 1 (+ 1 (/ 1 umad-rate)))))
|
(/ 1 (+ 1 (/ 1 umad-rate)))))
|
||||||
plushy))
|
plushy))
|
||||||
@ -42,11 +42,14 @@
|
|||||||
(cond
|
(cond
|
||||||
(< prob (:crossover (:variation argmap)))
|
(< prob (:crossover (:variation argmap)))
|
||||||
(crossover (:plushy (selection/select-parent pop argmap))
|
(crossover (:plushy (selection/select-parent pop argmap))
|
||||||
(:plushy (selection/select-parent pop argmap)))
|
(:plushy (selection/select-parent pop argmap))
|
||||||
|
argmap)
|
||||||
(< prob (+ (:crossover (:variation argmap))
|
(< prob (+ (:crossover (:variation argmap))
|
||||||
(:umad (:variation argmap))))
|
(:umad (:variation argmap))))
|
||||||
(uniform-deletion (uniform-addition (:plushy (selection/select-parent pop argmap))
|
(uniform-deletion (uniform-addition (:plushy (selection/select-parent pop argmap))
|
||||||
(:instructions argmap)
|
(:instructions argmap)
|
||||||
(:umad-rate argmap))
|
(:umad-rate argmap)
|
||||||
(/ 1 (+ (/ 1 (:umad-rate argmap)) 1)))
|
argmap)
|
||||||
|
(/ 1 (+ (/ 1 (:umad-rate argmap)) 1))
|
||||||
|
argmap)
|
||||||
:else (:plushy (selection/select-parent pop argmap))))})
|
:else (:plushy (selection/select-parent pop argmap))))})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user