diff --git a/PSB2_path.txt b/PSB2_path.txt index b449bfb..c9a901d 100644 --- a/PSB2_path.txt +++ b/PSB2_path.txt @@ -1 +1 @@ -/Volumes/Samsung_T5/Evolutionary Computing/PSB2/datasets \ No newline at end of file +/Volumes/Samsung_T5/EvolutionaryComputing/PSB2 \ No newline at end of file diff --git a/src/propeller/core.cljc b/src/propeller/core.cljc index bced168..830635f 100755 --- a/src/propeller/core.cljc +++ b/src/propeller/core.cljc @@ -7,11 +7,11 @@ (defn eval-problem-var [problem-name var-name] - (eval (symbol (str "propeller.problems." problem-name "/" var-name))) + (eval (symbol (str "propeller.problems." problem-name "/" var-name)))) ;; Overload 2: PSB specific ;; Passes into eval - [problem-name var-name PSB2-name] - ((eval (symbol (str "propeller.problems." problem-name "/" var-name))) PSB2-name)) + ; [problem-name var-name psb2-name] + ; ((eval (symbol (str "propeller.problems." problem-name "/" var-name))) psb2-name)) (defn -main "Runs propel-gp, giving it a map of arguments." @@ -29,13 +29,14 @@ (println (str "Set path to PSB2 as " (second args))) (System/exit 1)) + ;; ** worked on GENERAL SOLUTION, save for later ** ;; Creates PSB2 problems - (when (= (first args) "PSB2") + ;(when (= (first args) "PSB2") ;; For tomorrow, Figure out what this does? - (require (symbol (str "propeller.problems.PSB2" (first args)))) + ;(require (symbol (str "propeller.problems.PSB2" (first args))))) ;; For tomorrow, add the gp/gp function here ;; --- - + ;; ** end save for later ** ;; Creates regular problems (require (symbol (str "propeller.problems." (first args)))) diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 0eb0426..ad2a4a9 100755 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -61,7 +61,7 @@ (if (zero? (:total-error (error-function argmap best-individual :test))) (println "Test cases passed.") (println "Test cases failed.")) - ;(#?(:clj shutdown-agents)) + ; (#?(:clj shutdown-agents)) ) ;; (>= generation max-generations) diff --git a/src/propeller/problems/PSB2_Problems.cljc b/src/propeller/problems/PSB2_Problems.cljc index fea00c9..569238c 100644 --- a/src/propeller/problems/PSB2_Problems.cljc +++ b/src/propeller/problems/PSB2_Problems.cljc @@ -1,15 +1,78 @@ (ns propeller.problems.PSB2-Problems - (:require [psb2.core :as psb2])) + (:require [psb2.core :as psb2] + [propeller.genome :as genome] + [propeller.push.interpreter :as interpreter] + [propeller.utils :as utils] + [propeller.push.utils.helpers :refer [get-stack-instructions]] + [propeller.push.state :as state] + [propeller.tools.math :as math])) ;; Get path from text file (def PSB2-path (slurp "PSB2_path.txt")) -(defn train-and-test - "Returns the train and test sets from PSB2 using Prof. Helmuth's function" - ;; Default to 200 train and 2000 test - [problem] - (psb2/fetch-examples PSB2-path problem 200 2000) - ;; To with 2 extra args, can customise train and test set sizes - [problem train test] - (psb2/fetch-examples PSB2-path problem train test)) +;; ** worked on GENERAL SOLUTION for PSB2, save for later ** +;(defn train-and-test +; "Returns the train and test sets from PSB2 using Prof. Helmuth's function" +; ;; Default to 200 train and 2000 test +; [problem] +; (psb2/fetch-examples PSB2-path problem 200 2000) +; ;; To with 2 extra args, can customise train and test set sizes +; [problem train test] +; (psb2/fetch-examples PSB2-path problem train test)) +;; ** end save for later ** + +;; train and test set generation: Specific function for fuel-cost, +;; single PSB2 problem implementation +;(defn train-and-test-data +; "Returns the train and test sets " +; [] +; (psb2/fetch-examples PSB2-path "fuel-cost" 200 2000)) + +(def train-and-test-data (psb2/fetch-examples PSB2-path "fuel-cost" 200 2000)) + + + +;; Instruction set: ported from number-io, meant for fuel-cost +(def instructions + (utils/not-lazy + (concat + ;; stack-specific instructions + (get-stack-instructions #{:float :integer :print}) + ;; input instructions + (list :in1)))) + ;; ERCs (constants) + ;; (list random-float random-int)))) + +;; Error function from number-io +(defn error-function + ([argmap individual] + (error-function argmap individual :train)) + ([argmap individual subset] + (let [program (genome/plushy->push (:plushy individual) argmap) + data (get train-and-test-data subset) + inputs (map (fn [i] (get i :input1)) (get train-and-test-data subset)) + correct-outputs (map (fn [i] (get i :output1)) (get train-and-test-data subset)) + outputs (map (fn [input] + (state/peek-stack + (interpreter/interpret-program + program + (assoc state/empty-state :input {:in1 (first input)} + :output '("")) + (:step-limit argmap)) + :output)) + inputs) + parsed-outputs (map (fn [output] + (try (read-string output) + #?(:clj (catch Exception e 1000.0) + :cljs (catch js/Error. e 1000.0)))) + outputs) + errors (map (fn [correct-output output] + (min 1000.0 (math/abs (- correct-output output)))) + correct-outputs + parsed-outputs)] + (assoc individual + :behaviors parsed-outputs + :errors errors + :total-error #?(:clj (apply +' errors) + :cljs (apply + errors)))))) diff --git a/src/propeller/problems/simple_regression.cljc b/src/propeller/problems/simple_regression.cljc index 94508cf..5d19460 100755 --- a/src/propeller/problems/simple_regression.cljc +++ b/src/propeller/problems/simple_regression.cljc @@ -71,9 +71,4 @@ :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) - :cljs (apply + errors)))))) - - -(defn test-thingy - [x] - (println x)) + :cljs (apply + errors)))))) \ No newline at end of file