Only exchange in bmx with distance <= a limit, hardcoded to 4 for now
This commit is contained in:
parent
49f6f6de72
commit
a706babff1
@ -170,12 +170,23 @@ The function `new-individual` returns a new individual produced by selection and
|
|||||||
[plushy-a plushy-b rate]
|
[plushy-a plushy-b rate]
|
||||||
(let [a-genes (utils/extract-genes plushy-a)
|
(let [a-genes (utils/extract-genes plushy-a)
|
||||||
b-genes (utils/extract-genes plushy-b)]
|
b-genes (utils/extract-genes plushy-b)]
|
||||||
(flatten (interpose :gap
|
(flatten
|
||||||
(mapv (fn [g]
|
(interpose
|
||||||
(if (< (rand) rate)
|
:gap
|
||||||
(apply min-key #(metrics/unigram-bigram-distance g %) b-genes)
|
(mapv (fn [a-gene]
|
||||||
g))
|
(if (< (rand) rate)
|
||||||
a-genes)))))
|
(let [match-info (map (fn [b-gene]
|
||||||
|
{:distance (metrics/unigram-bigram-distance a-gene b-gene)
|
||||||
|
:gene b-gene})
|
||||||
|
b-genes)
|
||||||
|
candidates (filter (fn [info]
|
||||||
|
(<= (:distance info) 4))
|
||||||
|
match-info)]
|
||||||
|
(if (empty? candidates)
|
||||||
|
a-gene
|
||||||
|
(:gene (apply min-key :distance candidates))))
|
||||||
|
a-gene))
|
||||||
|
a-genes)))))
|
||||||
|
|
||||||
(defn new-individual
|
(defn new-individual
|
||||||
"Returns a new individual produced by selection and variation of
|
"Returns a new individual produced by selection and variation of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user