Update substitution-cipher for new problem specification scheme
This commit is contained in:
parent
3616293dc9
commit
b2fb5b1f53
@ -19,6 +19,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" "substitution-cipher" 200 2000))
|
||||||
|
|
||||||
(defn map-vals-input
|
(defn map-vals-input
|
||||||
"Returns all the input values of a map (specific helper method for substitution-cipher)"
|
"Returns all the input values of a map (specific helper method for substitution-cipher)"
|
||||||
[i]
|
[i]
|
||||||
@ -42,36 +44,39 @@
|
|||||||
(list 0 ""))))
|
(list 0 ""))))
|
||||||
|
|
||||||
(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] (map-vals-input i)) data)
|
||||||
(let [program (genome/plushy->push (:plushy individual) argmap)
|
correct-outputs (map (fn [i] (map-vals-output i)) data)
|
||||||
data (get (get argmap :train-and-test-data) subset)
|
outputs (map (fn [input]
|
||||||
inputs (map (fn [i] (map-vals-input i)) data)
|
(state/peek-stack
|
||||||
correct-outputs (map (fn [i] (map-vals-output i)) data)
|
(interpreter/interpret-program
|
||||||
outputs (map (fn [input]
|
program
|
||||||
(state/peek-stack
|
(assoc state/empty-state :input {:in1 (nth input 0)
|
||||||
(interpreter/interpret-program
|
:in2 (nth input 1)
|
||||||
program
|
:in3 (nth input 2)})
|
||||||
(assoc state/empty-state :input {:in1 (nth input 0)
|
(:step-limit argmap))
|
||||||
:in2 (nth input 1)
|
:string))
|
||||||
:in3 (nth input 2)})
|
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)
|
(def arglist
|
||||||
:cljs (apply + errors))))))
|
{:instructions instructions
|
||||||
|
:error-function error-function
|
||||||
|
:training-data (:train train-and-test-data)
|
||||||
|
:testing-data (:test train-and-test-data)})
|
Loading…
x
Reference in New Issue
Block a user