Merge edited version of Mahran-Yousef:master pull request
This commit is contained in:
commit
c6f9b58556
@ -5,8 +5,8 @@
|
||||
<output-test url="file://$MODULE_DIR$/target/classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
|
||||
<sourceFolder url="file://C:\Users\user\Documents\GitHub\propeller\dev-resources" isTestSource="false" />
|
||||
<sourceFolder url="file://C:\Users\user\Documents\GitHub\propeller\resources" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
|
@ -9,11 +9,14 @@
|
||||
(gp (update-in (merge {:instructions default-instructions
|
||||
:error-function regression-error-function
|
||||
:max-generations 500
|
||||
:population-size 200
|
||||
:population-size 500
|
||||
:max-initial-plushy-size 50
|
||||
:step-limit 100
|
||||
:parent-selection :tournament
|
||||
:tournament-size 5}
|
||||
:parent-selection :lexicase
|
||||
:tournament-size 5
|
||||
:UMADRate 0.1
|
||||
:variation {:UMAD 0.5 :crossover 0.5}
|
||||
:elitism false}
|
||||
(apply hash-map
|
||||
(map read-string args)))
|
||||
[:error-function]
|
||||
|
@ -38,5 +38,9 @@
|
||||
(zero? (:total-error (first evaluated-pop))) (println "SUCCESS")
|
||||
(>= generation max-generations) nil
|
||||
:else (recur (inc generation)
|
||||
(if (:elitism argmap)
|
||||
(conj (repeatedly (dec population-size)
|
||||
#(new-individual evaluated-pop argmap))
|
||||
(first evaluated-pop))
|
||||
(repeatedly population-size
|
||||
#(new-individual evaluated-pop argmap)))))))
|
||||
#(new-individual evaluated-pop argmap))))))))
|
||||
|
@ -16,22 +16,19 @@
|
||||
longer))))
|
||||
|
||||
(defn uniform-addition
|
||||
"Randomly adds new instructions before every instruction (and at the end of
|
||||
the plushy) with some probability."
|
||||
[plushy instructions]
|
||||
(let [rand-code (repeatedly (inc (count plushy))
|
||||
(fn []
|
||||
(if (< (rand) 0.05)
|
||||
(rand-nth instructions)
|
||||
:mutation-padding)))]
|
||||
(remove #(= % :mutation-padding)
|
||||
(interleave (conj plushy :mutation-padding)
|
||||
rand-code))))
|
||||
"Returns plushy with new instructions possibly added before or after each existing instruction."
|
||||
[plushy instructions UMADRate]
|
||||
(apply concat
|
||||
(map #(if (< (rand) UMADRate)
|
||||
(shuffle [% (rand-nth instructions)])
|
||||
[%])
|
||||
plushy)))
|
||||
|
||||
(defn uniform-deletion
|
||||
"Randomly deletes instructions from plushy at some rate."
|
||||
[plushy]
|
||||
(remove (fn [x] (< (rand) 0.05))
|
||||
[plushy UMADRate]
|
||||
(remove (fn [_] (< (rand)
|
||||
(/ 1 (+ 1 (/ 1 UMADRate)))))
|
||||
plushy))
|
||||
|
||||
(defn new-individual
|
||||
@ -41,8 +38,13 @@
|
||||
{:plushy
|
||||
(let [prob (rand)]
|
||||
(cond
|
||||
(< prob 0.5) (crossover (:plushy (select-parent pop argmap))
|
||||
(< prob (:crossover (:variation argmap)))
|
||||
(crossover (:plushy (select-parent pop argmap))
|
||||
(:plushy (select-parent pop argmap)))
|
||||
(< prob 0.75) (uniform-addition (:plushy (select-parent pop argmap))
|
||||
(:instructions argmap))
|
||||
:else (uniform-deletion (:plushy (select-parent pop argmap)))))})
|
||||
(< prob (+ (:crossover (:variation argmap))
|
||||
(:UMAD (:variation argmap)) 2))
|
||||
(uniform-deletion (uniform-addition (:plushy (select-parent pop argmap))
|
||||
(:instructions argmap)
|
||||
(:UMADRate argmap))
|
||||
(:UMADRate argmap))
|
||||
:else (:plushy (select-parent pop argmap))))})
|
Loading…
x
Reference in New Issue
Block a user