This commit is contained in:
parent
2cead8b88d
commit
abec0ddf12
@ -8,6 +8,6 @@
|
|||||||
[org.clojure/test.check "1.1.0"]
|
[org.clojure/test.check "1.1.0"]
|
||||||
[net.clojars.schneau/psb2 "1.1.0"]]
|
[net.clojars.schneau/psb2 "1.1.0"]]
|
||||||
:main ^:skip-aot propeller.core
|
:main ^:skip-aot propeller.core
|
||||||
:repl-options {:init-ns propeller.core})
|
:repl-options {:init-ns propeller.core}
|
||||||
;:jvm-opts ^:replace [])
|
:jvm-opts ^:replace [])
|
||||||
|
|
||||||
|
@ -31,15 +31,10 @@
|
|||||||
:population-size 500
|
:population-size 500
|
||||||
:max-initial-plushy-size 100
|
:max-initial-plushy-size 100
|
||||||
:step-limit 200
|
:step-limit 200
|
||||||
;:max-generations 300
|
|
||||||
;:population-size 1000
|
|
||||||
;:max-initial-plushy-size 250
|
|
||||||
;:step-limit 2000
|
|
||||||
:parent-selection :lexicase
|
:parent-selection :lexicase
|
||||||
:tournament-size 5
|
:tournament-size 5
|
||||||
:umad-rate 0.1
|
:umad-rate 0.1
|
||||||
:variation {:umad 0.5 :crossover 0.5}
|
:variation {:umad 0.5 :crossover 0.5}
|
||||||
;:variation {:umad 1.0 :crossover 0.0}
|
|
||||||
:elitism false
|
:elitism false
|
||||||
:PSB2-path ""
|
:PSB2-path ""
|
||||||
:PSB2-problem (clojure.string/replace (first args) #"PSB2." "")}
|
:PSB2-problem (clojure.string/replace (first args) #"PSB2." "")}
|
||||||
@ -47,6 +42,4 @@
|
|||||||
(map #(if (and (string? %) (not (.contains % "/"))) (read-string %) %)
|
(map #(if (and (string? %) (not (.contains % "/"))) (read-string %) %)
|
||||||
(rest args))))
|
(rest args))))
|
||||||
[:error-function]
|
[:error-function]
|
||||||
identity)))
|
identity)))
|
||||||
|
|
||||||
;;keyword path as a separate argument lol
|
|
@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
; =========== PROBLEM DESCRIPTION =============================
|
; =========== PROBLEM DESCRIPTION =============================
|
||||||
; MIDDLE CHARACTER from PSB2
|
; MIDDLE CHARACTER from PSB2
|
||||||
;Given a string, return the middle
|
; Given a string, return the middle
|
||||||
;character as a string if it is odd length; return the two middle
|
; character as a string if it is odd length; return the two middle
|
||||||
;characters as a string if it is even length.
|
; characters as a string if it is even length.
|
||||||
;
|
;
|
||||||
; Source: https://arxiv.org/pdf/2106.06086.pdf
|
; Source: https://arxiv.org/pdf/2106.06086.pdf
|
||||||
; ===============================================================
|
; ===============================================================
|
||||||
|
70
src/propeller/problems/PSB2/twitter.cljc
Normal file
70
src/propeller/problems/PSB2/twitter.cljc
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
(ns propeller.problems.PSB2.twitter
|
||||||
|
(: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.math :as math]
|
||||||
|
[propeller.tools.metrics :as metrics]))
|
||||||
|
|
||||||
|
; =========== PROBLEM DESCRIPTION =============================
|
||||||
|
; TWITTER from PSB2
|
||||||
|
; Given a string representing a tweet, validate whether the tweet
|
||||||
|
; meets Twitter’s original character requirements. If the tweet
|
||||||
|
; has more than 140 characters, return the string "Too many characters".
|
||||||
|
; If the tweet is empty, return the string "You didn’t type anything".
|
||||||
|
; Otherwise, return "Your tweet has X characters", where
|
||||||
|
; the X is the number of characters in the tweet.
|
||||||
|
;
|
||||||
|
; Source: https://arxiv.org/pdf/2106.06086.pdf
|
||||||
|
; ===============================================================
|
||||||
|
|
||||||
|
(defn random-int [] (- (rand-int 201) 100))
|
||||||
|
|
||||||
|
(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 0 140 "Too many characters" "You didn't type anything" "your tweet has " " characters"))))
|
||||||
|
|
||||||
|
(defn error-function
|
||||||
|
([argmap individual]
|
||||||
|
(error-function argmap individual :train))
|
||||||
|
([argmap individual subset]
|
||||||
|
(let [program (genome/plushy->push (:plushy individual) argmap)
|
||||||
|
data (get (get argmap :train-and-test-data) subset)
|
||||||
|
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 (str correct-output) (str output))))
|
||||||
|
correct-outputs
|
||||||
|
parsed-outputs)]
|
||||||
|
(assoc individual
|
||||||
|
:behaviors parsed-outputs
|
||||||
|
:errors errors
|
||||||
|
:total-error #?(:clj (apply +' errors)
|
||||||
|
:cljs (apply + errors))))))
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user