Make all problem files contain -main, gp call, and default argmap

This commit is contained in:
Lee Spector 2021-07-14 15:55:38 -04:00
parent 1698c51194
commit b8da169b54
14 changed files with 350 additions and 134 deletions

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[clojure.pprint :as pprint]
[propeller.tools.math :as math]))
[propeller.tools.math :as math]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION ============================
; BASEMENT from PSB2
@ -59,9 +60,23 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[clojure.pprint :as pprint]
[propeller.tools.math :as math]))
[propeller.tools.math :as math]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION ===============================
; BOUNCING BALLS from PSB2
@ -70,8 +71,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[clojure.pprint :as pprint]
[propeller.tools.math :as math]))
[propeller.tools.math :as math]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION ======================
; BOWLING from PSB2
@ -58,8 +59,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[propeller.tools.math :as math]
[propeller.tools.metrics :as metrics]))
[propeller.tools.metrics :as metrics]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION =====================================
; CAMEL CASE from PSB2
@ -94,8 +95,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[clojure.pprint :as pprint]
[propeller.tools.math :as math]))
[propeller.tools.math :as math]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION ===============================
; DICE GAME from PSB2
@ -67,8 +68,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[clojure.pprint :as pprint]
[propeller.tools.math :as math]))
[propeller.tools.math :as math]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION =========================
; FUEL COST from PSB2
@ -60,9 +61,23 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[propeller.tools.math :as math]
[propeller.tools.metrics :as metrics]))
[propeller.tools.metrics :as metrics]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION =============================
; MIDDLE CHARACTER from PSB2
@ -63,8 +64,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[propeller.tools.math :as math]
[propeller.tools.metrics :as metrics]))
[propeller.tools.metrics :as metrics]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION =========================
; SUBSTITUTION CIPHER from PSB2
@ -75,8 +76,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state]
[propeller.tools.math :as math]
[propeller.tools.metrics :as metrics]))
[propeller.tools.metrics :as metrics]
[propeller.gp :as gp]))
; =========== PROBLEM DESCRIPTION =============================
; TWITTER from PSB2
@ -66,8 +67,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -2,7 +2,8 @@
(:require [propeller.genome :as genome]
[propeller.push.interpreter :as interpreter]
[propeller.push.state :as state]
[propeller.tools.math :as math]))
[propeller.tools.math :as math]
[propeller.gp :as gp]))
(defn- target-function
"Target function: f(x) = x^3 + x + 3"
@ -59,8 +60,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors))))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -6,6 +6,7 @@
[propeller.utils :as utils]
[propeller.push.state :as state]
[propeller.tools.math :as math]
[propeller.gp :as gp]
#?(:cljs [cljs.reader :refer [read-string]])))
;; =============================================================================
@ -60,34 +61,51 @@
:test test-set}))
(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 (:inputs data)
correct-outputs (:outputs data)
outputs (map (fn [input]
(state/peek-stack
(interpreter/interpret-program
program
(assoc state/empty-state :input {:in1 (first input)
:in2 (last 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))))))
[argmap data individual]
(let [program (genome/plushy->push (:plushy individual) argmap)
inputs (:inputs data)
correct-outputs (:outputs data)
outputs (map (fn [input]
(state/peek-stack
(interpreter/interpret-program
program
(assoc state/empty-state :input {:in1 (first input)
:in2 (last 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)))))
(defn -main
"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))))))

View File

@ -5,6 +5,7 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.utils :as utils]
[propeller.push.state :as state]
[propeller.gp :as gp]
#?(:cljs [cljs.reader :refer [read-string]])))
;; =============================================================================
@ -62,34 +63,51 @@
:test test-set}))
(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 (:inputs data)
correct-outputs (:outputs 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)
:in4 (get input 3)}
:output '(""))
(:step-limit argmap))
:output))
inputs)
errors (map (fn [correct-output output]
(let [parsed-output (try (read-string output)
#?(:clj (catch Exception e 1000.0)
:cljs (catch js/Error. e 1000.0)))]
(if (= correct-output parsed-output) 0 1)))
correct-outputs
outputs)]
(assoc individual
:behaviors outputs
:errors errors
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors))))))
[argmap data individual]
(let [program (genome/plushy->push (:plushy individual) argmap)
inputs (:inputs data)
correct-outputs (:outputs 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)
:in4 (get input 3)}
:output '(""))
(:step-limit argmap))
:output))
inputs)
errors (map (fn [correct-output output]
(let [parsed-output (try (read-string output)
#?(:clj (catch Exception e 1000.0)
:cljs (catch js/Error. e 1000.0)))]
(if (= correct-output parsed-output) 0 1)))
correct-outputs
outputs)]
(assoc individual
:behaviors outputs
:errors errors
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(defn -main
"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))))))

View File

@ -1,7 +1,8 @@
(ns propeller.problems.string-classification
(:require [propeller.genome :as genome]
[propeller.push.interpreter :as interpreter]
[propeller.push.state :as state]))
[propeller.push.state :as state]
[propeller.gp :as gp]))
;; =============================================================================
;; String classification
@ -79,8 +80,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))

View File

@ -1,7 +1,8 @@
(ns propeller.problems.valiant
(:require [propeller.genome :as genome]
[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-inputs 50) ;5) ; 50) ;500)
@ -58,8 +59,22 @@
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors)))))
(def arglist
{:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})
(defn -main
"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))))))