Update twitter for new problem specification scheme

This commit is contained in:
Lee Spector 2021-07-13 23:01:19 -04:00
parent b2fb5b1f53
commit 20be7c04e3

View File

@ -20,6 +20,8 @@
; Source: https://arxiv.org/pdf/2106.06086.pdf ; Source: https://arxiv.org/pdf/2106.06086.pdf
; =============================================================== ; ===============================================================
(def train-and-test-data (psb2/fetch-examples "data" "twitter" 200 2000))
(defn random-int [] (- (rand-int 201) 100)) (defn random-int [] (- (rand-int 201) 100))
(def instructions (def instructions
@ -35,36 +37,37 @@
(list 0 140 "Too many characters" "You didn't type anything" "your tweet has " " characters")))) (list 0 140 "Too many characters" "You didn't type anything" "your tweet has " " characters"))))
(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 (map (fn [i] (get i :input1)) data)
(let [program (genome/plushy->push (:plushy individual) argmap) correct-outputs (map (fn [i] (get i :output1)) data)
data (get (get argmap :train-and-test-data) subset) outputs (map (fn [input]
inputs (map (fn [i] (get i :input1)) data) (state/peek-stack
correct-outputs (map (fn [i] (get i :output1)) data) (interpreter/interpret-program
outputs (map (fn [input] program
(state/peek-stack (assoc state/empty-state :input {:in1 input})
(interpreter/interpret-program (:step-limit argmap))
program :string))
(assoc state/empty-state :input {:in1 input}) inputs)
(:step-limit argmap)) parsed-outputs (map (fn [output]
:string)) (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)))) (if (= output :no-stack-item)
outputs) 10000
errors (map (fn [correct-output output] (metrics/levenshtein-distance (str correct-output) (str output))))
(if (= output :no-stack-item) correct-outputs
10000 parsed-outputs)]
(metrics/levenshtein-distance (str correct-output) (str 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)
: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)})