From b8da169b543a00a3f3e84c5f74943a87e6a9f81c Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Wed, 14 Jul 2021 15:55:38 -0400 Subject: [PATCH 1/6] Make all problem files contain -main, gp call, and default argmap --- src/propeller/problems/PSB2/basement.cljc | 27 +++++-- .../problems/PSB2/bouncing_balls.cljc | 27 +++++-- src/propeller/problems/PSB2/bowling.cljc | 27 +++++-- src/propeller/problems/PSB2/camel_case.cljc | 27 +++++-- src/propeller/problems/PSB2/dice_game.cljc | 27 +++++-- src/propeller/problems/PSB2/fuel_cost.cljc | 27 +++++-- .../problems/PSB2/middle_character.cljc | 27 +++++-- .../problems/PSB2/substitution_cipher.cljc | 27 +++++-- src/propeller/problems/PSB2/twitter.cljc | 27 +++++-- src/propeller/problems/simple_regression.cljc | 27 +++++-- .../problems/software/number_io.cljc | 80 ++++++++++++------- src/propeller/problems/software/smallest.cljc | 80 ++++++++++++------- .../problems/string_classification.cljc | 27 +++++-- src/propeller/problems/valiant.cljc | 27 +++++-- 14 files changed, 350 insertions(+), 134 deletions(-) diff --git a/src/propeller/problems/PSB2/basement.cljc b/src/propeller/problems/PSB2/basement.cljc index 608d4f3..4c7abad 100644 --- a/src/propeller/problems/PSB2/basement.cljc +++ b/src/propeller/problems/PSB2/basement.cljc @@ -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)))))) diff --git a/src/propeller/problems/PSB2/bouncing_balls.cljc b/src/propeller/problems/PSB2/bouncing_balls.cljc index 1a4f053..0e2dc0b 100644 --- a/src/propeller/problems/PSB2/bouncing_balls.cljc +++ b/src/propeller/problems/PSB2/bouncing_balls.cljc @@ -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)))))) diff --git a/src/propeller/problems/PSB2/bowling.cljc b/src/propeller/problems/PSB2/bowling.cljc index f0cdbc9..20a15d0 100644 --- a/src/propeller/problems/PSB2/bowling.cljc +++ b/src/propeller/problems/PSB2/bowling.cljc @@ -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)}) \ No newline at end of file +(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)))))) \ No newline at end of file diff --git a/src/propeller/problems/PSB2/camel_case.cljc b/src/propeller/problems/PSB2/camel_case.cljc index ac6a04d..a82f54b 100644 --- a/src/propeller/problems/PSB2/camel_case.cljc +++ b/src/propeller/problems/PSB2/camel_case.cljc @@ -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)))))) diff --git a/src/propeller/problems/PSB2/dice_game.cljc b/src/propeller/problems/PSB2/dice_game.cljc index 3de73f9..3672695 100644 --- a/src/propeller/problems/PSB2/dice_game.cljc +++ b/src/propeller/problems/PSB2/dice_game.cljc @@ -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)))))) diff --git a/src/propeller/problems/PSB2/fuel_cost.cljc b/src/propeller/problems/PSB2/fuel_cost.cljc index 9769fff..162b7e3 100644 --- a/src/propeller/problems/PSB2/fuel_cost.cljc +++ b/src/propeller/problems/PSB2/fuel_cost.cljc @@ -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)))))) diff --git a/src/propeller/problems/PSB2/middle_character.cljc b/src/propeller/problems/PSB2/middle_character.cljc index d023e52..e935b5a 100644 --- a/src/propeller/problems/PSB2/middle_character.cljc +++ b/src/propeller/problems/PSB2/middle_character.cljc @@ -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)))))) diff --git a/src/propeller/problems/PSB2/substitution_cipher.cljc b/src/propeller/problems/PSB2/substitution_cipher.cljc index 4798660..b6b2a88 100644 --- a/src/propeller/problems/PSB2/substitution_cipher.cljc +++ b/src/propeller/problems/PSB2/substitution_cipher.cljc @@ -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)}) \ No newline at end of file +(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)))))) \ No newline at end of file diff --git a/src/propeller/problems/PSB2/twitter.cljc b/src/propeller/problems/PSB2/twitter.cljc index 1a386ec..17bc755 100644 --- a/src/propeller/problems/PSB2/twitter.cljc +++ b/src/propeller/problems/PSB2/twitter.cljc @@ -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)}) \ No newline at end of file +(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)))))) \ No newline at end of file diff --git a/src/propeller/problems/simple_regression.cljc b/src/propeller/problems/simple_regression.cljc index 6bcde53..2f96ffa 100755 --- a/src/propeller/problems/simple_regression.cljc +++ b/src/propeller/problems/simple_regression.cljc @@ -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)}) \ No newline at end of file +(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)))))) \ No newline at end of file diff --git a/src/propeller/problems/software/number_io.cljc b/src/propeller/problems/software/number_io.cljc index afc449d..f3e3191 100755 --- a/src/propeller/problems/software/number_io.cljc +++ b/src/propeller/problems/software/number_io.cljc @@ -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)))))) \ No newline at end of file diff --git a/src/propeller/problems/software/smallest.cljc b/src/propeller/problems/software/smallest.cljc index c48876b..4ee6280 100755 --- a/src/propeller/problems/software/smallest.cljc +++ b/src/propeller/problems/software/smallest.cljc @@ -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)))))) \ No newline at end of file diff --git a/src/propeller/problems/string_classification.cljc b/src/propeller/problems/string_classification.cljc index aa49c16..70fa252 100755 --- a/src/propeller/problems/string_classification.cljc +++ b/src/propeller/problems/string_classification.cljc @@ -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)}) \ No newline at end of file +(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)))))) \ No newline at end of file diff --git a/src/propeller/problems/valiant.cljc b/src/propeller/problems/valiant.cljc index 7cfc407..0c05192 100644 --- a/src/propeller/problems/valiant.cljc +++ b/src/propeller/problems/valiant.cljc @@ -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)))))) From 5240423f66876fa6ac412cc3948c74b7add8a793 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Wed, 14 Jul 2021 16:37:21 -0400 Subject: [PATCH 2/6] Update README; fix command-line handling of arguments --- README.md | 64 ++++++++++++++++--- src/propeller/problems/PSB2/basement.cljc | 2 +- .../problems/PSB2/bouncing_balls.cljc | 2 +- src/propeller/problems/PSB2/bowling.cljc | 2 +- src/propeller/problems/PSB2/camel_case.cljc | 2 +- src/propeller/problems/PSB2/dice_game.cljc | 2 +- src/propeller/problems/PSB2/fuel_cost.cljc | 2 +- .../problems/PSB2/middle_character.cljc | 2 +- .../problems/PSB2/substitution_cipher.cljc | 2 +- src/propeller/problems/PSB2/twitter.cljc | 2 +- src/propeller/problems/simple_regression.cljc | 2 +- .../problems/software/number_io.cljc | 2 +- src/propeller/problems/software/smallest.cljc | 2 +- .../problems/string_classification.cljc | 2 +- src/propeller/problems/valiant.cljc | 2 +- 15 files changed, 69 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 56511eb..6debf61 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,62 @@ Yet another Push-based genetic programming system in Clojure. ## Usage -To run PushGP from a REPL, load propel.core into your REPL (i.e. `lein repl`), -and run `-main` with arguments including, first, the problem name, for example: -`(-main 'simple-regression)` or `(-main 'simple-regression :population-size 100)`. +If you have installed [leiningen](https://leiningen.org), which is a tool +for running Clojure programs, then you can run Propeller on a genetic +programming problem that is defined within this project from the command +line with the command `lein run -m `, replacing `` +with the actual namespace that you will find at the top of the problem file. + +For example, you can run the simple-regression genetic programming problem with: + +``` +lein run -m propeller.problems.simple-regression +``` + +Additional command-line arguments may +be provided to override the default key/value pairs specified in the +problem file, for example: + + +``` +lein run -m propeller.problems.simple-regression :population-size 100 +``` + +On Unix operating systems, including MacOS, you can use something +like the following to send output both to the terminal +and to a text file (called `outfile` in this example): + +``` +lein run -m propeller.problems.simple-regression | tee outfile +``` + +If you want to provide command line arguments that include +characters that may be interpreted by your command line shell +before they get to Clojure, then enclose those in double +quotes, like in this example that provides a non-default +value for the `:variation` argument, which is a clojure map +containing curly brackets that may confuse your shell: + +``` +lein run -m propeller.problems.simple-regression :variation "{:umad 1.0}" +``` + +To run a genetic programming problem from a REPL, start +your REPL for the project (e.g. with `lein repl` at the +command line when in the project directory, or through your +IDE) and then do something like the following (which in +this case runs the simple-regression problem with +`:population-size` 100): + +``` +(require 'propeller.problems.simple-regression) +(in-ns 'propeller.problems.simple-regression) +(-main :population-size 100 :variation {:umad 1.0}) +``` + +If you want to run the problem with the default parameters, +then you should call `-main` without arguments, as `(-main)`. -To run PushGP on the genetic programming problem p from the -command line, execute `lein run p`. For example `lein run simple-regression`. Additional command-line arguments may -be provided to override the default key/value pairs specified in `-main`, for -example, `lein run simple-regression :population-size 100`. You can use something -like `lein run simple-regression | tee outfile` to send output both to the terminal -and to `outfile`. ## CLJS Usage diff --git a/src/propeller/problems/PSB2/basement.cljc b/src/propeller/problems/PSB2/basement.cljc index 4c7abad..fa80357 100644 --- a/src/propeller/problems/PSB2/basement.cljc +++ b/src/propeller/problems/PSB2/basement.cljc @@ -78,5 +78,5 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) diff --git a/src/propeller/problems/PSB2/bouncing_balls.cljc b/src/propeller/problems/PSB2/bouncing_balls.cljc index 0e2dc0b..0cab515 100644 --- a/src/propeller/problems/PSB2/bouncing_balls.cljc +++ b/src/propeller/problems/PSB2/bouncing_balls.cljc @@ -89,4 +89,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) diff --git a/src/propeller/problems/PSB2/bowling.cljc b/src/propeller/problems/PSB2/bowling.cljc index 20a15d0..6fd63b8 100644 --- a/src/propeller/problems/PSB2/bowling.cljc +++ b/src/propeller/problems/PSB2/bowling.cljc @@ -77,4 +77,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) \ No newline at end of file + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) \ No newline at end of file diff --git a/src/propeller/problems/PSB2/camel_case.cljc b/src/propeller/problems/PSB2/camel_case.cljc index a82f54b..3bc2447 100644 --- a/src/propeller/problems/PSB2/camel_case.cljc +++ b/src/propeller/problems/PSB2/camel_case.cljc @@ -113,4 +113,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) diff --git a/src/propeller/problems/PSB2/dice_game.cljc b/src/propeller/problems/PSB2/dice_game.cljc index 3672695..db669b5 100644 --- a/src/propeller/problems/PSB2/dice_game.cljc +++ b/src/propeller/problems/PSB2/dice_game.cljc @@ -86,4 +86,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) diff --git a/src/propeller/problems/PSB2/fuel_cost.cljc b/src/propeller/problems/PSB2/fuel_cost.cljc index 162b7e3..0f1592a 100644 --- a/src/propeller/problems/PSB2/fuel_cost.cljc +++ b/src/propeller/problems/PSB2/fuel_cost.cljc @@ -79,5 +79,5 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) diff --git a/src/propeller/problems/PSB2/middle_character.cljc b/src/propeller/problems/PSB2/middle_character.cljc index e935b5a..8b7e123 100644 --- a/src/propeller/problems/PSB2/middle_character.cljc +++ b/src/propeller/problems/PSB2/middle_character.cljc @@ -82,4 +82,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) diff --git a/src/propeller/problems/PSB2/substitution_cipher.cljc b/src/propeller/problems/PSB2/substitution_cipher.cljc index b6b2a88..554c203 100644 --- a/src/propeller/problems/PSB2/substitution_cipher.cljc +++ b/src/propeller/problems/PSB2/substitution_cipher.cljc @@ -94,4 +94,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) \ No newline at end of file + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) \ No newline at end of file diff --git a/src/propeller/problems/PSB2/twitter.cljc b/src/propeller/problems/PSB2/twitter.cljc index 17bc755..bdf35f7 100644 --- a/src/propeller/problems/PSB2/twitter.cljc +++ b/src/propeller/problems/PSB2/twitter.cljc @@ -85,4 +85,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) \ No newline at end of file + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) \ No newline at end of file diff --git a/src/propeller/problems/simple_regression.cljc b/src/propeller/problems/simple_regression.cljc index 2f96ffa..e0ed37d 100755 --- a/src/propeller/problems/simple_regression.cljc +++ b/src/propeller/problems/simple_regression.cljc @@ -78,4 +78,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) \ No newline at end of file + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) \ No newline at end of file diff --git a/src/propeller/problems/software/number_io.cljc b/src/propeller/problems/software/number_io.cljc index f3e3191..2acae61 100755 --- a/src/propeller/problems/software/number_io.cljc +++ b/src/propeller/problems/software/number_io.cljc @@ -108,4 +108,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) \ No newline at end of file + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) \ No newline at end of file diff --git a/src/propeller/problems/software/smallest.cljc b/src/propeller/problems/software/smallest.cljc index 4ee6280..a70ac59 100755 --- a/src/propeller/problems/software/smallest.cljc +++ b/src/propeller/problems/software/smallest.cljc @@ -110,4 +110,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) \ No newline at end of file + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) \ No newline at end of file diff --git a/src/propeller/problems/string_classification.cljc b/src/propeller/problems/string_classification.cljc index 70fa252..a06490d 100755 --- a/src/propeller/problems/string_classification.cljc +++ b/src/propeller/problems/string_classification.cljc @@ -98,4 +98,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) \ No newline at end of file + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) \ No newline at end of file diff --git a/src/propeller/problems/valiant.cljc b/src/propeller/problems/valiant.cljc index 0c05192..a98410a 100644 --- a/src/propeller/problems/valiant.cljc +++ b/src/propeller/problems/valiant.cljc @@ -77,4 +77,4 @@ :umad-rate 0.1 :variation {:umad 0.5 :crossover 0.5} :elitism false} - (apply hash-map (map read-string (rest args)))))) + (apply hash-map (map #(if (string? %) (read-string %) %) args))))) From 1cc2b26df200844e9c68707192cb42e3c196021b Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Wed, 14 Jul 2021 16:41:42 -0400 Subject: [PATCH 3/6] Update -main in propeller.core to just print a message --- src/propeller/core.cljc | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/src/propeller/core.cljc b/src/propeller/core.cljc index f33c73b..0023a41 100755 --- a/src/propeller/core.cljc +++ b/src/propeller/core.cljc @@ -1,34 +1,10 @@ (ns propeller.core - #?(:clj (:gen-class)) - (:require [propeller.gp :as gp] - #?(:cljs [cljs.reader :refer [read-string]]))) - -(defn eval-problem-var - [problem-name var-name] - (eval (symbol (str "propeller.problems." problem-name "/" var-name)))) + #?(:clj (:gen-class))) (defn -main - "Runs propel-gp, giving it a map of arguments." + "Not intended to be run; just print a message." [& args] ;; Exception for when no args were passed - (when (empty? args) - (println "You must specify a problem to run.") - (println "Try, for example:") - (println " lein run software.smallest") - (System/exit 1)) - (require (symbol (str "propeller.problems." (first args)))) - (gp/gp - (merge - {: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} - (eval-problem-var (first args) "arglist") - (apply hash-map - (map #(if (and (string? %) (not (.contains % "/"))) (read-string %) %) - (rest args)))))) \ No newline at end of file + (println "To run a genetic programming problem, provide a the problem's") + (println "namespace as specified in the Propeller README file at") + (println "https://github.com/lspector/propeller/blob/master/README.md")) \ No newline at end of file From 686ba1fdb242ac336d75f4c7da57d34e264298a7 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Wed, 14 Jul 2021 16:50:33 -0400 Subject: [PATCH 4/6] Remove unused require --- src/propeller/problems/PSB2/basement.cljc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/propeller/problems/PSB2/basement.cljc b/src/propeller/problems/PSB2/basement.cljc index fa80357..9143c0e 100644 --- a/src/propeller/problems/PSB2/basement.cljc +++ b/src/propeller/problems/PSB2/basement.cljc @@ -5,7 +5,6 @@ [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] [propeller.gp :as gp])) From cea5eaf5da83f9ca2df8be860143f535616d0e7a Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Wed, 14 Jul 2021 16:57:54 -0400 Subject: [PATCH 5/6] Remove .idea files from version control --- .idea/.gitignore | 2 -- .idea/ClojureProjectResolveSettings.xml | 6 ------ .idea/compiler.xml | 18 ------------------ .../Leiningen__clojure_complete_0_2_5.xml | 9 --------- .idea/libraries/Leiningen__nrepl_0_6_0.xml | 9 --------- .../Leiningen__org_clojure_clojure_1_10_0.xml | 9 --------- ...en__org_clojure_core_specs_alpha_0_2_44.xml | 9 --------- ...iningen__org_clojure_spec_alpha_0_2_176.xml | 9 --------- .idea/misc.xml | 13 ------------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 11 files changed, 98 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/ClojureProjectResolveSettings.xml delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/libraries/Leiningen__clojure_complete_0_2_5.xml delete mode 100644 .idea/libraries/Leiningen__nrepl_0_6_0.xml delete mode 100644 .idea/libraries/Leiningen__org_clojure_clojure_1_10_0.xml delete mode 100644 .idea/libraries/Leiningen__org_clojure_core_specs_alpha_0_2_44.xml delete mode 100644 .idea/libraries/Leiningen__org_clojure_spec_alpha_0_2_176.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 5c98b42..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/ClojureProjectResolveSettings.xml b/.idea/ClojureProjectResolveSettings.xml deleted file mode 100644 index df470b1..0000000 --- a/.idea/ClojureProjectResolveSettings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - IDE - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 9deeaef..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Leiningen__clojure_complete_0_2_5.xml b/.idea/libraries/Leiningen__clojure_complete_0_2_5.xml deleted file mode 100644 index c6f5338..0000000 --- a/.idea/libraries/Leiningen__clojure_complete_0_2_5.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Leiningen__nrepl_0_6_0.xml b/.idea/libraries/Leiningen__nrepl_0_6_0.xml deleted file mode 100644 index 5997b74..0000000 --- a/.idea/libraries/Leiningen__nrepl_0_6_0.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Leiningen__org_clojure_clojure_1_10_0.xml b/.idea/libraries/Leiningen__org_clojure_clojure_1_10_0.xml deleted file mode 100644 index 513d335..0000000 --- a/.idea/libraries/Leiningen__org_clojure_clojure_1_10_0.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Leiningen__org_clojure_core_specs_alpha_0_2_44.xml b/.idea/libraries/Leiningen__org_clojure_core_specs_alpha_0_2_44.xml deleted file mode 100644 index 0c20df3..0000000 --- a/.idea/libraries/Leiningen__org_clojure_core_specs_alpha_0_2_44.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Leiningen__org_clojure_spec_alpha_0_2_176.xml b/.idea/libraries/Leiningen__org_clojure_spec_alpha_0_2_176.xml deleted file mode 100644 index 31c7656..0000000 --- a/.idea/libraries/Leiningen__org_clojure_spec_alpha_0_2_176.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 97e4469..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index acfd354..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 8280c3c6d2689ae8c7e6faf1d80316be3eba7854 Mon Sep 17 00:00:00 2001 From: Shuzo Katayama <62683709+DuckNoodleSoup@users.noreply.github.com> Date: Wed, 14 Jul 2021 21:48:03 -0400 Subject: [PATCH 6/6] temporarily remove spin words I forgot to ignore this work in progress file from the last commit --- src/propeller/problems/PSB2/spin_words.cljc | 77 --------------------- 1 file changed, 77 deletions(-) delete mode 100644 src/propeller/problems/PSB2/spin_words.cljc diff --git a/src/propeller/problems/PSB2/spin_words.cljc b/src/propeller/problems/PSB2/spin_words.cljc deleted file mode 100644 index 43b04a3..0000000 --- a/src/propeller/problems/PSB2/spin_words.cljc +++ /dev/null @@ -1,77 +0,0 @@ -(ns propeller.problems.PSB2.spin-words - (: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.metrics :as metrics])) - -; =========== PROBLEM DESCRIPTION ============================== -; SPIN WORDS from PSB2 -; Given a string of one or more words -; (separated by spaces), reverse all of the words that are five -; or more letters long and return the resulting string. -; -; Source: https://arxiv.org/pdf/2106.06086.pdf -; ================================================================ - -(def train-and-test-data (psb2/fetch-examples "data" "spin-words" 200 2000)) - -; Visible character ERC -(defn random-char - [] - (rand-nth (map char (range 97 122)))) - -;; WORK ON THIS TOMORROW; -;; SPIN WORDS STRING ERC; - -(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 4 5 \space random-char )))) - - -(defn error-function - [argmap data individual] - (let [program (genome/plushy->push (:plushy individual) argmap) - 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)) - :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))))) - -(def arglist - {:instructions instructions - :error-function error-function - :training-data (:train train-and-test-data) - :testing-data (:test train-and-test-data)}) -