remove hacky hyperselection code
This commit is contained in:
parent
98d7126dee
commit
7ca3767b02
@ -5,7 +5,6 @@
|
|||||||
[propeller.simplification :as simplification]
|
[propeller.simplification :as simplification]
|
||||||
[propeller.variation :as variation]
|
[propeller.variation :as variation]
|
||||||
[propeller.downsample :as downsample]
|
[propeller.downsample :as downsample]
|
||||||
[propeller.hyperselection :as hyperselection]
|
|
||||||
[propeller.push.instructions.bool]
|
[propeller.push.instructions.bool]
|
||||||
[propeller.push.instructions.character]
|
[propeller.push.instructions.character]
|
||||||
[propeller.push.instructions.code]
|
[propeller.push.instructions.code]
|
||||||
@ -126,16 +125,14 @@
|
|||||||
(+ evaluations (* population-size (count training-data)) ;every member evaluated on the current sample
|
(+ evaluations (* population-size (count training-data)) ;every member evaluated on the current sample
|
||||||
(if (zero? (mod generation ds-parent-gens)) (* (count parent-reps) (- (count indexed-training-data) (count training-data))) 0) ; the parent-reps not evaluted already on down-sample
|
(if (zero? (mod generation ds-parent-gens)) (* (count parent-reps) (- (count indexed-training-data) (count training-data))) 0) ; the parent-reps not evaluted already on down-sample
|
||||||
(if best-individual-passes-ds (- (count indexed-training-data) (count training-data)) 0)) ; if we checked for generalization or not
|
(if best-individual-passes-ds (- (count indexed-training-data) (count training-data)) 0)) ; if we checked for generalization or not
|
||||||
(let [reindexed-pop (hyperselection/reindex-pop evaluated-pop argmap)] ; give every individual an index for hyperselection loggin
|
|
||||||
(hyperselection/log-hyperselection-and-ret
|
|
||||||
(if (:elitism argmap)
|
(if (:elitism argmap)
|
||||||
(conj (utils/pmapallv (fn [_] (variation/new-individual reindexed-pop argmap))
|
(conj (utils/pmapallv (fn [_] (variation/new-individual evaluated-pop argmap))
|
||||||
(range (dec population-size))
|
(range (dec population-size))
|
||||||
argmap)
|
argmap)
|
||||||
(first reindexed-pop)) ;elitism maintains the most-fit individual
|
(first evaluated-pop)) ;elitism maintains the most-fit individual
|
||||||
(utils/pmapallv (fn [_] (variation/new-individual reindexed-pop argmap))
|
(utils/pmapallv (fn [_] (variation/new-individual evaluated-pop argmap))
|
||||||
(range population-size)
|
(range population-size)
|
||||||
argmap))))
|
argmap))
|
||||||
(if downsample?
|
(if downsample?
|
||||||
(if (zero? (mod generation ds-parent-gens))
|
(if (zero? (mod generation ds-parent-gens))
|
||||||
(downsample/update-case-distances rep-evaluated-pop indexed-training-data indexed-training-data ids-type (/ solution-error-threshold (count indexed-training-data))) ; update distances every ds-parent-gens generations
|
(downsample/update-case-distances rep-evaluated-pop indexed-training-data indexed-training-data ids-type (/ solution-error-threshold (count indexed-training-data))) ; update distances every ds-parent-gens generations
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
(ns propeller.hyperselection
|
|
||||||
(:require [propeller.utils :as utils]))
|
|
||||||
|
|
||||||
(defn sum-list-map-indices
|
|
||||||
"sums a list of maps that have the :index property's index multiplicity"
|
|
||||||
[list-of-maps]
|
|
||||||
(->> list-of-maps
|
|
||||||
(map #(:index %))
|
|
||||||
frequencies))
|
|
||||||
|
|
||||||
(defn ordered-freqs
|
|
||||||
"takes a map from indices to frequencies, and returns a sorted list of the frequences is descencing order"
|
|
||||||
[freqs]
|
|
||||||
(->> freqs
|
|
||||||
vals
|
|
||||||
(sort >)))
|
|
||||||
|
|
||||||
(defn normalize-list-by-popsize [popsize lst]
|
|
||||||
(map #(double (/ % popsize)) lst))
|
|
||||||
|
|
||||||
(defn hyperselection-track
|
|
||||||
"outputs a normalized list of the hyperselection proportion for each parent"
|
|
||||||
[new-pop]
|
|
||||||
(->> new-pop
|
|
||||||
sum-list-map-indices
|
|
||||||
ordered-freqs
|
|
||||||
(normalize-list-by-popsize (count new-pop))))
|
|
||||||
|
|
||||||
(defn log-hyperselection-and-ret [new-pop]
|
|
||||||
(prn {:hyperselection (hyperselection-track new-pop)})
|
|
||||||
new-pop)
|
|
||||||
|
|
||||||
(defn reindex-pop
|
|
||||||
"assigns each member of the population a unique index before selection to track hyperselection"
|
|
||||||
[pop argmap]
|
|
||||||
(utils/pmapallv (fn [indiv index] (assoc indiv :index index)) pop (range (count pop)) argmap))
|
|
@ -253,8 +253,6 @@ The function `new-individual` returns a new individual produced by selection and
|
|||||||
"Returns a new individual produced by selection and variation of
|
"Returns a new individual produced by selection and variation of
|
||||||
individuals in the population."
|
individuals in the population."
|
||||||
[pop argmap]
|
[pop argmap]
|
||||||
(let [umad-parent (selection/select-parent pop argmap)
|
|
||||||
parent-ind (:index umad-parent)] ;this is a hack to log hyperselection, only works for umad
|
|
||||||
{:plushy
|
{:plushy
|
||||||
(let [r (rand)
|
(let [r (rand)
|
||||||
op (loop [accum 0.0
|
op (loop [accum 0.0
|
||||||
@ -347,4 +345,4 @@ The function `new-individual` returns a new individual produced by selection and
|
|||||||
:else
|
:else
|
||||||
(throw #?(:clj (Exception. (str "No match in new-individual for " op))
|
(throw #?(:clj (Exception. (str "No match in new-individual for " op))
|
||||||
:cljs (js/Error
|
:cljs (js/Error
|
||||||
(str "No match in new-individual for " op))))))}))
|
(str "No match in new-individual for " op))))))})
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
(:require [clojure.test :as t]
|
(:require [clojure.test :as t]
|
||||||
[propeller.utils :as u]
|
[propeller.utils :as u]
|
||||||
[propeller.simplification :as s]
|
[propeller.simplification :as s]
|
||||||
[propeller.downsample :as ds]
|
[propeller.downsample :as ds]))
|
||||||
[propeller.hyperselection :as hs]))
|
|
||||||
|
|
||||||
|
|
||||||
(t/deftest assign-indices-to-data-test
|
(t/deftest assign-indices-to-data-test
|
||||||
@ -138,26 +137,3 @@
|
|||||||
{:case-delta 0})]
|
{:case-delta 0})]
|
||||||
(prn {:selected selected})
|
(prn {:selected selected})
|
||||||
(t/is (= 1 (count selected))))))
|
(t/is (= 1 (count selected))))))
|
||||||
|
|
||||||
|
|
||||||
(t/deftest hyperselection-test
|
|
||||||
(let [parents1 '({:blah 3 :index 1} {:blah 3 :index 1}
|
|
||||||
{:blah 3 :index 1} {:blah 3 :index 2})
|
|
||||||
parents2 '({:plushy 2 :index 0} {:blah 3 :index 2}
|
|
||||||
{:blah 3 :index 3} {:index 4})
|
|
||||||
emptyparents '({:blah 1} {:blah 1} {:blah 1})]
|
|
||||||
(t/testing "sum-list-map-indices function works correctly"
|
|
||||||
(t/is (= {1 3, 2 1} (hs/sum-list-map-indices parents1)))
|
|
||||||
(t/is (= {0 1, 2 1, 3 1, 4 1} (hs/sum-list-map-indices parents2))))
|
|
||||||
(t/testing "ordered-freqs function works correctly"
|
|
||||||
(t/is (= '(3 1) (hs/ordered-freqs (hs/sum-list-map-indices parents1))))
|
|
||||||
(t/is (= '(1 1 1 1) (hs/ordered-freqs (hs/sum-list-map-indices parents2)))))
|
|
||||||
(t/testing "hyperselection-track works correctly"
|
|
||||||
(t/is (= '(0.75 0.25) (hs/hyperselection-track parents1)))
|
|
||||||
(t/is (= '(0.25 0.25 0.25 0.25) (hs/hyperselection-track parents2))))
|
|
||||||
(t/testing "reindex-pop works correctly"
|
|
||||||
(t/is (= '({:blah 3 :index 0} {:blah 3 :index 1}
|
|
||||||
{:blah 3 :index 2} {:blah 3 :index 3}) (hs/reindex-pop parents1 {})))
|
|
||||||
(t/is (= '({:plushy 2 :index 0} {:blah 3 :index 1}
|
|
||||||
{:blah 3 :index 2} {:index 3}) (hs/reindex-pop parents2 {})))
|
|
||||||
(t/is (= '({:blah 1 :index 0} {:blah 1 :index 1} {:blah 1 :index 2}) (hs/reindex-pop emptyparents {}))))))
|
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
(:require [clojure.test :as t]
|
(:require [clojure.test :as t]
|
||||||
[propeller.utils :as u]
|
[propeller.utils :as u]
|
||||||
[propeller.simplification :as s]
|
[propeller.simplification :as s]
|
||||||
[propeller.downsample :as ds]
|
[propeller.downsample :as ds]))
|
||||||
[propeller.hyperselection :as hs]))
|
|
||||||
|
|
||||||
(t/deftest first-non-nil-test
|
(t/deftest first-non-nil-test
|
||||||
(t/is (= 1 (u/first-non-nil '(1 2 3))))
|
(t/is (= 1 (u/first-non-nil '(1 2 3))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user