Update complex_regression.cljc
This commit is contained in:
parent
336710144d
commit
11b09c9be0
@ -9,21 +9,22 @@
|
|||||||
(defn- target-function
|
(defn- target-function
|
||||||
"Target function: f(x) = (x^3 + 1)^3 + 1"
|
"Target function: f(x) = (x^3 + 1)^3 + 1"
|
||||||
[x]
|
[x]
|
||||||
(* (+ (* x x x) 1) (+ (* x x x) 1) (+ (* x x x) 1) + 1))
|
(let [x-new (+ (* x x x) 1)]
|
||||||
|
(+ (* x-new x-new x-new) 1)))
|
||||||
|
|
||||||
(def train-and-test-data
|
(def train-and-test-data
|
||||||
(let [train-inputs (range -10 11)
|
(let [train-inputs (range -5.0 5.0 0.5)
|
||||||
test-inputs (concat (range -20 -10) (range 11 21))]
|
test-inputs (range -5.25 5.75 0.5)]
|
||||||
{:train (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) train-inputs)
|
{:train (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) train-inputs)
|
||||||
:test (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) test-inputs)}))
|
:test (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) test-inputs)}))
|
||||||
|
|
||||||
(def instructions
|
(def instructions
|
||||||
(list :in1
|
(list :in1
|
||||||
:integer_add
|
:float_add
|
||||||
:integer_subtract
|
:float_subtract
|
||||||
:integer_mult
|
:float_mult
|
||||||
:integer_quot
|
:float_quot
|
||||||
:integer_eq
|
:float_eq
|
||||||
:exec_dup
|
:exec_dup
|
||||||
:exec_if
|
:exec_if
|
||||||
'close
|
'close
|
||||||
@ -34,18 +35,18 @@
|
|||||||
"Finds the behaviors and errors of an individual. The error is the absolute
|
"Finds the behaviors and errors of an individual. The error is the absolute
|
||||||
deviation between the target output value and the program's selected behavior,
|
deviation between the target output value and the program's selected behavior,
|
||||||
or 1000000 if no behavior is produced. The behavior is here defined as the
|
or 1000000 if no behavior is produced. The behavior is here defined as the
|
||||||
final top item on the INTEGER stack."
|
final top item on the FLOAT stack."
|
||||||
([argmap data individual]
|
([argmap data individual]
|
||||||
(let [program (genome/plushy->push (:plushy individual) argmap)
|
(let [program (genome/plushy->push (:plushy individual) argmap)
|
||||||
inputs (map (fn [x] (first (:input1 x))) data)
|
inputs (map (fn [x] (first (:input1 x))) data)
|
||||||
correct-outputs (map (fn [x] (first (:output1 x))) data)
|
correct-outputs (map (fn [x] (first (:output1 x))) data)
|
||||||
outputs (map (fn [input]
|
outputs (map (fn [input]
|
||||||
(state/peek-stack
|
(state/peek-stack
|
||||||
(interpreter/interpret-program
|
(interpreter/interpret-program
|
||||||
program
|
program
|
||||||
(assoc state/empty-state :input {:in1 input})
|
(assoc state/empty-state :input {:in1 input})
|
||||||
(:step-limit argmap))
|
(:step-limit argmap))
|
||||||
:integer))
|
:float))
|
||||||
inputs)
|
inputs)
|
||||||
errors (map (fn [correct-output output]
|
errors (map (fn [correct-output output]
|
||||||
(if (= output :no-stack-item)
|
(if (= output :no-stack-item)
|
||||||
@ -54,28 +55,31 @@
|
|||||||
correct-outputs
|
correct-outputs
|
||||||
outputs)]
|
outputs)]
|
||||||
(assoc individual
|
(assoc individual
|
||||||
:behaviors outputs
|
:behaviors outputs
|
||||||
:errors errors
|
:errors errors
|
||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors))))))
|
:cljs (apply + errors))))))
|
||||||
|
|
||||||
(defn -main
|
(defn -main
|
||||||
"Runs propel-gp, giving it a map of arguments."
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
[& args]
|
[& args]
|
||||||
(gp/gp
|
(gp/gp
|
||||||
(merge
|
(merge
|
||||||
{:instructions instructions
|
{: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)
|
||||||
:max-generations 500
|
:max-generations 5000
|
||||||
:population-size 500
|
:population-size 500
|
||||||
:max-initial-plushy-size 100
|
:max-initial-plushy-size 100
|
||||||
:step-limit 200
|
:step-limit 200
|
||||||
:parent-selection :lexicase
|
:parent-selection :ds-lexicase
|
||||||
:tournament-size 5
|
:ds-function :case-maxmin
|
||||||
:umad-rate 0.1
|
:downsample-rate 0.1
|
||||||
:variation {:umad 1.0 :crossover 0.0}
|
:case-t-size 20
|
||||||
:elitism false}
|
:tournament-size 5
|
||||||
(apply hash-map (map #(if (string? %) (read-string %) %) args))))
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 1.0 :crossover 0.0}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map #(if (string? %) (read-string %) %) args))))
|
||||||
(#?(:clj shutdown-agents)))
|
(#?(:clj shutdown-agents)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user