Update fuel_cost.cljc
This commit is contained in:
parent
6f152a0357
commit
b5953d3779
@ -2,6 +2,7 @@
|
|||||||
(:require [psb2.core :as psb2]
|
(:require [psb2.core :as psb2]
|
||||||
[propeller.genome :as genome]
|
[propeller.genome :as genome]
|
||||||
[propeller.push.interpreter :as interpreter]
|
[propeller.push.interpreter :as interpreter]
|
||||||
|
[propeller.problems.data-creation :as dc]
|
||||||
[propeller.utils :as utils]
|
[propeller.utils :as utils]
|
||||||
[propeller.push.instructions :refer [get-stack-instructions]]
|
[propeller.push.instructions :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
@ -19,22 +20,23 @@
|
|||||||
; Source: https://arxiv.org/pdf/2106.06086.pdf
|
; Source: https://arxiv.org/pdf/2106.06086.pdf
|
||||||
; ============================================================
|
; ============================================================
|
||||||
|
|
||||||
(def train-and-test-data (psb2/fetch-examples "data" "fuel-cost" 200 2000))
|
(def train-data (dc/read-data-that-has-no-strings "fuel-cost" "train"))
|
||||||
|
(def test-data (dc/read-data-that-has-no-strings "fuel-cost" "test"))
|
||||||
|
|
||||||
; Random integer between -100 and 100 (from smallest)
|
; Random integer between -100 and 100 (from smallest)
|
||||||
(defn random-int [] (- (rand-int 201) 100))
|
(defn random-int [] (- (rand-int 201) 100))
|
||||||
|
|
||||||
(def instructions
|
(def instructions
|
||||||
(utils/not-lazy
|
(utils/not-lazy
|
||||||
(concat
|
(concat
|
||||||
;;; stack-specific instructions
|
;;; stack-specific instructions
|
||||||
(get-stack-instructions #{:exec :integer :boolean :vector_integer :print})
|
(get-stack-instructions #{:exec :integer :boolean :vector_integer :print})
|
||||||
;;; input instructions
|
;;; input instructions
|
||||||
(list :in1)
|
(list :in1)
|
||||||
;;; close
|
;;; close
|
||||||
(list 'close)
|
(list 'close)
|
||||||
;;; ERCs (constants)
|
;;; ERCs (constants)
|
||||||
(list random-int 0 1 2 3))))
|
(list random-int 0 1 2 3))))
|
||||||
|
|
||||||
(defn error-function
|
(defn error-function
|
||||||
[argmap data individual]
|
[argmap data individual]
|
||||||
@ -43,11 +45,11 @@
|
|||||||
correct-outputs (map (fn [i] (get i :output1)) data)
|
correct-outputs (map (fn [i] (get i :output1)) data)
|
||||||
outputs (map (fn [input]
|
outputs (map (fn [input]
|
||||||
(state/peek-stack
|
(state/peek-stack
|
||||||
(interpreter/interpret-program
|
(interpreter/interpret-program
|
||||||
program
|
program
|
||||||
(assoc state/empty-state :input {:in1 input})
|
(assoc state/empty-state :input {:in1 input})
|
||||||
(:step-limit argmap))
|
(:step-limit argmap))
|
||||||
:integer))
|
:integer))
|
||||||
inputs)
|
inputs)
|
||||||
errors (map (fn [correct-output output]
|
errors (map (fn [correct-output output]
|
||||||
(if (= output :no-stack-item)
|
(if (= output :no-stack-item)
|
||||||
@ -56,31 +58,31 @@
|
|||||||
correct-outputs
|
correct-outputs
|
||||||
outputs)]
|
outputs)]
|
||||||
(assoc individual
|
(assoc individual
|
||||||
: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 -main
|
(defn -main
|
||||||
"Runs propel-gp, giving it a map of arguments."
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
[& args]
|
[& args]
|
||||||
(gp/gp
|
(gp/gp
|
||||||
(merge
|
(merge
|
||||||
{:instructions instructions
|
{:instructions instructions
|
||||||
:error-function error-function
|
:error-function error-function
|
||||||
:training-data (:train train-and-test-data)
|
:training-data train-data
|
||||||
:testing-data (:test train-and-test-data)
|
:testing-data test-data
|
||||||
:case-t-size (count (:train train-and-test-data))
|
:case-t-size (count train-data)
|
||||||
:case-parent-rate 0
|
:case-parent-rate 0
|
||||||
:case-parent-gens 1
|
:case-parent-gens 1
|
||||||
:max-generations 300
|
:max-generations 300
|
||||||
:population-size 1000
|
:population-size 1000
|
||||||
:max-initial-plushy-size 250
|
:max-initial-plushy-size 250
|
||||||
:step-limit 2000
|
:step-limit 2000
|
||||||
:parent-selection :lexicase
|
:parent-selection :lexicase
|
||||||
:tournament-size 5
|
:tournament-size 5
|
||||||
:umad-rate 0.1
|
:umad-rate 0.1
|
||||||
:variation {:umad 1.0 :crossover 0.0}
|
:variation {:umad 1.0 :crossover 0.0}
|
||||||
:elitism false}
|
:elitism false}
|
||||||
(apply hash-map (map #(if (string? %) (read-string %) %) args))))
|
(apply hash-map (map #(if (string? %) (read-string %) %) args))))
|
||||||
(#?(:clj shutdown-agents)))
|
(#?(:clj shutdown-agents)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user