Closed jjttjj closed 5 years ago
The error function here is problematic in a coupe of respects. The "let" binds a symbol (ouput, should probably be output) but doesn't return a value. It should return a value, and that value should be a number, which it won't be if the program leaves the :float
stack empty, so you need to check for that and return some number (probably a high penalty error). The error for a particular input should reflect the difference between the top float and what it should be, which could come either from data or an equation that your are trying to "re-discover" with GP. In the code below, I've made it the difference between the top float and 3 times the input squared. I also increased the population size. I also added the number 1.0 for it to have as raw material. Anyway, try running this, and it should run without the error you were seeing:
(pushgp
{:error-function
(fn [{:keys [program] :as individual}]
(assoc individual
:errors (vec
(for [input (mapv float (range 10))]
(let [output (->> (make-push-state)
(push-item input :input)
(run-push program)
(top-item :float))]
(if (number? output)
(Math/abs (- output (* input input 3)))
1000))))))
:atom-generators (list 'in1
'float_div
'float_mult
'float_add
'float_sub
1.0)
:population-size 1000
:parent-selection :tournament
:use-single-thread true})
Starting a fresh repl in my project (which depends on clojush 3.19.0) and inputting the following excerpt from the tutorial worksheet throws an exception: