Handle argmap adjustments outside of gp loop; add :gene when using autoconstructive crossover

This commit is contained in:
Lee Spector 2023-11-08 18:53:58 -05:00
parent be1e2aae78
commit 25e8efe255
2 changed files with 23 additions and 9 deletions

View File

@ -41,7 +41,7 @@
#?(:clj (shutdown-agents)) #?(:clj (shutdown-agents))
nil) nil)
(defn gp (defn gp-loop
"Main GP loop." "Main GP loop."
[{:keys [population-size max-generations error-function instructions [{:keys [population-size max-generations error-function instructions
max-initial-plushy-size solution-error-threshold ds-parent-rate ds-parent-gens dont-end ids-type downsample?] max-initial-plushy-size solution-error-threshold ds-parent-rate ds-parent-gens dont-end ids-type downsample?]
@ -138,3 +138,16 @@
(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
indexed-training-data) indexed-training-data)
indexed-training-data)))))) indexed-training-data))))))
(defn gp
"Top-level gp function. Calls gp-loop with possibly-adjusted arguments."
[argmap]
(let [adjust-for-autoconstructive-crossover
(fn [args]
(let [prob (:autoconstructive-crossover (:variation args))
n (:autoconstructive-crossover-enrichment args)]
(if (and prob (> prob 0))
(update args :instructions concat (repeat (or n 1) :gene))
args)))]
(gp-loop (-> argmap
(adjust-for-autoconstructive-crossover)))))

View File

@ -300,7 +300,7 @@
[& args] [& args]
(gp/gp (gp/gp
(merge (merge
{:instructions (concat instructions [:gene]) ;; autox {:instructions instructions
:error-function error-function :error-function error-function
:training-data (:train train-and-test-data) :training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data) :testing-data (:test train-and-test-data)
@ -309,9 +309,9 @@
:max-initial-plushy-size 100 :max-initial-plushy-size 100
:step-limit 10000 :step-limit 10000
:parent-selection :lexicase :parent-selection :lexicase
;:downsample? true :downsample? true
;:ds-function :case-rand :ds-function :case-rand
;:downsample-rate 0.5 :downsample-rate 0.1
;:parent-selection :tournament ;:parent-selection :tournament
;:parent-selection :motley-batch-lexicase ;:parent-selection :motley-batch-lexicase
;:max-batch-size [1 2 4 8 16 32 64 128 256] ;:max-batch-size [1 2 4 8 16 32 64 128 256]
@ -331,12 +331,13 @@
;:alternation-rate [1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256] ;:alternation-rate [1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256]
;:alignment-deviation [0 1 2 4 8 16 32 64 128] ;:alignment-deviation [0 1 2 4 8 16 32 64 128]
:variation {:ah-umad 0 :variation {:ah-umad 0
:umad 0.5 ;autox :umad 0.5
:autoconstructive-crossover 0.5 ;autox :autoconstructive-crossover 0.5
:alternation 0 :alternation 0
:reproduction 0 :reproduction 0
:tail-aligned-crossover 0} :tail-aligned-crossover 0}
;:replacement-rate 0.01 ;:replacement-rate 0.01
:elitism false :elitism false
:single-thread-mode false} :single-thread-mode false
:autoconstructive-crossover-enrichment 10}
(apply hash-map (map #(if (string? %) (read-string %) %) args))))) (apply hash-map (map #(if (string? %) (read-string %) %) args)))))