fixed fuel cost
This commit is contained in:
parent
98270691e0
commit
3075d8a35a
117
errors.txt
Normal file
117
errors.txt
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
Average total error: 1.20971232E8
|
||||||
|
Average total error: 7.0990816E7
|
||||||
|
Average total error: 5.8947272E7
|
||||||
|
Average total error: 4.744878E7
|
||||||
|
Average total error: 4.1555428E7
|
||||||
|
Average total error: 3.8916616E7
|
||||||
|
Average total error: 3.8646348E7
|
||||||
|
Average total error: 4.678786E7
|
||||||
|
Average total error: 3.8375184E7
|
||||||
|
Average total error: 3.6898772E7
|
||||||
|
Average total error: 3.8002356E7
|
||||||
|
Average total error: 3.8138176E7
|
||||||
|
Average total error: 3.8647716E7
|
||||||
|
Average total error: 3.6817828E7
|
||||||
|
Average total error: 3.2690788E7
|
||||||
|
Average total error: 3.3710072E7
|
||||||
|
Average total error: 4.3554124E7
|
||||||
|
Average total error: 3.8026116E7
|
||||||
|
Average total error: 4.5374592E7
|
||||||
|
Average total error: 4.7729904E7
|
||||||
|
Average total error: 4.278798E7
|
||||||
|
Average total error: 3.8943096E7
|
||||||
|
Average total error: 3.796032E7
|
||||||
|
Average total error: 4.2565964E7
|
||||||
|
Average total error: 5.199024E7
|
||||||
|
Average total error: 4.9884316E7
|
||||||
|
Average total error: 5.0332596E7
|
||||||
|
Average total error: 4.4738712E7
|
||||||
|
Average total error: 5.1121884E7
|
||||||
|
Average total error: 5.28278E7
|
||||||
|
Average total error: 4.737436E7
|
||||||
|
Average total error: 4.8825116E7
|
||||||
|
Average total error: 4.5050176E7
|
||||||
|
Average total error: 4.7032076E7
|
||||||
|
Average total error: 3.75375E7
|
||||||
|
Average total error: 4.1770188E7
|
||||||
|
Average total error: 4.2192324E7
|
||||||
|
Average total error: 3.8121424E7
|
||||||
|
Average total error: 3.6940792E7
|
||||||
|
Average total error: 4.0735792E7
|
||||||
|
Average total error: 3.7949944E7
|
||||||
|
Average total error: 3.8094084E7
|
||||||
|
Average total error: 3.9462696E7
|
||||||
|
Average total error: 4.2240504E7
|
||||||
|
Average total error: 4.1255188E7
|
||||||
|
Average total error: 4.235198E7
|
||||||
|
Average total error: 3.7214584E7
|
||||||
|
Average total error: 3.861928E7
|
||||||
|
Average total error: 3.77219E7
|
||||||
|
Average total error: 3.7414448E7
|
||||||
|
Average total error: 3.2616348E7
|
||||||
|
Average total error: 2.8501912E7
|
||||||
|
Average total error: 2.9924808E7
|
||||||
|
Average total error: 3.351813E7
|
||||||
|
Average total error: 3.3687728E7
|
||||||
|
Average total error: 3.6236108E7
|
||||||
|
Average total error: 3.6975212E7
|
||||||
|
Average total error: 3.6543472E7
|
||||||
|
Average total error: 3.8481856E7
|
||||||
|
Average total error: 3.4455868E7
|
||||||
|
Average total error: 3.0916116E7
|
||||||
|
Average total error: 2.8618544E7
|
||||||
|
Average total error: 2.7537918E7
|
||||||
|
Average total error: 2.9564782E7
|
||||||
|
Average total error: 2.56306E7
|
||||||
|
Average total error: 2.2281254E7
|
||||||
|
Average total error: 2.599309E7
|
||||||
|
Average total error: 1.966063E7
|
||||||
|
Average total error: 1.7483378E7
|
||||||
|
Average total error: 1.6682909E7
|
||||||
|
Average total error: 1.5032185E7
|
||||||
|
Average total error: 1.7223616E7
|
||||||
|
Average total error: 1.7384072E7
|
||||||
|
Average total error: 1.89933E7
|
||||||
|
Average total error: 2.5394602E7
|
||||||
|
Average total error: 1.708214E7
|
||||||
|
Average total error: 2.1111482E7
|
||||||
|
Average total error: 1.82417E7
|
||||||
|
Average total error: 2.4765124E7
|
||||||
|
Average total error: 2.0515838E7
|
||||||
|
Average total error: 2.5062742E7
|
||||||
|
Average total error: 2.6861224E7
|
||||||
|
Average total error: 3.4709076E7
|
||||||
|
Average total error: 3.0924278E7
|
||||||
|
Average total error: 3.5103116E7
|
||||||
|
Average total error: 3.0408544E7
|
||||||
|
Average total error: 3.8609756E7
|
||||||
|
Average total error: 3.8840836E7
|
||||||
|
Average total error: 3.641088E7
|
||||||
|
Average total error: 3.7741632E7
|
||||||
|
Average total error: 3.4173112E7
|
||||||
|
Average total error: 3.921708E7
|
||||||
|
Average total error: 3.5226188E7
|
||||||
|
Average total error: 3.9501532E7
|
||||||
|
Average total error: 3.7897072E7
|
||||||
|
Average total error: 3.4845884E7
|
||||||
|
Average total error: 3.3286008E7
|
||||||
|
Average total error: 3.5198156E7
|
||||||
|
Average total error: 2.665777E7
|
||||||
|
Average total error: 2.0974234E7
|
||||||
|
Average total error: 2.3158012E7
|
||||||
|
Average total error: 2.6645172E7
|
||||||
|
Average total error: 2.6971466E7
|
||||||
|
Average total error: 2.2053082E7
|
||||||
|
Average total error: 2.0063062E7
|
||||||
|
Average total error: 2.9107796E7
|
||||||
|
Average total error: 2.5797774E7
|
||||||
|
Average total error: 2.9464382E7
|
||||||
|
Average total error: 1.6345746E7
|
||||||
|
Average total error: 2.2872656E7
|
||||||
|
Average total error: 2.6626478E7
|
||||||
|
Average total error: 2.4253808E7
|
||||||
|
Average total error: 3.2652544E7
|
||||||
|
Average total error: 3.1584964E7
|
||||||
|
Average total error: 3.2416886E7
|
||||||
|
Average total error: 3.328668E7
|
||||||
|
Average total error: 3.4721056E7
|
1522
results.txt
Normal file
1522
results.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,10 +8,6 @@
|
|||||||
(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
|
|
||||||
;; Passes into eval
|
|
||||||
; [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,16 +25,7 @@
|
|||||||
(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 problems
|
||||||
;; Creates PSB2 problems
|
|
||||||
;(when (= (first args) "PSB2")
|
|
||||||
;; For tomorrow, Figure out what this does?
|
|
||||||
;(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))))
|
(require (symbol (str "propeller.problems." (first args))))
|
||||||
(gp/gp
|
(gp/gp
|
||||||
(update-in
|
(update-in
|
||||||
|
60
src/propeller/problems/PSB2/fuel_cost.cljc
Normal file
60
src/propeller/problems/PSB2/fuel_cost.cljc
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
(ns propeller.problems.PSB2.fuel-cost
|
||||||
|
(: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]
|
||||||
|
[clojure.pprint :as pprint]
|
||||||
|
[propeller.tools.math :as math]))
|
||||||
|
|
||||||
|
;; Get path from text file
|
||||||
|
(def PSB2-path (slurp "PSB2_path.txt"))
|
||||||
|
|
||||||
|
; Random integer between -100 and 100 (from smallest)
|
||||||
|
(defn random-int [] (- (rand-int 201) 100))
|
||||||
|
|
||||||
|
(def train-and-test-data (psb2/fetch-examples PSB2-path "fuel-cost" 200 2000))
|
||||||
|
|
||||||
|
(def instructions
|
||||||
|
(utils/not-lazy
|
||||||
|
(concat
|
||||||
|
;;; stack-specific instructions
|
||||||
|
(get-stack-instructions #{:exec :integer :vector_integer :boolean :print})
|
||||||
|
;;; input instructions
|
||||||
|
(list :in1)
|
||||||
|
;;; close
|
||||||
|
(list 'close)
|
||||||
|
;;; ERCs (constants)
|
||||||
|
(list random-int 0 1 2 3))))
|
||||||
|
|
||||||
|
; Error function takes from integer stack, calculates error based on absolute value of
|
||||||
|
; difference between output and correct output.
|
||||||
|
(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)) data)
|
||||||
|
correct-outputs (map (fn [i] (get i :output1)) data)
|
||||||
|
outputs (map (fn [input]
|
||||||
|
(state/peek-stack
|
||||||
|
(interpreter/interpret-program
|
||||||
|
program
|
||||||
|
(assoc state/empty-state :input {:in1 input})
|
||||||
|
(:step-limit argmap))
|
||||||
|
:integer))
|
||||||
|
inputs)
|
||||||
|
errors (map (fn [correct-output output]
|
||||||
|
(if (= output :no-stack-item)
|
||||||
|
1000000
|
||||||
|
(min 1000.0 (math/abs (- correct-output output)))))
|
||||||
|
correct-outputs
|
||||||
|
outputs)]
|
||||||
|
(assoc individual
|
||||||
|
:behaviors outputs
|
||||||
|
:errors errors
|
||||||
|
:total-error #?(:clj (apply +' errors)
|
||||||
|
:cljs (apply + errors))))))
|
||||||
|
|
64
src/propeller/problems/PSB2/substitution_cipher.cljc
Normal file
64
src/propeller/problems/PSB2/substitution_cipher.cljc
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
(ns propeller.problems.PSB2.substitution-cipher
|
||||||
|
(: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]
|
||||||
|
[propeller.tools.metrics :as metrics]))
|
||||||
|
|
||||||
|
;; Get path from text file
|
||||||
|
(def PSB2-path (slurp "PSB2_path.txt"))
|
||||||
|
|
||||||
|
(def train-and-test-data (psb2/fetch-examples PSB2-path "substitution-cipher" 200 2000))
|
||||||
|
|
||||||
|
(def instructions
|
||||||
|
(utils/not-lazy
|
||||||
|
(concat
|
||||||
|
;;; stack-specific instructions
|
||||||
|
(get-stack-instructions #{:exec :integer :boolean :char :string :print})
|
||||||
|
;;; input instructions
|
||||||
|
(list :in1)
|
||||||
|
;;; close
|
||||||
|
(list 'close)
|
||||||
|
;;; ERCs (constants)
|
||||||
|
(list 0 ""))))
|
||||||
|
|
||||||
|
; Error function takes from integer stack, calculates error based on absolute value of
|
||||||
|
; difference between output and correct output.
|
||||||
|
(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)) data)
|
||||||
|
correct-outputs (map (fn [i] (get i :output1)) data)
|
||||||
|
outputs (map (fn [input]
|
||||||
|
(state/peek-stack
|
||||||
|
(interpreter/interpret-program
|
||||||
|
program
|
||||||
|
(assoc state/empty-state :input {:in1 (get input 0)
|
||||||
|
:in2 (get input 1)
|
||||||
|
:in3 (get input 2)})
|
||||||
|
(:step-limit argmap))
|
||||||
|
:string))
|
||||||
|
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]
|
||||||
|
(if (= output :no-stack-item)
|
||||||
|
10000
|
||||||
|
(metrics/levenshtein-distance correct-output output)))
|
||||||
|
correct-outputs
|
||||||
|
parsed-outputs)]
|
||||||
|
(assoc individual
|
||||||
|
:behaviors parsed-outputs
|
||||||
|
:errors errors
|
||||||
|
:total-error #?(:clj (apply +' errors)
|
||||||
|
:cljs (apply + errors))))))
|
||||||
|
|
@ -1,78 +0,0 @@
|
|||||||
(ns propeller.problems.PSB2-Problems
|
|
||||||
(: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"))
|
|
||||||
|
|
||||||
;; ** 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))))))
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
|||||||
[x]
|
[x]
|
||||||
(+ (* x x x) x 3))
|
(+ (* x x x) x 3))
|
||||||
|
|
||||||
;; Set of original propel instructions
|
; Set of original propel instructions
|
||||||
(def instructions
|
(def instructions
|
||||||
(list :in1
|
(list :in1
|
||||||
:integer_add
|
:integer_add
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
:float '()
|
:float '()
|
||||||
:input {}
|
:input {}
|
||||||
:integer '()
|
:integer '()
|
||||||
:output '()
|
:output '("")
|
||||||
:string '()
|
:string '()
|
||||||
:vector_boolean '()
|
:vector_boolean '()
|
||||||
:vector_float '()
|
:vector_float '()
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
;; =============================================================================
|
;; =============================================================================
|
||||||
|
|
||||||
;; Used by keep-number-reasonable as the maximum magnitude of any integer/float
|
;; Used by keep-number-reasonable as the maximum magnitude of any integer/float
|
||||||
(def max-number-magnitude 1.0E12)
|
(def max-number-magnitude 1.0E8)
|
||||||
|
|
||||||
;; Used by keep-number-reasonable as the minimum magnitude of any float
|
;; Used by keep-number-reasonable as the minimum magnitude of any float
|
||||||
(def min-number-magnitude 1.0E-10)
|
(def min-number-magnitude 1.0E-10)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user