Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added meta-errors; changes to autoconstruction and autoconstructive_d…

…igital_multiplier.
  • Loading branch information...
commit 58942110f1c82206b4b60cd71e58f419c58fa66a 1 parent 6fe87a5
@lspector authored
View
14 project.clj
@@ -1,4 +1,4 @@
-(defproject clojush "2.0.23"
+(defproject clojush "2.0.24"
:description "The Push programming language and the PushGP genetic programming
system implemented in Clojure.
See http://hampshire.edu/lspector/push.html"
@@ -21,10 +21,10 @@
;:jvm-opts ["-Xmx12g" "-Xms12g" "-XX:+UseParallelGC"]
;:jvm-opts ["-Xmx58g" "-Xms58g" "-XX:+UseParallelGC" "-Djava.awt.headless=true"]
;; the following should automatically take 80% of the machine's RAM and also use the G1 garbage collector
- :jvm-opts ~(let [mem-to-use (long (* (.getTotalPhysicalMemorySize
- (java.lang.management.ManagementFactory/getOperatingSystemMXBean))
- 0.8))]
- [(str "-Xmx" mem-to-use)
- (str "-Xms" mem-to-use)
- "-XX:+UseG1GC"])
+; :jvm-opts ~(let [mem-to-use (long (* (.getTotalPhysicalMemorySize
+; (java.lang.management.ManagementFactory/getOperatingSystemMXBean))
+; 0.8))]
+; [(str "-Xmx" mem-to-use)
+; (str "-Xms" mem-to-use)
+; "-XX:+UseG1GC"])
:main clojush.core)
View
8 src/clojush/evaluate.clj
@@ -25,22 +25,22 @@
(defn calculate-meta-errors
"Calculates one meta-error for each meta-error category provided. Each
meta-error-category should either be a keyword for a built-in meta category
- or a function that takes an individual and returns a meta error value.
+ or a function that takes an individual and an argmap and returns a meta error value.
The built-in meta categories include:
:size (minimize size of program)
:compressibility (minimize ammount a program compresses compared to itself)
:total-error (minimize total error)
:unsolved-cases (maximize number of cases with zero error)"
- [ind {:keys [meta-error-categories error-threshold]}]
+ [ind {:keys [meta-error-categories error-threshold] :as argmap}]
(let [meta-error-fn (fn [cat]
(cond
- (fn? cat) (cat ind)
+ (fn? cat) (cat ind argmap)
(= cat :size) (count (:genome ind))
; (= cat :compressibility) 555 ;;TMH fix later
(= cat :total-error) (:total-error ind)
(= cat :unsolved-cases) (count (filter #(> % error-threshold) (:errors ind)))
:else (throw (Exception. (str "Unrecognized meta category: " cat)))))]
- (map meta-error-fn meta-error-categories)))
+ (doall (map meta-error-fn meta-error-categories))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; evaluate individuals
View
66 src/clojush/problems/demos/autoconstructive_digital_multiplier.clj
@@ -2,7 +2,15 @@
;; a version of digital-multiplier.clj modified to use only the autoconstriction
;; genetic operator.
+;;*****************************************************************************
+;; NOTE: This is work in progress, based on ideas that are under development.
+;; For the time being you shouldn't expect it to work well or remain stable.
+;; Documentation is also spotty.
+;;*****************************************************************************
+
+
;; Documentation for the original digital-multiplier.clj file:
+
;; digital-multiplier.clj
;; an example problem for clojush, a Push/PushGP system written in Clojure
;; Tom Helmuth, thelmuth@cs.umass.edu
@@ -19,17 +27,9 @@
;; Each of these vectors has 2*n items, accessed by instructions in0 through
;; in(2*n) and out0 through out(2*n) respectively.
-
-;;; TO DO
-;; epigenetic markers, and genome instructions for modifying them
-;; exec instructions.... what does this mean for epigenetic markers to get the closes?
-;; geography?
-
-
-
(ns clojush.problems.demos.autoconstructive-digital-multiplier
- (:use clojush.pushgp.pushgp
- [clojush pushstate interpreter random]
+ (:use [clojush.pushgp pushgp genetic-operators]
+ [clojush pushstate interpreter random translate]
clojure.math.numeric-tower))
;; Borrowed from mux examples
@@ -144,6 +144,7 @@
output-bits (vec (int->bits (* num1 num2) (* 2 num-bits-n)))]
(vector input-bits output-bits))))
+;; Version from digital-multiplier.clj
;; Create error function; it is applied partially when defined, and takes
;; a program and returns its error vector.
;(defn dm-error-function
@@ -175,9 +176,8 @@
;; a program and returns its error vector.
(defn dm-error-function
"Defines the error function of num-bits binary multiplier."
- [num-bits-n test-cases individual]
- (let [program (:program individual)
- errors (doall
+ [num-bits-n test-cases program]
+ (let [errors (doall
(for [[input output] test-cases]
(let [initial-output-vector (vec (repeat (* 2 num-bits-n) nil))
final-state (run-push program
@@ -200,15 +200,45 @@
result-output)))))]
errors))
+(defn error-difference
+ [errors1 errors2]
+ (reduce + (map #(Math/abs (- %1 %2))
+ errors1
+ errors2)))
+
+(declare full-dm-error-function)
+
+(defn dm-meta-error-fn
+ "Takes an individual and an argmap and returns a meta-error value."
+ [ind {:keys [atom-generators max-points-in-initial-program] :as argmap}]
+ (let [random-genome (random-plush-genome max-points-in-initial-program atom-generators argmap)
+ semantics-fn (fn [g1 g2 g3]
+ (full-dm-error-function
+ (translate-plush-genome-to-push-program
+ {:genome
+ (produce-child-genome-by-autoconstruction g1 g2 g3)})))
+ e1 (semantics-fn (:genome ind) (:genome ind) (:genome ind))
+ e2 (semantics-fn (:genome ind) (:genome ind) random-genome)
+ e3 (semantics-fn (:genome ind) random-genome (:genome ind))]
+ (if (and (distinct? e1 e2)
+ (distinct? e1 e3))
+ #_(and (apply distinct? [e1 e2 e3])
+ (< (error-difference e1 e2)
+ (error-difference e1 e3)))
+ 0
+ 1)))
+
;; Define argmap for pushgp
(defn define-digital-multiplier
[num-bits-n]
(define-ins (* 2 num-bits-n))
(define-outs (* 2 num-bits-n))
+ (def full-dm-error-function
+ (partial dm-error-function
+ num-bits-n
+ (dm-test-cases num-bits-n)))
(def argmap
- {:error-function (partial dm-error-function
- num-bits-n
- (dm-test-cases num-bits-n))
+ {:error-function full-dm-error-function
:atom-generators (dm-atom-generators num-bits-n)
:population-size 500
:max-generations 10000
@@ -220,7 +250,9 @@
:parent-selection :lexicase
;:trivial-geography-radius 50
:report-simplifications 0
- :pass-individual-to-error-function true}
+ ;:pass-individual-to-error-function true
+ :meta-error-categories [dm-meta-error-fn]
+ }
)
)
View
30 src/clojush/pushgp/genetic_operators.clj
@@ -242,27 +242,31 @@
instruction-map)))
genome)))
+(defn produce-child-genome-by-autoconstruction
+ [parent1-genome parent2-genome parent3-genome]
+ (top-item :genome
+ (run-push
+ (translate-plush-genome-to-push-program
+ {:genome (process-genome-for-autoconstruction
+ parent1-genome)})
+ (-> (->> (make-push-state)
+ (push-item parent3-genome :genome)
+ (push-item parent2-genome :genome)
+ (push-item parent1-genome :genome))
+ (assoc :parent1-genome parent1-genome)
+ (assoc :parent2-genome parent2-genome)
+ (assoc :random-genome parent3-genome)))))
+
(defn autoconstruction
"Returns a genome for child produced by autoconstruction by executing parent1 with parent1,
-parent2, and a random genome on top of the genome stack."
+parent2, and a random genome on top of the genome stack. EXPERIMENTAL AND SUBJECT TO CHANGE."
[parent1 parent2 {:keys [maintain-ancestors atom-generators max-points-in-initial-program]
:as argmap}]
(let [parent1-genome (:genome parent1)
parent2-genome (:genome parent2)
random-genome (random-plush-genome max-points-in-initial-program atom-generators argmap)
child-genome-fn (fn []
- (top-item :genome
- (run-push
- (translate-plush-genome-to-push-program
- {:genome (process-genome-for-autoconstruction
- parent1-genome)})
- (-> (->> (make-push-state)
- (push-item random-genome :genome)
- (push-item parent2-genome :genome)
- (push-item parent1-genome :genome))
- (assoc :parent1-genome parent1-genome)
- (assoc :parent2-genome parent2-genome)
- (assoc :random-genome random-genome)))))
+ (produce-child-genome-by-autoconstruction parent1-genome parent2-genome random-genome))
child1-genome (child-genome-fn)
other-child-genomes (repeatedly 1 child-genome-fn)
clone (some #{child1-genome}
Please sign in to comment.
Something went wrong with that request. Please try again.