Experiment to use genetic programming to generate clojure.spec programs from test data
Clojure
Permalink
Failed to load latest commit information.
doc inital commit Jul 15, 2016
src/genetic_programming_spec get rid of unneeded quoting Oct 26, 2016
test/genetic_programming_spec inital commit Jul 15, 2016
.gitignore inital commit Jul 15, 2016
CHANGELOG.md inital commit Jul 15, 2016
LICENSE inital commit Jul 15, 2016
README.md add read Jul 17, 2016
project.clj update project and test-data Jul 16, 2016

README.md

genetic-programming-spec

An experiment in genetic programming with clojure.spec

Usage

Use the evolve function to generate clojure.spec programs from your test data.

Parameters are:

  • population size
  • max number of generations
  • tournament size for selection
  • vector of test data
(def creature-specs (evolve 100 100 7 ["hi" true 5 10 "boo"]))
(perfect-fit creature-specs)
;=> {:program (clojure.spec/cat :0 string? :1 boolean? :2 (s/and integer? odd?) :3 integer? :4 string?), :score 100}

After you have your clojure.spec creature generated, you can have it generate even more data for you!

(s/exercise (eval (:program (perfect-fit creature-specs))) 5)
;; ([("" true -1 -1 "") {:0 "", :1 true, :2 -1, :3 -1, :4 ""}]
;;  [("D" false -1 -1 "G") {:0 "D", :1 false, :2 -1, :3 -1, :4 "G"}]
;;  [("12" false -1 0 "l0") {:0 "12", :1 false, :2 -1, :3 0, :4 "l0"}]
;;  [("" false -1 -2 "") {:0 "", :1 false, :2 -1, :3 -2, :4 ""}]
;;  [("2" false 1 0 "Jro") {:0 "2", :1 false, :2 1, :3 0, :4 "Jro"}])

License

Copyright © 2016 Carin Meier

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.