fuel cost working
This commit is contained in:
parent
6def4035c3
commit
98270691e0
@ -1 +1 @@
|
|||||||
/Volumes/Samsung_T5/Evolutionary Computing/PSB2/datasets
|
/Volumes/Samsung_T5/EvolutionaryComputing/PSB2
|
@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
(defn eval-problem-var
|
(defn eval-problem-var
|
||||||
[problem-name var-name]
|
[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
|
;; Overload 2: PSB specific
|
||||||
;; Passes into eval
|
;; Passes into eval
|
||||||
[problem-name var-name PSB2-name]
|
; [problem-name var-name psb2-name]
|
||||||
((eval (symbol (str "propeller.problems." problem-name "/" var-name))) PSB2-name))
|
; ((eval (symbol (str "propeller.problems." problem-name "/" var-name))) psb2-name))
|
||||||
|
|
||||||
(defn -main
|
(defn -main
|
||||||
"Runs propel-gp, giving it a map of arguments."
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
@ -29,13 +29,14 @@
|
|||||||
(println (str "Set path to PSB2 as " (second args)))
|
(println (str "Set path to PSB2 as " (second args)))
|
||||||
(System/exit 1))
|
(System/exit 1))
|
||||||
|
|
||||||
|
;; ** worked on GENERAL SOLUTION, save for later **
|
||||||
;; Creates PSB2 problems
|
;; Creates PSB2 problems
|
||||||
(when (= (first args) "PSB2")
|
;(when (= (first args) "PSB2")
|
||||||
;; For tomorrow, Figure out what this does?
|
;; 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
|
;; For tomorrow, add the gp/gp function here
|
||||||
;; ---
|
;; ---
|
||||||
|
;; ** end save for later **
|
||||||
|
|
||||||
;; Creates regular problems
|
;; Creates regular problems
|
||||||
(require (symbol (str "propeller.problems." (first args))))
|
(require (symbol (str "propeller.problems." (first args))))
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
(if (zero? (:total-error (error-function argmap best-individual :test)))
|
(if (zero? (:total-error (error-function argmap best-individual :test)))
|
||||||
(println "Test cases passed.")
|
(println "Test cases passed.")
|
||||||
(println "Test cases failed."))
|
(println "Test cases failed."))
|
||||||
;(#?(:clj shutdown-agents))
|
; (#?(:clj shutdown-agents))
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
(>= generation max-generations)
|
(>= generation max-generations)
|
||||||
|
@ -1,15 +1,78 @@
|
|||||||
(ns propeller.problems.PSB2-Problems
|
(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
|
;; Get path from text file
|
||||||
(def PSB2-path (slurp "PSB2_path.txt"))
|
(def PSB2-path (slurp "PSB2_path.txt"))
|
||||||
|
|
||||||
(defn train-and-test
|
;; ** worked on GENERAL SOLUTION for PSB2, save for later **
|
||||||
"Returns the train and test sets from PSB2 using Prof. Helmuth's function"
|
;(defn train-and-test
|
||||||
;; Default to 200 train and 2000 test
|
; "Returns the train and test sets from PSB2 using Prof. Helmuth's function"
|
||||||
[problem]
|
; ;; Default to 200 train and 2000 test
|
||||||
(psb2/fetch-examples PSB2-path problem 200 2000)
|
; [problem]
|
||||||
;; To with 2 extra args, can customise train and test set sizes
|
; (psb2/fetch-examples PSB2-path problem 200 2000)
|
||||||
[problem train test]
|
; ;; To with 2 extra args, can customise train and test set sizes
|
||||||
(psb2/fetch-examples PSB2-path problem train test))
|
; [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))))))
|
||||||
|
|
||||||
|
@ -71,9 +71,4 @@
|
|||||||
: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 test-thingy
|
|
||||||
[x]
|
|
||||||
(println x))
|
|
Loading…
x
Reference in New Issue
Block a user