Problem file adds data to argmap, error function takes data to use, so far just simple-regression.
This commit is contained in:
parent
09375d1643
commit
719b2c6444
@ -52,16 +52,18 @@
|
||||
(let [evaluated-pop (sort-by :total-error
|
||||
(#?(:clj pmap
|
||||
:cljs map)
|
||||
(partial error-function argmap) population))
|
||||
(partial error-function argmap (:training-data argmap))
|
||||
population))
|
||||
best-individual (first evaluated-pop)]
|
||||
(report evaluated-pop generation argmap)
|
||||
(cond
|
||||
;; Success on training cases is verified on testing cases
|
||||
(zero? (:total-error best-individual))
|
||||
(do (prn {:success-generation generation})
|
||||
(prn {:total-test-error (:total-error (error-function argmap best-individual :test))})
|
||||
(#?(:clj shutdown-agents))
|
||||
)
|
||||
(prn {:total-test-error (:total-error (error-function argmap
|
||||
(:testing-data argmap)
|
||||
best-individual))})
|
||||
(#?(:clj shutdown-agents)))
|
||||
;;
|
||||
(>= generation max-generations)
|
||||
nil
|
||||
|
@ -4,21 +4,21 @@
|
||||
[propeller.push.state :as state]
|
||||
[propeller.tools.math :as math]))
|
||||
|
||||
;; =============================================================================
|
||||
;; Problem: f(x) = 7x^2 - 20x + 13
|
||||
;; =============================================================================
|
||||
|
||||
(defn- target-function-hard
|
||||
"Target function: f(x) = 7x^2 - 20x + 13"
|
||||
[x]
|
||||
(+ (* 7 x x) (* -20 x) 13))
|
||||
|
||||
(defn- target-function
|
||||
"Target function: f(x) = x^3 + x + 3"
|
||||
[x]
|
||||
(+ (* x x x) x 3))
|
||||
|
||||
; Set of original propel instructions
|
||||
(def training-data
|
||||
(let [training-inputs (range -10 11)]
|
||||
{:inputs training-inputs
|
||||
:outputs (map target-function training-inputs)}))
|
||||
|
||||
(def testing-data
|
||||
(let [testing-inputs (concat (range -20 -10) (range 11 21))]
|
||||
{:inputs testing-inputs
|
||||
:outputs (map target-function testing-inputs)}))
|
||||
|
||||
(def instructions
|
||||
(list :in1
|
||||
:integer_add
|
||||
@ -32,25 +32,13 @@
|
||||
0
|
||||
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
|
||||
"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,
|
||||
or 1000000 if no behavior is produced. The behavior is here defined as the
|
||||
final top item on the INTEGER stack."
|
||||
([argmap individual]
|
||||
(error-function argmap individual :train))
|
||||
([argmap individual subset]
|
||||
([argmap data individual]
|
||||
(let [program (genome/plushy->push (:plushy individual) argmap)
|
||||
data (get (train-and-test-data target-function) subset)
|
||||
inputs (:inputs data)
|
||||
correct-outputs (:outputs data)
|
||||
outputs (map (fn [input]
|
||||
@ -75,4 +63,6 @@
|
||||
|
||||
(def arglist
|
||||
{:instructions instructions
|
||||
:error-function error-function})
|
||||
:error-function error-function
|
||||
:training-data training-data
|
||||
:testing-data testing-data})
|
Loading…
x
Reference in New Issue
Block a user