Top Banner
Review of objects Review of objects overview overview
31

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

Dec 13, 2015

Download

Documents

Janel Francis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Review of objects  overview overview. Class of objects  Attributes/ methods.

Review of objectsReview of objects

overviewoverview

Page 2: Review of objects  overview overview. Class of objects  Attributes/ methods.

Class of objectsClass of objects

Attributes/ methodsAttributes/ methods

Page 3: Review of objects  overview overview. Class of objects  Attributes/ methods.

Object Object

Instance of an classInstance of an class

Page 4: Review of objects  overview overview. Class of objects  Attributes/ methods.

Method Method

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

Page 5: Review of objects  overview overview. Class of objects  Attributes/ methods.

Message passingMessage passing

Object to objectObject to object

Page 6: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 7: Review of objects  overview overview. Class of objects  Attributes/ methods.

Abstraction Abstraction

Many to the fewMany to the few

Page 8: Review of objects  overview overview. Class of objects  Attributes/ methods.

Encapsulation Encapsulation

Hide the complexitiesHide the complexities

Page 9: Review of objects  overview overview. Class of objects  Attributes/ 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

Page 10: Review of objects  overview overview. Class of objects  Attributes/ methods.

GAsGAs

Page 11: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 12: Review of objects  overview overview. Class of objects  Attributes/ methods.

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 13: Review of objects  overview overview. Class of objects  Attributes/ methods.

Interesting Interesting

Example Example

Page 14: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 15: Review of objects  overview overview. Class of objects  Attributes/ methods.

Evolved Virtual CreaturesEvolved Virtual Creatures

Page 16: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 17: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 18: Review of objects  overview overview. Class of objects  Attributes/ methods.

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)

Page 19: Review of objects  overview overview. Class of objects  Attributes/ methods.

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]

Page 20: Review of objects  overview overview. Class of objects  Attributes/ methods.

Step 4Step 4

4. the ones closest survive (selection), the rest are 4. the ones closest survive (selection), the rest are discardeddiscarded

Page 21: Review of objects  overview overview. Class of objects  Attributes/ methods.

Step 5Step 5

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

Page 22: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 23: Review of objects  overview overview. Class of objects  Attributes/ methods.

Step 7Step 7

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

Page 24: Review of objects  overview overview. Class of objects  Attributes/ methods.

Step 8Step 8

8. return to step 38. return to step 3

Page 25: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 26: Review of objects  overview overview. Class of objects  Attributes/ methods.

Variables Variables ;;;variables;;;variables

(defvar *mutation*(defvar *mutation* (defvar *allowable-deviation* (defvar *allowable-deviation*

Page 27: Review of objects  overview overview. Class of objects  Attributes/ methods.

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."))

Page 28: Review of objects  overview overview. Class of objects  Attributes/ methods.

Functions Functions ;;;functions;;;functions

(defun melody (defun melody

(defun fitness (defun fitness

(defun mate(defun mate

(defun inherit(defun inherit

(defun mutation (defun mutation

Page 29: Review of objects  overview overview. Class of objects  Attributes/ methods.

Top levelTop level ;;;top-level;;;top-level

(defun produce-crossover-melodies (defun produce-crossover-melodies

Page 30: Review of objects  overview overview. Class of objects  Attributes/ methods.

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

Page 31: Review of objects  overview overview. Class of objects  Attributes/ methods.

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