add get-brain-less-than to get a brain of a specific quality
This commit is contained in:
parent
0f3e55b472
commit
86f84db19a
1 changed files with 21 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
;;TODO: actually interesting brains, refactor, better children handling
|
||||
|
||||
(defmacro r
|
||||
[]
|
||||
'(use 'nn.core :reload)
|
||||
|
@ -33,7 +35,9 @@
|
|||
(defn min-key-seq
|
||||
"The minimum of a seq by key"
|
||||
[k seq]
|
||||
(apply min-key k seq))
|
||||
(if (empty? seq)
|
||||
nil
|
||||
(apply min-key k seq)))
|
||||
|
||||
(defn nn
|
||||
"Create a \"neural network\" from a brain, an activation function, and a variation function (that takes a number)"
|
||||
|
@ -247,6 +251,12 @@
|
|||
(map (partial score-with-evolver evolver))
|
||||
min-seq))
|
||||
|
||||
(defn best-brain
|
||||
"Get the best brain of an evolver"
|
||||
[evolver]
|
||||
(min-key-seq (partial score-with-evolver evolver)
|
||||
(:brains evolver)))
|
||||
|
||||
(defn worst-score
|
||||
"Get the best score of an evolver"
|
||||
[evolver]
|
||||
|
@ -265,3 +275,13 @@
|
|||
(map (comp str best-score)
|
||||
(take 1000 (evolution (n-multiplier-evolver n)))))
|
||||
"]"))
|
||||
|
||||
(defn get-brain-less-than
|
||||
"Evolve an evolver until it's best brain's score is less than the given value,
|
||||
then return the best brain"
|
||||
[n evolver]
|
||||
(->> evolver
|
||||
evolution
|
||||
(take-while #(> (best-score %) n))
|
||||
last
|
||||
best-brain))
|
||||
|
|
Loading…
Reference in a new issue