Post on 13-Dec-2015
Inheritance Inheritance
Objects inheriting attributes and methods Objects inheriting attributes and methods of superclasses as well as having their of superclasses as well as having their own attributes and methodsown attributes and methods
Polymorphism Polymorphism
Methods of same name can mean Methods of same name can mean different things as they are tied to their different things as they are tied to their own classesown classes
Genetic AlgorithmsGenetic Algorithms Definition Definition a computer simulation in which a population of abstract representations a computer simulation in which a population of abstract representations
(called chromosomes, genotype, or genome) of candidate solutions (called (called chromosomes, genotype, or genome) of candidate solutions (called individuals, creatures, or phenotypes) to an optimization problem evolves individuals, creatures, or phenotypes) to an optimization problem evolves toward better solutions.toward better solutions.
BasicsBasics A genetic representation of the solution domain,A genetic representation of the solution domain, A fitness function to evaluate the solution domain.A fitness function to evaluate the solution domain.
Along the way Along the way crossover and mutationcrossover and mutation
Fitness testsFitness tests
Until Until a solution is found that satisfies minimum criteriaa solution is found that satisfies minimum criteria
Karl SimsKarl Sims
Evolved Virtual CreaturesEvolved Virtual Creatures Not an animationNot an animation Evolved objects in motionEvolved objects in motion Encased in various media (water, air, etc.)Encased in various media (water, air, etc.) With gravityWith gravity
In lispIn lisp
Creating a very simple genetic algorithm for Creating a very simple genetic algorithm for producing melodies of a certain typeproducing melodies of a certain type
Step 1Step 1
1. program a class of objects that have music 1. program a class of objects that have music melodies as attributesmelodies as attributes
Step 2Step 2 2. create a whole bunch, say 100, of instances of this 2. create a whole bunch, say 100, of instances of this
object class (initial population)object class (initial population)
Step 3Step 3
3. give the objects a (fitness test) based on overall 3. give the objects a (fitness test) based on overall interval direction, say 9 [stop when fulfilled]interval direction, say 9 [stop when fulfilled]
Step 4Step 4
4. the ones closest survive (selection), the rest are 4. the ones closest survive (selection), the rest are discardeddiscarded
Step 6Step 6
6. their offspring inherit (crossover) the general 6. their offspring inherit (crossover) the general shape of the parents combined melodiesshape of the parents combined melodies
1. program a class of objects that have music melodies as 1. program a class of objects that have music melodies as attributesattributes
2. create a whole bunch, say 100, of instances of this object 2. create a whole bunch, say 100, of instances of this object class (initial population)class (initial population)
3. give the objects a (fitness test) based on overall interval 3. give the objects a (fitness test) based on overall interval direction, say 9 [stop when fulfilled]direction, say 9 [stop when fulfilled]
4. the ones closest survive (selection), the rest are discarded4. the ones closest survive (selection), the rest are discarded
5. the remaining ones (mate) 5. the remaining ones (mate)
6. their offspring inherit (crossover) the general shape of the 6. their offspring inherit (crossover) the general shape of the parents combined melodiesparents combined melodies
7. maybe a (mutation) creeps in7. maybe a (mutation) creeps in
8. return to step 38. return to step 3
Variables Variables ;;;variables;;;variables
(defvar *mutation*(defvar *mutation* (defvar *allowable-deviation* (defvar *allowable-deviation*
ObjectObject
;;;class of object with one attribute (a melody);;;class of object with one attribute (a melody)
(defclass individual ()(defclass individual () ((melody :initarg :melody :initform nil :accessor melody))((melody :initarg :melody :initform nil :accessor melody)) (:documentation "Our objects in the evolutionary potboiler."))(:documentation "Our objects in the evolutionary potboiler."))
Functions Functions ;;;functions;;;functions
(defun melody (defun melody
(defun fitness (defun fitness
(defun mate(defun mate
(defun inherit(defun inherit
(defun mutation (defun mutation
Top levelTop level ;;;top-level;;;top-level
(defun produce-crossover-melodies (defun produce-crossover-melodies
MGCMGC ;;;use MGC to quickly turn into a midi file;;;use MGC to quickly turn into a midi file
(mgc "GA-1.mid" :ontimes '() :pitches '() :durations '() :channels '() :dynamics '())(mgc "GA-1.mid" :ontimes '() :pitches '() :durations '() :channels '() :dynamics '())
(defvar *mutation*(defvar *mutation* (defvar *allowable-deviation* (defvar *allowable-deviation*
(defclass individual ()(defclass individual () ((melody :initarg :melody :initform nil :accessor melody))((melody :initarg :melody :initform nil :accessor melody)) (:documentation "Our objects in the evolutionary potboiler."))(:documentation "Our objects in the evolutionary potboiler."))
(setf i-1 (make-instance 'individual))(setf i-1 (make-instance 'individual))
(defun melody (defun melody
(defun fitness (defun fitness
(defun mate(defun mate
(defun inherit(defun inherit
(defun mutation (defun mutation
(defun produce-crossover-melodies (defun produce-crossover-melodies
(mgc "GA-1.mid" :ontimes '() :pitches '() :durations '() :channels '() :dynamics '())(mgc "GA-1.mid" :ontimes '() :pitches '() :durations '() :channels '() :dynamics '())