From a7deb0361112173509e93e068c17568a77a0375c Mon Sep 17 00:00:00 2001 From: Shuzo Katayama Date: Tue, 13 Jul 2021 11:56:49 -0400 Subject: [PATCH] fixed argmap and levenshtein distance --- src/propeller/core.cljc | 10 ++++---- src/propeller/gp.cljc | 24 +++++++++---------- .../problems/PSB2/substitution_cipher.cljc | 2 +- src/propeller/tools/metrics.cljc | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/propeller/core.cljc b/src/propeller/core.cljc index 713fa41..e85cab7 100755 --- a/src/propeller/core.cljc +++ b/src/propeller/core.cljc @@ -27,14 +27,14 @@ (merge {:instructions (eval-problem-var (first args) "instructions") :error-function (eval-problem-var (first args) "error-function") - :max-generations 300 - :population-size 1000 - :max-initial-plushy-size 250 - :step-limit 2000 + :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 1.0 :crossover 0.0} + :variation {:umad 0.5 :crossover 0.5} :elitism false :PSB2-path "" :PSB2-problem (clojure.string/replace (first args) #"PSB2." "")} diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index c151ecf..6774a3e 100755 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -17,16 +17,16 @@ "Reports information each generation." [pop generation argmap] (let [best (first pop)] - (println {:generation generation - :best-plushy (:plushy best) - :best-program (genome/plushy->push (:plushy best) argmap) - :best-total-error (:total-error best) - :best-errors (:errors best) - :best-behaviors (:behaviors best) - :genotypic-diversity (float (/ (count (distinct (map :plushy pop))) (count pop))) - :behavioral-diversity (float (/ (count (distinct (map :behaviors pop))) (count pop))) - :average-genome-length (float (/ (reduce + (map count (map :plushy pop))) (count pop))) - :average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))}) + (clojure.pprint/pprint {:generation generation + :best-plushy (:plushy best) + :best-program (genome/plushy->push (:plushy best) argmap) + :best-total-error (:total-error best) + :best-errors (:errors best) + :best-behaviors (:behaviors best) + :genotypic-diversity (float (/ (count (distinct (map :plushy pop))) (count pop))) + :behavioral-diversity (float (/ (count (distinct (map :behaviors pop))) (count pop))) + :average-genome-length (float (/ (reduce + (map count (map :plushy pop))) (count pop))) + :average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))}) (println))) ; (clojure.pprint/pprint @@ -43,7 +43,7 @@ (let [PSB2-data (if (= PSB2-path "") #{} (psb2/fetch-examples PSB2-path PSB2-problem 200 2000)) - enhanced-argmap (assoc argmap :train-and-test-data PSB2-data)] + argmap (assoc argmap :train-and-test-data PSB2-data)] (loop [generation 0 population (repeatedly @@ -54,7 +54,7 @@ (let [evaluated-pop (sort-by :total-error (#?(:clj pmap :cljs map) - (partial error-function enhanced-argmap) population)) + (partial error-function argmap) population)) best-individual (first evaluated-pop)] (report evaluated-pop generation argmap) (cond diff --git a/src/propeller/problems/PSB2/substitution_cipher.cljc b/src/propeller/problems/PSB2/substitution_cipher.cljc index c29ef3f..83d96d2 100644 --- a/src/propeller/problems/PSB2/substitution_cipher.cljc +++ b/src/propeller/problems/PSB2/substitution_cipher.cljc @@ -68,7 +68,7 @@ errors (map (fn [correct-output output] (if (= output :no-stack-item) 10000 - (metrics/levenshtein-distance correct-output output))) + (metrics/levenshtein-distance (str correct-output) (str output)))) correct-outputs parsed-outputs)] (assoc individual diff --git a/src/propeller/tools/metrics.cljc b/src/propeller/tools/metrics.cljc index 156265f..bebd992 100755 --- a/src/propeller/tools/metrics.cljc +++ b/src/propeller/tools/metrics.cljc @@ -75,7 +75,7 @@ ;; we need to initialize the prev-row with the edit distance ;; between the various prefixes of b and the empty string (range (inc (count (str b)))) - (str a))))) + (str a)))) (defn sequence-similarity "Returns a number between 0 and 1, indicating how similar the sequences are