Fix string-classification problem by adding train-and-test-data and fixing wrong instruction name

This commit is contained in:
Lee Spector 2020-11-29 22:09:36 -05:00
parent 0c6ebde41b
commit 4783d6695a
2 changed files with 55 additions and 27 deletions

View File

@ -27,7 +27,7 @@
:string_reverse :string_reverse
:string_concat :string_concat
:string_length :string_length
:string_includes? :string_contains
'close 'close
0 0
1 1
@ -40,33 +40,45 @@
"G" "G"
"T")) "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 (defn error-function
"Finds the behaviors and errors of an individual: Error is 0 if the value and "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 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 behavior is produced. The behavior is here defined as the final top item on
the BOOLEAN stack." the BOOLEAN stack."
[argmap individual] ([argmap individual]
(let [program (genome/plushy->push (:plushy individual) argmap) (error-function argmap individual :train))
inputs ["GCG" "GACAG" "AGAAG" "CCCA" "GATTACA" "TAGG" "GACT"] ([argmap individual subset]
correct-outputs [false false false false true true true] (let [program (genome/plushy->push (:plushy individual) argmap)
outputs (map (fn [input] data (get (train-and-test-data) subset)
(state/peek-stack inputs (:inputs data)
(interpreter/interpret-program correct-outputs (:outputs data)
program outputs (map (fn [input]
(assoc state/empty-state :input {:in1 input}) (state/peek-stack
(:step-limit argmap)) (interpreter/interpret-program
:boolean)) program
inputs) (assoc state/empty-state :input {:in1 input})
errors (map (fn [correct-output output] (:step-limit argmap))
(if (= output :no-stack-item) :boolean))
1000000 inputs)
(if (= correct-output output) errors (map (fn [correct-output output]
0 (if (= output :no-stack-item)
1))) 1000000
correct-outputs (if (= correct-output output)
outputs)] 0
(assoc individual 1)))
:behaviors outputs correct-outputs
:errors errors outputs)]
:total-error #?(:clj (apply +' errors) (assoc individual
:cljs (apply + errors))))) :behaviors outputs
:errors errors
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors))))))

View File

@ -135,4 +135,20 @@
;:umad 1 ;:umad 1
} }
:elitism false :elitism false
:diploid true}) :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})