Using lexicase in the demo and reformatting
This commit is contained in:
parent
1d12a36566
commit
ef6899d690
@ -5,8 +5,8 @@
|
||||
<output-test url="file://$MODULE_DIR$/target/classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
|
||||
<sourceFolder url="file://C:\Users\user\Documents\GitHub\propeller\dev-resources" isTestSource="false" />
|
||||
<sourceFolder url="file://C:\Users\user\Documents\GitHub\propeller\resources" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
|
@ -9,13 +9,14 @@
|
||||
(gp (update-in (merge {:instructions default-instructions
|
||||
:error-function regression-error-function
|
||||
:max-generations 500
|
||||
:population-size 200
|
||||
:population-size 500
|
||||
:max-initial-plushy-size 50
|
||||
:step-limit 100
|
||||
:parent-selection :tournament
|
||||
:tournament-size 5
|
||||
:UMADRate 0.2
|
||||
:variation {:UMAD 0.5 :crossover 0.5}}
|
||||
:parent-selection :lexicase
|
||||
:tournament-size 20
|
||||
:UMADRate 0.2
|
||||
:variation {:UMAD 0.5 :crossover 0.5}
|
||||
:elitism false}
|
||||
(apply hash-map
|
||||
(map read-string args)))
|
||||
[:error-function]
|
||||
|
@ -4,16 +4,16 @@
|
||||
(defn push-from-plushy
|
||||
"Returns the Push program expressed by the given plushy representation."
|
||||
[plushy]
|
||||
(let [opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
|
||||
(loop [push () ;; iteratively build the Push program from the plushy
|
||||
(let [opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
|
||||
(loop [push () ;; iteratively build the Push program from the plushy
|
||||
plushy (mapcat #(if-let [n (get opens %)] [% ['open n]] [%]) plushy)]
|
||||
(if (empty? plushy) ;; maybe we're done?
|
||||
(if (some opener? push) ;; done with plushy, but unclosed open
|
||||
(recur push '(close)) ;; recur with one more close
|
||||
push) ;; otherwise, really done, return push
|
||||
(if (empty? plushy) ;; maybe we're done?
|
||||
(if (some opener? push) ;; done with plushy, but unclosed open
|
||||
(recur push '(close)) ;; recur with one more close
|
||||
push) ;; otherwise, really done, return push
|
||||
(let [i (first plushy)]
|
||||
(if (= i 'close)
|
||||
(if (some opener? push) ;; process a close when there's an open
|
||||
(if (some opener? push) ;; process a close when there's an open
|
||||
(recur (let [post-open (reverse (take-while (comp not opener?)
|
||||
(reverse push)))
|
||||
open-index (- (count push) (count post-open) 1)
|
||||
@ -23,8 +23,8 @@
|
||||
(concat pre-open [post-open])
|
||||
(concat pre-open [post-open ['open (dec num-open)]])))
|
||||
(rest plushy))
|
||||
(recur push (rest plushy))) ;; unmatched close, ignore
|
||||
(recur (concat push [i]) (rest plushy)))))))) ;; anything else
|
||||
(recur push (rest plushy))) ;; unmatched close, ignore
|
||||
(recur (concat push [i]) (rest plushy)))))))) ;; anything else
|
||||
|
||||
(defn make-random-plushy
|
||||
"Creates and returns a new plushy."
|
||||
|
@ -38,9 +38,9 @@
|
||||
"G"
|
||||
"T"))
|
||||
|
||||
(def opens ; number of blocks opened by instructions (default = 0)
|
||||
(def opens ; number of blocks opened by instructions (default = 0)
|
||||
{'exec_dup 1
|
||||
'exec_if 2})
|
||||
'exec_if 2})
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; actual instructions
|
||||
|
@ -2,17 +2,17 @@
|
||||
(:use [propeller util]))
|
||||
|
||||
(def example-push-state
|
||||
{:exec '()
|
||||
{:exec '()
|
||||
:integer '(1 2 3 4 5 6 7)
|
||||
:string '("abc")
|
||||
:input {:in1 4}})
|
||||
:string '("abc")
|
||||
:input {:in1 4}})
|
||||
|
||||
(def empty-push-state
|
||||
{:exec '()
|
||||
{:exec '()
|
||||
:integer '()
|
||||
:string '()
|
||||
:string '()
|
||||
:boolean '()
|
||||
:input {}})
|
||||
:input {}})
|
||||
|
||||
(defn push-to-stack
|
||||
"Pushes item onto stack in state"
|
||||
|
@ -5,37 +5,37 @@
|
||||
#_(interpret-program '(1 2 integer_+) empty-push-state 1000)
|
||||
|
||||
#_(interpret-program '(3 5 integer_= exec_if (1 "yes") (2 "no"))
|
||||
empty-push-state
|
||||
1000)
|
||||
empty-push-state
|
||||
1000)
|
||||
|
||||
#_(interpret-program '(in1 string_reverse 1 string_take "?" string_= exec_if
|
||||
(in1 " I am asking." string_concat)
|
||||
(in1 " I am saying." string_concat))
|
||||
(assoc empty-push-state :input {:in1 "Can you hear me?"})
|
||||
1000)
|
||||
(in1 " I am asking." string_concat)
|
||||
(in1 " I am saying." string_concat))
|
||||
(assoc empty-push-state :input {:in1 "Can you hear me?"})
|
||||
1000)
|
||||
|
||||
#_(interpret-program '(in1 string_reverse 1 string_take "?" string_= exec_if
|
||||
(in1 " I am asking." string_concat)
|
||||
(in1 " I am saying." string_concat))
|
||||
(assoc empty-push-state :input {:in1 "I can hear you."})
|
||||
1000)
|
||||
(in1 " I am asking." string_concat)
|
||||
(in1 " I am saying." string_concat))
|
||||
(assoc empty-push-state :input {:in1 "I can hear you."})
|
||||
1000)
|
||||
|
||||
#_(push-from-plushy (make-random-plushy default-instructions 20))
|
||||
|
||||
#_(interpret-program (push-from-plushy (make-random-plushy default-instructions 20))
|
||||
(assoc empty-push-state :input {:in1 "I can hear you."})
|
||||
1000)
|
||||
(assoc empty-push-state :input {:in1 "I can hear you."})
|
||||
1000)
|
||||
|
||||
;; Target function: f(x) = x^3 + x + 3
|
||||
|
||||
#_(gp {:instructions default-instructions
|
||||
:error-function regression-error-function
|
||||
:max-generations 50
|
||||
:population-size 200
|
||||
:max-initial-plushy-size 50
|
||||
:step-limit 100
|
||||
:parent-selection :tournament
|
||||
:tournament-size 5})
|
||||
:error-function regression-error-function
|
||||
:max-generations 50
|
||||
:population-size 200
|
||||
:max-initial-plushy-size 50
|
||||
:step-limit 100
|
||||
:parent-selection :tournament
|
||||
:tournament-size 5})
|
||||
|
||||
#_(gp {:instructions default-instructions
|
||||
:error-function string-classification-error-function
|
||||
|
Loading…
x
Reference in New Issue
Block a user