Make all problem files contain -main, gp call, and default argmap
This commit is contained in:
parent
1698c51194
commit
b8da169b54
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[propeller.tools.math :as math]))
|
[propeller.tools.math :as math]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION ============================
|
; =========== PROBLEM DESCRIPTION ============================
|
||||||
; BASEMENT from PSB2
|
; BASEMENT from PSB2
|
||||||
@ -59,9 +60,23 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[propeller.tools.math :as math]))
|
[propeller.tools.math :as math]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION ===============================
|
; =========== PROBLEM DESCRIPTION ===============================
|
||||||
; BOUNCING BALLS from PSB2
|
; BOUNCING BALLS from PSB2
|
||||||
@ -70,8 +71,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[propeller.tools.math :as math]))
|
[propeller.tools.math :as math]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION ======================
|
; =========== PROBLEM DESCRIPTION ======================
|
||||||
; BOWLING from PSB2
|
; BOWLING from PSB2
|
||||||
@ -58,8 +59,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.tools.math :as math]
|
[propeller.tools.math :as math]
|
||||||
[propeller.tools.metrics :as metrics]))
|
[propeller.tools.metrics :as metrics]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION =====================================
|
; =========== PROBLEM DESCRIPTION =====================================
|
||||||
; CAMEL CASE from PSB2
|
; CAMEL CASE from PSB2
|
||||||
@ -94,8 +95,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[propeller.tools.math :as math]))
|
[propeller.tools.math :as math]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION ===============================
|
; =========== PROBLEM DESCRIPTION ===============================
|
||||||
; DICE GAME from PSB2
|
; DICE GAME from PSB2
|
||||||
@ -67,8 +68,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[propeller.tools.math :as math]))
|
[propeller.tools.math :as math]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION =========================
|
; =========== PROBLEM DESCRIPTION =========================
|
||||||
; FUEL COST from PSB2
|
; FUEL COST from PSB2
|
||||||
@ -60,9 +61,23 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.tools.math :as math]
|
[propeller.tools.math :as math]
|
||||||
[propeller.tools.metrics :as metrics]))
|
[propeller.tools.metrics :as metrics]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION =============================
|
; =========== PROBLEM DESCRIPTION =============================
|
||||||
; MIDDLE CHARACTER from PSB2
|
; MIDDLE CHARACTER from PSB2
|
||||||
@ -63,8 +64,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.tools.math :as math]
|
[propeller.tools.math :as math]
|
||||||
[propeller.tools.metrics :as metrics]))
|
[propeller.tools.metrics :as metrics]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION =========================
|
; =========== PROBLEM DESCRIPTION =========================
|
||||||
; SUBSTITUTION CIPHER from PSB2
|
; SUBSTITUTION CIPHER from PSB2
|
||||||
@ -75,8 +76,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
@ -6,7 +6,8 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.tools.math :as math]
|
[propeller.tools.math :as math]
|
||||||
[propeller.tools.metrics :as metrics]))
|
[propeller.tools.metrics :as metrics]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION =============================
|
; =========== PROBLEM DESCRIPTION =============================
|
||||||
; TWITTER from PSB2
|
; TWITTER from PSB2
|
||||||
@ -66,8 +67,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
@ -2,7 +2,8 @@
|
|||||||
(:require [propeller.genome :as genome]
|
(:require [propeller.genome :as genome]
|
||||||
[propeller.push.interpreter :as interpreter]
|
[propeller.push.interpreter :as interpreter]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.tools.math :as math]))
|
[propeller.tools.math :as math]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
(defn- target-function
|
(defn- target-function
|
||||||
"Target function: f(x) = x^3 + x + 3"
|
"Target function: f(x) = x^3 + x + 3"
|
||||||
@ -59,8 +60,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors))))))
|
:cljs (apply + errors))))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
@ -6,6 +6,7 @@
|
|||||||
[propeller.utils :as utils]
|
[propeller.utils :as utils]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.tools.math :as math]
|
[propeller.tools.math :as math]
|
||||||
|
[propeller.gp :as gp]
|
||||||
#?(:cljs [cljs.reader :refer [read-string]])))
|
#?(:cljs [cljs.reader :refer [read-string]])))
|
||||||
|
|
||||||
;; =============================================================================
|
;; =============================================================================
|
||||||
@ -60,34 +61,51 @@
|
|||||||
:test test-set}))
|
:test test-set}))
|
||||||
|
|
||||||
(defn error-function
|
(defn error-function
|
||||||
([argmap individual]
|
[argmap data individual]
|
||||||
(error-function argmap individual :train))
|
(let [program (genome/plushy->push (:plushy individual) argmap)
|
||||||
([argmap individual subset]
|
inputs (:inputs data)
|
||||||
(let [program (genome/plushy->push (:plushy individual) argmap)
|
correct-outputs (:outputs data)
|
||||||
data (get train-and-test-data subset)
|
outputs (map (fn [input]
|
||||||
inputs (:inputs data)
|
(state/peek-stack
|
||||||
correct-outputs (:outputs data)
|
(interpreter/interpret-program
|
||||||
outputs (map (fn [input]
|
program
|
||||||
(state/peek-stack
|
(assoc state/empty-state :input {:in1 (first input)
|
||||||
(interpreter/interpret-program
|
:in2 (last input)}
|
||||||
program
|
:output '(""))
|
||||||
(assoc state/empty-state :input {:in1 (first input)
|
(:step-limit argmap))
|
||||||
:in2 (last input)}
|
:output))
|
||||||
:output '(""))
|
inputs)
|
||||||
(:step-limit argmap))
|
parsed-outputs (map (fn [output]
|
||||||
:output))
|
(try (read-string output)
|
||||||
inputs)
|
#?(:clj (catch Exception e 1000.0)
|
||||||
parsed-outputs (map (fn [output]
|
:cljs (catch js/Error. e 1000.0))))
|
||||||
(try (read-string output)
|
outputs)
|
||||||
#?(:clj (catch Exception e 1000.0)
|
errors (map (fn [correct-output output]
|
||||||
:cljs (catch js/Error. e 1000.0))))
|
(min 1000.0 (math/abs (- correct-output output))))
|
||||||
outputs)
|
correct-outputs
|
||||||
errors (map (fn [correct-output output]
|
parsed-outputs)]
|
||||||
(min 1000.0 (math/abs (- correct-output output))))
|
(assoc individual
|
||||||
correct-outputs
|
:behaviors parsed-outputs
|
||||||
parsed-outputs)]
|
:errors errors
|
||||||
(assoc individual
|
:total-error #?(:clj (apply +' errors)
|
||||||
:behaviors parsed-outputs
|
:cljs (apply + errors)))))
|
||||||
:errors errors
|
|
||||||
:total-error #?(:clj (apply +' errors)
|
(defn -main
|
||||||
:cljs (apply + errors))))))
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
|
[& args]
|
||||||
|
(gp/gp
|
||||||
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
@ -5,6 +5,7 @@
|
|||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.utils :as utils]
|
[propeller.utils :as utils]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
|
[propeller.gp :as gp]
|
||||||
#?(:cljs [cljs.reader :refer [read-string]])))
|
#?(:cljs [cljs.reader :refer [read-string]])))
|
||||||
|
|
||||||
;; =============================================================================
|
;; =============================================================================
|
||||||
@ -62,34 +63,51 @@
|
|||||||
:test test-set}))
|
:test test-set}))
|
||||||
|
|
||||||
(defn error-function
|
(defn error-function
|
||||||
([argmap individual]
|
[argmap data individual]
|
||||||
(error-function argmap individual :train))
|
(let [program (genome/plushy->push (:plushy individual) argmap)
|
||||||
([argmap individual subset]
|
inputs (:inputs data)
|
||||||
(let [program (genome/plushy->push (:plushy individual) argmap)
|
correct-outputs (:outputs data)
|
||||||
data (get train-and-test-data subset)
|
outputs (map (fn [input]
|
||||||
inputs (:inputs data)
|
(state/peek-stack
|
||||||
correct-outputs (:outputs data)
|
(interpreter/interpret-program
|
||||||
outputs (map (fn [input]
|
program
|
||||||
(state/peek-stack
|
(assoc state/empty-state :input {:in1 (get input 0)
|
||||||
(interpreter/interpret-program
|
:in2 (get input 1)
|
||||||
program
|
:in3 (get input 2)
|
||||||
(assoc state/empty-state :input {:in1 (get input 0)
|
:in4 (get input 3)}
|
||||||
:in2 (get input 1)
|
:output '(""))
|
||||||
:in3 (get input 2)
|
(:step-limit argmap))
|
||||||
:in4 (get input 3)}
|
:output))
|
||||||
:output '(""))
|
inputs)
|
||||||
(:step-limit argmap))
|
errors (map (fn [correct-output output]
|
||||||
:output))
|
(let [parsed-output (try (read-string output)
|
||||||
inputs)
|
#?(:clj (catch Exception e 1000.0)
|
||||||
errors (map (fn [correct-output output]
|
:cljs (catch js/Error. e 1000.0)))]
|
||||||
(let [parsed-output (try (read-string output)
|
(if (= correct-output parsed-output) 0 1)))
|
||||||
#?(:clj (catch Exception e 1000.0)
|
correct-outputs
|
||||||
:cljs (catch js/Error. e 1000.0)))]
|
outputs)]
|
||||||
(if (= correct-output parsed-output) 0 1)))
|
(assoc individual
|
||||||
correct-outputs
|
:behaviors outputs
|
||||||
outputs)]
|
:errors errors
|
||||||
(assoc individual
|
:total-error #?(:clj (apply +' errors)
|
||||||
:behaviors outputs
|
:cljs (apply + errors)))))
|
||||||
:errors errors
|
|
||||||
:total-error #?(:clj (apply +' errors)
|
(defn -main
|
||||||
:cljs (apply + errors))))))
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
|
[& args]
|
||||||
|
(gp/gp
|
||||||
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
@ -1,7 +1,8 @@
|
|||||||
(ns propeller.problems.string-classification
|
(ns propeller.problems.string-classification
|
||||||
(:require [propeller.genome :as genome]
|
(:require [propeller.genome :as genome]
|
||||||
[propeller.push.interpreter :as interpreter]
|
[propeller.push.interpreter :as interpreter]
|
||||||
[propeller.push.state :as state]))
|
[propeller.push.state :as state]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
;; =============================================================================
|
;; =============================================================================
|
||||||
;; String classification
|
;; String classification
|
||||||
@ -79,8 +80,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
@ -1,7 +1,8 @@
|
|||||||
(ns propeller.problems.valiant
|
(ns propeller.problems.valiant
|
||||||
(:require [propeller.genome :as genome]
|
(:require [propeller.genome :as genome]
|
||||||
[propeller.push.interpreter :as interpreter]
|
[propeller.push.interpreter :as interpreter]
|
||||||
[propeller.push.state :as state]))
|
[propeller.push.state :as state]
|
||||||
|
[propeller.gp :as gp]))
|
||||||
|
|
||||||
(def num-vars 100) ;10) ;100) ;1000)
|
(def num-vars 100) ;10) ;100) ;1000)
|
||||||
(def num-inputs 50) ;5) ; 50) ;500)
|
(def num-inputs 50) ;5) ; 50) ;500)
|
||||||
@ -58,8 +59,22 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors)))))
|
:cljs (apply + errors)))))
|
||||||
|
|
||||||
(def arglist
|
(defn -main
|
||||||
{:instructions instructions
|
"Runs propel-gp, giving it a map of arguments."
|
||||||
:error-function error-function
|
[& args]
|
||||||
:training-data (:train train-and-test-data)
|
(gp/gp
|
||||||
:testing-data (:test train-and-test-data)})
|
(merge
|
||||||
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)
|
||||||
|
:max-generations 500
|
||||||
|
:population-size 500
|
||||||
|
:max-initial-plushy-size 100
|
||||||
|
:step-limit 200
|
||||||
|
:parent-selection :lexicase
|
||||||
|
:tournament-size 5
|
||||||
|
:umad-rate 0.1
|
||||||
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
|
:elitism false}
|
||||||
|
(apply hash-map (map read-string (rest args))))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user