diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 4af4474..3049c98 100644 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -65,8 +65,8 @@ (do (prn {:success-generation generation}) (prn {:total-test-error (:total-error (error-function argmap (:testing-data argmap) best-individual))}) - (if (:simplification? argmap) - (let [simplified-plushy (simplification/auto-simplify-plushy argmap (:plushy best-individual) (:simplification-steps argmap) error-function (:testing-data argmap) (:simplification-k argmap) (:simplification-verbose? argmap))] + (when (:simplification? argmap) + (let [simplified-plushy (simplification/auto-simplify-plushy (:plushy best-individual) error-function argmap)] (prn {:total-test-error-simplified (:total-error (error-function argmap (:testing-data argmap) (hash-map :plushy simplified-plushy)))})))) ;; (>= generation max-generations) diff --git a/src/propeller/problems/PSB2/camel_case.cljc b/src/propeller/problems/PSB2/camel_case.cljc index 99b20be..ba80c6b 100644 --- a/src/propeller/problems/PSB2/camel_case.cljc +++ b/src/propeller/problems/PSB2/camel_case.cljc @@ -78,19 +78,14 @@ (: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)] + outputs)] (assoc individual - :behaviors parsed-outputs + :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) :cljs (apply + errors))))) diff --git a/src/propeller/problems/PSB2/fizz_buzz.cljc b/src/propeller/problems/PSB2/fizz_buzz.cljc index 4b892e7..ee1f536 100644 --- a/src/propeller/problems/PSB2/fizz_buzz.cljc +++ b/src/propeller/problems/PSB2/fizz_buzz.cljc @@ -46,19 +46,14 @@ (: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 (str correct-output) (str output)))) + (metrics/levenshtein-distance correct-output output))) correct-outputs - parsed-outputs)] + outputs)] (assoc individual - :behaviors parsed-outputs + :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) :cljs (apply + errors))))) diff --git a/src/propeller/problems/PSB2/middle_character.cljc b/src/propeller/problems/PSB2/middle_character.cljc index f9a4b18..a665d9b 100644 --- a/src/propeller/problems/PSB2/middle_character.cljc +++ b/src/propeller/problems/PSB2/middle_character.cljc @@ -47,19 +47,14 @@ (: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 (str correct-output) (str output)))) + (metrics/levenshtein-distance correct-output output))) correct-outputs - parsed-outputs)] + outputs)] (assoc individual - :behaviors parsed-outputs + :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) :cljs (apply + errors))))) diff --git a/src/propeller/problems/PSB2/spin_words.cljc b/src/propeller/problems/PSB2/spin_words.cljc index 5698f7a..b25386a 100644 --- a/src/propeller/problems/PSB2/spin_words.cljc +++ b/src/propeller/problems/PSB2/spin_words.cljc @@ -74,19 +74,14 @@ (: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)] + outputs)] (assoc individual - :behaviors parsed-outputs + :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) :cljs (apply + errors))))) diff --git a/src/propeller/problems/PSB2/square_digits.cljc b/src/propeller/problems/PSB2/square_digits.cljc index bc3bc61..76b1a24 100644 --- a/src/propeller/problems/PSB2/square_digits.cljc +++ b/src/propeller/problems/PSB2/square_digits.cljc @@ -46,19 +46,14 @@ (: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 (str correct-output) (str output)))) + (metrics/levenshtein-distance correct-output output))) correct-outputs - parsed-outputs)] + outputs)] (assoc individual - :behaviors parsed-outputs + :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) :cljs (apply + errors))))) diff --git a/src/propeller/problems/PSB2/substitution_cipher.cljc b/src/propeller/problems/PSB2/substitution_cipher.cljc index 3f83e64..f6b5d49 100644 --- a/src/propeller/problems/PSB2/substitution_cipher.cljc +++ b/src/propeller/problems/PSB2/substitution_cipher.cljc @@ -59,19 +59,14 @@ (: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 (str correct-output) (str output)))) + (metrics/levenshtein-distance correct-output output))) correct-outputs - parsed-outputs)] + outputs)] (assoc individual - :behaviors parsed-outputs + :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) :cljs (apply + errors))))) diff --git a/src/propeller/problems/PSB2/twitter.cljc b/src/propeller/problems/PSB2/twitter.cljc index 3d70851..95273e2 100644 --- a/src/propeller/problems/PSB2/twitter.cljc +++ b/src/propeller/problems/PSB2/twitter.cljc @@ -50,19 +50,14 @@ (: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 (str correct-output) (str output)))) + (metrics/levenshtein-distance correct-output output))) correct-outputs - parsed-outputs)] + outputs)] (assoc individual - :behaviors parsed-outputs + :behaviors outputs :errors errors :total-error #?(:clj (apply +' errors) :cljs (apply + errors))))) diff --git a/src/propeller/push/instructions/numeric.cljc b/src/propeller/push/instructions/numeric.cljc index 2000771..059e781 100755 --- a/src/propeller/push/instructions/numeric.cljc +++ b/src/propeller/push/instructions/numeric.cljc @@ -121,9 +121,13 @@ :name "_from_string"} (fn [stack state] (make-instruction state - #(try ((if (= stack :integer) int float) (read-string %)) - #?(:clj (catch Exception e) - :cljs (catch js/Error. e))) + #(try (if (= stack :integer) + #?(:clj (Integer/parseInt %) + :cljs (js/parseInt %)) + #?(:clj (Float/parseFloat %) + :cljs (js/parseFloat %))) + #?(:clj (catch Exception e :ignore-instruction) + :cljs (catch js/Error e :ignore-instruction))) [:string] stack))) diff --git a/src/propeller/simplification.cljc b/src/propeller/simplification.cljc index fbd47b1..f896e38 100644 --- a/src/propeller/simplification.cljc +++ b/src/propeller/simplification.cljc @@ -13,7 +13,7 @@ "deletes the values at given set of indices" [indices plushy] (let [sorted-indices (sort > indices)] - (keep-indexed #(if (not (some #{%1} sorted-indices)) %2) plushy))) + (keep-indexed #(when (not (some #{%1} sorted-indices)) %2) plushy))) (defn delete-k-random [k plushy] @@ -21,13 +21,13 @@ (defn auto-simplify-plushy "naive auto-simplification" - [argmap plushy steps error-function training-data k verbose?] - (if verbose? (prn {:start-plushy-length (count plushy) :k k})) + [plushy error-function {:keys [simplification-steps training-data simplification-k simplification-verbose?] :as argmap}] + (when simplification-verbose? (prn {:start-plushy-length (count plushy) :k simplification-k})) (let [initial-errors (:errors (error-function argmap training-data {:plushy plushy}))] (loop [step 0 curr-plushy plushy] - (if (< steps step) - (do (if verbose? (prn {:final-plushy-length (count curr-plushy) :final-plushy curr-plushy})) curr-plushy) - (let [new-plushy (delete-k-random (rand-int k) curr-plushy) + (if (< simplification-steps step) + (do (when simplification-verbose? (prn {:final-plushy-length (count curr-plushy) :final-plushy curr-plushy})) curr-plushy) + (let [new-plushy (delete-k-random (rand-int simplification-k) curr-plushy) new-plushy-errors (:errors (error-function argmap training-data {:plushy new-plushy})) new-equal? (= new-plushy-errors initial-errors)] (recur (inc step)