Add train/test data support to simple-regression problem
This commit is contained in:
parent
509c22b79c
commit
3ba030ceec
@ -32,31 +32,43 @@
|
|||||||
0
|
0
|
||||||
1))
|
1))
|
||||||
|
|
||||||
|
(defn train-and-test-data
|
||||||
|
[target-function]
|
||||||
|
(let [train-inputs (range -10 11)
|
||||||
|
test-inputs (concat (range -20 -10) (range 11 21))]
|
||||||
|
{:train {:inputs train-inputs
|
||||||
|
:outputs (map target-function train-inputs)}
|
||||||
|
:test {:inputs test-inputs
|
||||||
|
:outputs (map target-function test-inputs)}}))
|
||||||
|
|
||||||
(defn error-function
|
(defn error-function
|
||||||
"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 INTEGER stack."
|
||||||
[argmap individual]
|
([argmap individual]
|
||||||
(let [program (genome/plushy->push (:plushy individual) argmap)
|
(error-function argmap individual :train))
|
||||||
inputs (range -10 11)
|
([argmap individual subset]
|
||||||
correct-outputs (map target-function inputs)
|
(let [program (genome/plushy->push (:plushy individual) argmap)
|
||||||
outputs (map (fn [input]
|
data (get (train-and-test-data target-function) subset)
|
||||||
(state/peek-stack
|
inputs (:inputs data)
|
||||||
(interpreter/interpret-program
|
correct-outputs (:outputs data)
|
||||||
program
|
outputs (map (fn [input]
|
||||||
(assoc state/empty-state :input {:in1 input})
|
(state/peek-stack
|
||||||
(:step-limit argmap))
|
(interpreter/interpret-program
|
||||||
:integer))
|
program
|
||||||
inputs)
|
(assoc state/empty-state :input {:in1 input})
|
||||||
errors (map (fn [correct-output output]
|
(:step-limit argmap))
|
||||||
(if (= output :no-stack-item)
|
:integer))
|
||||||
1000000
|
inputs)
|
||||||
(math/abs (- correct-output output))))
|
errors (map (fn [correct-output output]
|
||||||
correct-outputs
|
(if (= output :no-stack-item)
|
||||||
outputs)]
|
1000000
|
||||||
(assoc individual
|
(math/abs (- correct-output output))))
|
||||||
:behaviors outputs
|
correct-outputs
|
||||||
:errors errors
|
outputs)]
|
||||||
:total-error #?(:clj (apply +' errors)
|
(assoc individual
|
||||||
:cljs (apply + errors)))))
|
:behaviors outputs
|
||||||
|
:errors errors
|
||||||
|
:total-error #?(:clj (apply +' errors)
|
||||||
|
:cljs (apply + errors))))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user