Skip to content

Commit

Permalink
Added :proportionate option for :age-combining-function; lein release…
Browse files Browse the repository at this point in the history
… :minor
  • Loading branch information
lspector committed Mar 22, 2017
1 parent 68eb5c2 commit 13f6c9f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/clojush/pushgp/genetic_operators.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,24 @@
(inc (:age p2))))
:average (fn [p1 p2 g]
(average (inc (:age p1))
(inc (:age p2))))))
(inc (:age p2))))
:proportionate (fn [p1 p2 g]
(if (= (:age p1) (:age p2))
(inc (:age p1))
(if (= (:genome p1) (:genome p2))
(/ (+ (inc (:age p1)) (inc (:age p2))) 2)
(let [p1-dist (levenshtein-distance g (:genome p1))
p2-dist (levenshtein-distance g (:genome p2))]
(+ (inc (:age p1))
(* (/ p1-dist (+ p1-dist p2-dist))
(- (inc (:age p2))
(inc (:age p1)))))))))))

;; test effects of :proportionate with expressions like this:
;(float ((age-combining-function {:age-combining-function :proportionate})
; {:genome [1 2 3 4 5 6 7] :age 100}
; {:genome [1 2 3 4] :age 200}
; [1 2 3]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; reproduction
Expand Down Expand Up @@ -945,3 +962,4 @@ be set globally or eliminated in the future."
:is-random-replacement
(if use-child false true)))))


0 comments on commit 13f6c9f

Please sign in to comment.