Skip to content

Commit

Permalink
Added uniform-integer-mutation genetic operator and genome_uniform_in…
Browse files Browse the repository at this point in the history
…teger_motation instruction.
  • Loading branch information
lspector committed Oct 21, 2016
1 parent 46fc7e2 commit 0828ad2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/clojush/args.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
:alternation 0.7
:uniform-mutation 0.1
:uniform-instruction-mutation 0.0
:uniform-integer-mutation 0.0
; Similar to the old ULTRA operator:
[:alternation :uniform-mutation] 0.2
:uniform-close-mutation 0.0
Expand Down
20 changes: 20 additions & 0 deletions src/clojush/instructions/genome.clj
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,24 @@
{:genome genome}
(merge @push-argmap {:uniform-mutation-rate rate}))))
:genome)))
state)))

(define-registered
genome_uniform_integer_mutation
^{:stack-types [:genome :integer]}
(fn [state]
(if (and (not (empty? (rest (:integer state))))
(not (empty? (:genome state))))
(let [rate (+ 0.001 (* 0.001 (mod (first (:integer state)) 100)))
stdev (+ 1 (#(if (pos? %) % (- %)) (second (:integer state))))
genome (first (:genome state))]
(->> (pop-item :integer state)
(pop-item :integer)
(pop-item :genome)
(push-item (vec (:genome (uniform-integer-mutation
{:genome genome}
(merge @push-argmap
{:uniform-mutation-constant-tweak-rate rate
:uniform-mutation-int-gaussian-standard-deviation stdev}))))
:genome)))
state)))
38 changes: 33 additions & 5 deletions src/clojush/pushgp/genetic_operators.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
(assoc instr-map :instruction new-instr)))

(defn uniform-mutation
"Uniformly mutates individual. For each token in program, there is
"Uniformly mutates individual. For each token in the genome, there is
uniform-mutation-rate probability of being mutated. If a token is to be
mutated, it has a uniform-mutation-constant-tweak-rate probability of being
mutated using a constant mutator (which varies depending on the type of the
Expand Down Expand Up @@ -89,19 +89,47 @@
;; uniform instruction mutation

(defn uniform-instruction-mutation
"Uniformly mutates individual. For each token in program, there is
"Uniformly mutates individual. For each token in the genome, there is
uniform-mutation-rate probability of being mutated. If a token is to be
mutated it will be replaced with a random instruction."
[ind {:keys [uniform-mutation-rate maintain-ancestors atom-generators]
:as argmap}]
(let [instruction-mutator (fn [token]
(assoc token
:instruction
(:instruction (first (random-plush-genome 1 atom-generators argmap)))))
:instruction
(:instruction (first (random-plush-genome 1 atom-generators argmap)))))
token-mutator (fn [token]
(if (< (lrand) uniform-mutation-rate)
(instruction-mutator token))
token)
token)
new-genome (map token-mutator (:genome ind))]
(make-individual :genome new-genome
:history (:history ind)
:ancestors (if maintain-ancestors
(cons (:genome ind) (:ancestors ind))
(:ancestors ind)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; uniform integer mutation

(defn uniform-integer-mutation
"Uniformly mutates individual. For each integer in program, there is
uniform-mutation-rate probability of being mutated. If a token is to be
mutated it will be replaced with a random instruction."
[ind {:keys [uniform-mutation-constant-tweak-rate uniform-mutation-int-gaussian-standard-deviation
maintain-ancestors atom-generators]
:as argmap}]
(let [constant-mutator (fn [token]
(let [const (:instruction token)]
(if (integer? const)
(assoc token
:instruction
(round (perturb-with-gaussian-noise uniform-mutation-int-gaussian-standard-deviation const)))
token)))
token-mutator (fn [token]
(if (< (lrand) uniform-mutation-constant-tweak-rate)
(constant-mutator token))
token)
new-genome (map token-mutator (:genome ind))]
(make-individual :genome new-genome
:history (:history ind)
Expand Down

0 comments on commit 0828ad2

Please sign in to comment.