Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detailed gene tracking #224

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
015d591
Add random-insertion flag to random-plush-instruction-map
Jul 25, 2016
4d959da
Add random-insertion flag to random-plush-genome-with-size
Jul 25, 2016
6b1abc0
Add random-insertion flag to random-plush-genome
Jul 25, 2016
7ef6e4e
Update call to random-plush-instruction-map in genome_gene_randomize
Jul 25, 2016
85e841d
Update call to random-plush-genome in revert-too-big-child
Jul 25, 2016
f3a1b6a
Update call to random-plush-genome in autoconstruction
Jul 26, 2016
a9c1d4e
Refactor random-plush-instruction-map
Jul 26, 2016
2b2eb81
Add UUIDs to instruction maps
Jul 26, 2016
bfd6095
Add function for updating UUIDs on instruction maps
Jul 26, 2016
8240edd
Add conditional-thread function
Jul 30, 2016
e7d5bad
Remove old commented-out code
lverns Sep 4, 2016
877664b
Fix incorrect comments on conditional-thread
lverns Sep 4, 2016
ee8d385
Refactor conditional-thread
lverns Sep 4, 2016
3b27a32
Add :track-instruction-maps option to argmap
lverns Sep 4, 2016
aef2e12
Make random-plush-instruction-map obey new flag
lverns Sep 4, 2016
44382cd
Fix bug in perform-genetic-operators
lverns Sep 4, 2016
3dae842
Call update-instruction-map-uuids in perform-genetic-operators
lverns Sep 4, 2016
4725570
Pull all the genome printing to a single function
lverns Sep 4, 2016
6f655e1
Hide :uuid and :parent-uuid in standard reports
lverns Sep 4, 2016
6c39e93
Merge branch 'feature/detailed-gene-tracing-rebased' into conflict-re…
Sep 9, 2016
4ee8e53
Change update-instruction-map-uuids to use vectors
Sep 9, 2016
9825bd9
Merge branch 'master' into conflict-resolution/detailed-gene-tracing-…
Sep 17, 2016
ceb92cf
Replace conditional-thread with cond->
Oct 8, 2016
9aed373
Undo whitespace changes
Oct 10, 2016
c6d7d25
Merge branch 'master' into conflict-resolution/detailed-gene-tracing-…
Oct 29, 2016
0e84cd2
Remove remove-insertion flag from random-plush-instruction-map
Oct 29, 2016
005b9cb
Remove random-instruction flag from random-plush-genome-with-size
Oct 29, 2016
38a2fee
Remove random-insertion flag from random-plush-genome
Oct 29, 2016
364657a
Update calls to random-plush-genome
Oct 29, 2016
0906cff
Update calls to random-plush-instruction-map
Oct 29, 2016
0ad8af9
Merge branch 'master' into conflict-resolution/detailed-gene-tracing-…
Nov 1, 2016
a751165
Fix typo in a docstring
Nov 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/clojush/args.clj
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
;; If :silent is used as an epigenetic-marker, this is the probability of random
;; instructions having :silent be true.

:track-instruction-maps false
;; If true, each Plush instruction map will have a UUID attached to it. If the
;; gene has a "parent gene", it will also have the UUID of its parent.

;;----------------------------------------
;; Arguments related to parent selection
;;----------------------------------------
Expand Down
32 changes: 25 additions & 7 deletions src/clojush/pushgp/breed.clj
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,41 @@
rand-gen
argmap))))

(defn update-instruction-map-uuids
"Takes an individual and updates the UUIDs on every instruction-map in its
:genome, except for the ones which are a random insertion."
[individual]
(update individual :genome
(fn [genome]
(mapv (fn [instruction-map]
(if (:random-insertion instruction-map)
(dissoc instruction-map :random-insertion)
(assoc instruction-map
:parent-uuid (:uuid instruction-map)
:uuid (java.util.UUID/randomUUID))))
genome))))

(defn perform-genetic-operator
"Takes a single genetic operator keyword or a sequence of operator keywords,
and performs them to create a new individual. Uses recursive helper function
even with a single operator by putting that operator in a vector."
[operator population location rand-gen
{:keys [max-points] :as argmap}]
{:keys [max-points
track-instruction-maps] :as argmap}]
(let [first-parent (select population location argmap)
operator-vector (if (sequential? operator) operator (vector operator))
child (perform-genetic-operator-list operator-vector
(assoc first-parent :parent-uuids (vector (:uuid first-parent)))
population location rand-gen argmap)]
(if (> (count (:genome child))
(/ max-points 4)) ; Check if too big
(revert-too-big-child first-parent child argmap)
(assoc child
:genetic-operators operator
))))
(cond->
(assoc child :genetic-operators operator)

(> (count (:genome child))
(/ max-points 4))
(as-> c (revert-too-big-child first-parent c argmap))

track-instruction-maps
(update-instruction-map-uuids))))

(defn breed
"Returns an individual bred from the given population using the given parameters."
Expand Down
14 changes: 12 additions & 2 deletions src/clojush/pushgp/pushgp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
(repl/pst except 10000)
(System/exit 0))

(defn strip-random-insertion-flags
"The :random-insertion flag is added to all elements of the
genome when generated. It is used to signal that an
instruction-map was generated randomly in the run (as opposed
to being mutated from a parent). The individuals in generation
0 are a special case and should not have this flag present."
[genome]
(map #(dissoc % :random-insertion) genome))

(defn make-pop-agents
"Makes the population of agents containing the initial random individuals in the population.
Argument is a push argmap"
Expand All @@ -27,9 +36,10 @@
:as argmap}]
(let [population-agents (repeatedly population-size
#(make-individual
:genome (random-plush-genome max-genome-size-in-initial-program
:genome (strip-random-insertion-flags
(random-plush-genome max-genome-size-in-initial-program
atom-generators
argmap)
argmap))
:genetic-operators :random))]
(mapv #(if use-single-thread
(atom %)
Expand Down
11 changes: 7 additions & 4 deletions src/clojush/pushgp/report.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
(println (name param) "=" (random/seed-to-string val))
(println (name param) "=" val))))

(defn print-genome [individual]
(pr-str (not-lazy (map #(dissoc % :uuid :parent-uuid) (:genome individual)))))

(defn behavioral-diversity
"Returns the behavioral diversity of the population, as described by David
Jackson in 'Promoting phenotypic diversity in genetic programming'. It is
Expand Down Expand Up @@ -199,7 +202,7 @@
count-zero-by-case (map #(apply + %) (apply mapv vector pop-zero-by-case))]

(println "--- Lexicse Program with Most Elite Cases Statistics ---")
(println "Lexicase best genome:" (pr-str (not-lazy (:genome lex-best))))
(println "Lexicase best genome:" (print-genome lex-best))
(println "Lexicase best program:" (pr-str (not-lazy (:program lex-best))))
(when (> report-simplifications 0)
(println "Lexicase best partial simplification:"
Expand All @@ -217,7 +220,7 @@
(println "Lexicase best size:" (count-points (:program lex-best)))
(printf "Percent parens: %.3f\n" (double (/ (count-parens (:program lex-best)) (count-points (:program lex-best))))) ;Number of (open) parens / points
(println "--- Lexicse Program with Most Zero Cases Statistics ---")
(println "Zero cases best genome:" (pr-str (not-lazy (:genome most-zero-cases-best))))
(println "Zero cases best genome:" (print-genome most-zero-cases-best))
(println "Zero cases best program:" (pr-str (not-lazy (:program most-zero-cases-best))))
(when (> report-simplifications 0)
(println "Zero cases best partial simplification:"
Expand Down Expand Up @@ -248,7 +251,7 @@
[population {:keys [print-errors meta-error-categories]}]
(let [ifs-best (apply min-key :weighted-error population)]
(println "--- Program with Best Implicit Fitness Sharing Error Statistics ---")
(println "IFS best genome:" (pr-str (not-lazy (:genome ifs-best))))
(println "IFS best genome:" (print-genome ifs-best))
(println "IFS best program:" (pr-str (not-lazy (:program ifs-best))))
(when print-errors (println "IFS best errors:" (not-lazy (:errors ifs-best))))
(when (and print-errors (not (empty? meta-error-categories)))
Expand Down Expand Up @@ -312,7 +315,7 @@
(when (some #{parent-selection} #{:lexicase :elitegroup-lexicase :leaky-lexicase}) (lexicase-report population argmap))
(when (= total-error-method :ifs) (implicit-fitness-sharing-report population argmap))
(println (format "--- Best Program (%s) Statistics ---" (str "based on " (name err-fn))))
(println "Best genome:" (pr-str (not-lazy (:genome best))))
(println "Best genome:" (print-genome best))
(println "Best program:" (pr-str (not-lazy (:program best))))
(when (> report-simplifications 0)
(println "Partial simplification:"
Expand Down
21 changes: 13 additions & 8 deletions src/clojush/random.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@
"Returns a random instruction map given the atom-generators and the required
epigenetic-markers."
([atom-generators]
(random-plush-instruction-map atom-generators {}))
([atom-generators {:keys [epigenetic-markers
close-parens-probabilities
silent-instruction-probability]
:or {epigenetic-markers []
close-parens-probabilities [0.772 0.206 0.021 0.001]
silent-instruction-probability 0}}]
(let [markers (conj epigenetic-markers :instruction)]
(random-plush-instruction-map atom-generators {}))
([atom-generators {:keys [epigenetic-markers
close-parens-probabilities
silent-instruction-probability
track-instruction-maps]
:or {epigenetic-markers []
close-parens-probabilities [0.772 0.206 0.021 0.001]
silent-instruction-probability 0}}]
(let [markers (cond->
(conj epigenetic-markers :instruction)
track-instruction-maps (conj :uuid :random-insertion))]
(zipmap markers
(map (fn [marker]
(case marker
Expand All @@ -65,6 +68,8 @@
:silent (if (< (lrand) silent-instruction-probability)
true
false)
:random-insertion true
:uuid (java.util.UUID/randomUUID)
))
markers)))))

Expand Down