diff --git a/src/propeller/problems/string_classification.cljc b/src/propeller/problems/string_classification.cljc index 42677c0..d6d0c0a 100755 --- a/src/propeller/problems/string_classification.cljc +++ b/src/propeller/problems/string_classification.cljc @@ -27,7 +27,7 @@ :string_reverse :string_concat :string_length - :string_includes? + :string_contains 'close 0 1 @@ -40,33 +40,45 @@ "G" "T")) +(defn train-and-test-data + [] + (let [train-inputs ["GCG" "GACAG" "AGAAG" "CCCA" "GATTACA" "TAGG" "GACT"] + test-inputs ["GCGT" "GACTTAG" "AGTAAG" "TCCTCA" "GAACA" "AGG" "GAC"]] + {:train {:inputs train-inputs + :outputs [false false false false true true true]} + :test {:inputs test-inputs + :outputs [true true true true false false false]}})) + (defn error-function "Finds the behaviors and errors of an individual: Error is 0 if the value and the program's selected behavior match, or 1 if they differ, or 1000000 if no behavior is produced. The behavior is here defined as the final top item on the BOOLEAN stack." - [argmap individual] - (let [program (genome/plushy->push (:plushy individual) argmap) - inputs ["GCG" "GACAG" "AGAAG" "CCCA" "GATTACA" "TAGG" "GACT"] - correct-outputs [false false false false true true true] - outputs (map (fn [input] - (state/peek-stack - (interpreter/interpret-program - program - (assoc state/empty-state :input {:in1 input}) - (:step-limit argmap)) - :boolean)) - inputs) - errors (map (fn [correct-output output] - (if (= output :no-stack-item) - 1000000 - (if (= correct-output output) - 0 - 1))) - correct-outputs - outputs)] - (assoc individual - :behaviors outputs - :errors errors - :total-error #?(:clj (apply +' errors) - :cljs (apply + errors))))) \ No newline at end of file + ([argmap individual] + (error-function argmap individual :train)) + ([argmap individual subset] + (let [program (genome/plushy->push (:plushy individual) argmap) + data (get (train-and-test-data) subset) + inputs (:inputs data) + correct-outputs (:outputs data) + outputs (map (fn [input] + (state/peek-stack + (interpreter/interpret-program + program + (assoc state/empty-state :input {:in1 input}) + (:step-limit argmap)) + :boolean)) + inputs) + errors (map (fn [correct-output output] + (if (= output :no-stack-item) + 1000000 + (if (= correct-output output) + 0 + 1))) + correct-outputs + outputs)] + (assoc individual + :behaviors outputs + :errors errors + :total-error #?(:clj (apply +' errors) + :cljs (apply + errors)))))) diff --git a/src/propeller/session.cljc b/src/propeller/session.cljc index 9c54e98..20d62a6 100755 --- a/src/propeller/session.cljc +++ b/src/propeller/session.cljc @@ -135,4 +135,20 @@ ;:umad 1 } :elitism false - :diploid true}) \ No newline at end of file + :diploid true}) + +#_(gp/gp {:instructions propeller.problems.string-classification/instructions + :error-function propeller.problems.string-classification/error-function + :max-generations 500 + :population-size 500 + :max-initial-plushy-size 100 + :step-limit 200 + :parent-selection :lexicase + :tournament-size 5 + :umad-rate 0.1 + :diploid-flip-rate 0.1 + :variation {:umad 0.8 + :diploid-flip 0.2 + } + :elitism false + :diploid true})