31
Review of objects Review of objects overview overview

Review of objects overview overview. Class of objects Attributes/ methods

Embed Size (px)

Citation preview

Review of objectsReview of objects

overviewoverview

Class of objectsClass of objects

Attributes/ methodsAttributes/ methods

Object Object

Instance of an classInstance of an class

Method Method

A function that acts on objects of a classA function that acts on objects of a class

Message passingMessage passing

Object to objectObject to object

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

Abstraction Abstraction

Many to the fewMany to the few

Encapsulation Encapsulation

Hide the complexitiesHide the complexities

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

GAsGAs

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

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Interesting Interesting

Example Example

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

Evolved Virtual CreaturesEvolved Virtual Creatures

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 5Step 5

5. the remaining ones (mate) 5. the remaining ones (mate)

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

Step 7Step 7

7. maybe a (mutation) creeps in7. maybe a (mutation) creeps in

Step 8Step 8

8. return to step 38. return to step 3

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 '())