Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed fast-lexicase-selection.

  • Loading branch information...
commit 4959b6d6d3a5dc81ec175cd9c1a40b3a94799e8d 1 parent 08e67e8
@thelmuth thelmuth authored
View
4 src/clojush/evaluate.clj
@@ -21,10 +21,10 @@
nil))
(defn calculate-hah-solution-rates
- [use-historically-assessed-hardness use-lexicase-selection use-fast-lexicase-selection
+ [use-historically-assessed-hardness use-lexicase-selection
pop-agents error-threshold population-size]
(when (and use-historically-assessed-hardness
- (not (or use-lexicase-selection use-fast-lexicase-selection)))
+ (not use-lexicase-selection))
(reset! solution-rates
(let [error-seqs (map :errors (map deref pop-agents))
num-cases (count (first error-seqs))]
View
2  src/clojush/globals.clj
@@ -40,5 +40,3 @@
;; Lexicase Parent Selection (see Spector paper in GECCO-UP 2012 workshop proceedings)
(def global-use-lexicase-selection (atom false)) ;; if true then no other selection params matter
-(def global-use-fast-lexicase-selection (atom false))
-(def global-lexicase-case-cohorts (atom [])) ;; used for fast-lexicase-selection
View
64 src/clojush/pushgp/parent_selection.clj
@@ -1,5 +1,4 @@
(ns clojush.pushgp.parent-selection
- (:require [clojure.set :as set])
(:use [clojush.random]
[clojush.globals]))
@@ -20,59 +19,22 @@
survivors)
(rest cases))))))
-(defn setup-fast-lexicase-selection
- "Sets global-lexicase-case-cohorts to be the data structure needed for fast-lexicase-selection.
- The value is a vector of copies of the population, one for each fitness case, with each
- sorted by error on the specified case and then partitioned into sequences of individuals with the
- same fitness for that case."
- [pop]
- (print "Setting up for fast lexicase selection... ")(flush)
- (reset! global-lexicase-case-cohorts
- (vec (map (fn [case-index]
- (partition-by
- #(nth (:errors %) case-index)
- (sort #(< (nth (:errors %1) case-index)
- (nth (:errors %2) case-index))
- pop)))
- (range (count (:errors (first pop)))))))
- ;; this prints a lot but it's a good sanity check and maybe useful information some day
- ;(println "Cohort sizes:" (map (fn [cohorts] (map count cohorts)) @global-lexicase-case-cohorts))
- (println "Done.")(flush)
- )
-
-(defn fast-lexicase-selection
- "Returns an individual that does the best on a randomly selected set of fitness cases.
- Assumes that setup-fast-lexicase-selection has been run, setting up global-lexicase-case-cohorts."
- [pop]
- (loop [cases (lshuffle (range (count (:errors (first pop)))))
- survivors (first (nth @global-lexicase-case-cohorts (first cases)))]
- (if (or (empty? (rest cases))
- (empty? (rest survivors)))
- (lrand-nth survivors)
- (let [min-err-for-next-case (apply min (map #(nth % (second cases))
- (map #(:errors %) survivors)))]
- (recur (rest cases)
- (filter #(= (nth (:errors %) (second cases)) min-err-for-next-case)
- survivors))))))
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; parent selection
(defn select
"Returns a selected parent, using lexicase or tournament selection."
[pop tournament-size radius location]
- (if @global-use-fast-lexicase-selection
- (fast-lexicase-selection pop)
- (if @global-use-lexicase-selection
- (lexicase-selection pop)
- (let [tournament-set
- (doall
- (for [_ (range tournament-size)]
- (nth pop
- (if (zero? radius)
- (lrand-int (count pop))
- (mod (+ location (- (lrand-int (+ 1 (* radius 2))) radius))
- (count pop))))))
- err-fn (if @global-use-historically-assessed-hardness :hah-error :total-error)]
- (reduce (fn [i1 i2] (if (< (err-fn i1) (err-fn i2)) i1 i2))
- tournament-set)))))
+ (if @global-use-lexicase-selection
+ (lexicase-selection pop)
+ (let [tournament-set
+ (doall
+ (for [_ (range tournament-size)]
+ (nth pop
+ (if (zero? radius)
+ (lrand-int (count pop))
+ (mod (+ location (- (lrand-int (+ 1 (* radius 2))) radius))
+ (count pop))))))
+ err-fn (if @global-use-historically-assessed-hardness :hah-error :total-error)]
+ (reduce (fn [i1 i2] (if (< (err-fn i1) (err-fn i2)) i1 i2))
+ tournament-set))))
View
21 src/clojush/pushgp/pushgp.clj
@@ -34,8 +34,7 @@
gaussian-mutation-per-number-mutation-probability
gaussian-mutation-standard-deviation reuse-errors
problem-specific-report use-single-thread random-seed
- use-historically-assessed-hardness use-lexicase-selection
- use-fast-lexicase-selection]
+ use-historically-assessed-hardness use-lexicase-selection]
:or {error-function (fn [p] '(0)) ;; pgm -> list of errors (1 per case)
error-threshold 0
population-size 1000
@@ -68,10 +67,9 @@
reuse-errors true
problem-specific-report default-problem-specific-report
use-single-thread false
- random-seed (System/nanoTime)
- use-historically-assessed-hardness false
- use-lexicase-selection false
- use-fast-lexicase-selection false
+ random-seed (System/nanoTime)
+ use-historically-assessed-hardness false
+ use-lexicase-selection false
}}]
(binding [*thread-local-random-generator* (java.util.Random. random-seed)]
;; set globals from parameters
@@ -86,7 +84,6 @@
(reset! global-reuse-errors reuse-errors)
(reset! global-use-historically-assessed-hardness use-historically-assessed-hardness)
(reset! global-use-lexicase-selection use-lexicase-selection)
- (reset! global-use-fast-lexicase-selection use-fast-lexicase-selection)
(initial-report) ;; Print the inital report
(print-params
(error-function error-threshold population-size max-points atom-generators max-generations
@@ -98,7 +95,7 @@
evalpush-time-limit node-selection-method node-selection-tournament-size
node-selection-leaf-probability pop-when-tagging reuse-errors
use-single-thread random-seed use-historically-assessed-hardness
- use-lexicase-selection use-fast-lexicase-selection
+ use-lexicase-selection
))
(printf "\nGenerating initial population...\n") (flush)
(let [pop-agents (vec (doall (for [_ (range population-size)]
@@ -122,10 +119,9 @@
(when-not use-single-thread (apply await pop-agents)) ;; SYNCHRONIZE ;might this need a dorun?
(printf "\nDone computing errors.") (flush)
(calculate-hah-solution-rates use-historically-assessed-hardness
- use-lexicase-selection
- use-fast-lexicase-selection ;; calculate solution rates
- pop-agents ;; if necessary for
- error-threshold ;; historically-assessed hardness
+ use-lexicase-selection ;; calculate solution rates
+ pop-agents ;; if necessary for
+ error-threshold ;; historically-assessed hardness
population-size)
;; report and check for success
(let [best (report (vec (doall (map deref pop-agents))) generation error-function
@@ -141,7 +137,6 @@
(int (* decimation-ratio population-size))
decimation-tournament-size
trivial-geography-radius))]
- (if use-fast-lexicase-selection (setup-fast-lexicase-selection pop))
(dotimes [i population-size]
((if use-single-thread swap! send)
(nth child-agents i)
Please sign in to comment.
Something went wrong with that request. Please try again.