Presentation is loading. Please wait.

Presentation is loading. Please wait.

What's ahead? Conway gives a whole new outlook on "loopy" ! John Conway 10/18 no class - Fall break 10/19 no new hw due 10/11 Dynamic & binary data 10/12.

Similar presentations


Presentation on theme: "What's ahead? Conway gives a whole new outlook on "loopy" ! John Conway 10/18 no class - Fall break 10/19 no new hw due 10/11 Dynamic & binary data 10/12."— Presentation transcript:

1 What's ahead? Conway gives a whole new outlook on "loopy" ! John Conway 10/18 no class - Fall break 10/19 no new hw due 10/11 Dynamic & binary data 10/12 ASCII art / C. cipher due 11/1 Objects and classes 2 11/2 Regular HW due 10/25 Dictionaries and objects 1 10/29 Images or life due 11/8 Final project ideas, p. 1 I'm a head! ASCII diamond?

2 10-11-10 ?

3 Binary, briefly 8 bits = 1 byte = 1 box The SAME bits can represent two different pieces of data, depending on the type type: str type: int 00101010 bits name: value: '*' 42 The same bits are in each container. But why these?

4 Base 10 What is 42 ? 42 4 tens + 2 ones 123 1 hundred + 2 tens + 3 ones ONEs column TENs column ONEs column TENs column HUNDREDs column

5 -------- Base 2Base 10 42 4 tens + 2 ones 101010 123 1 hundred + 2 tens + 3 ones ONEs columnTENs column ONEs columnTENs column HUNDREDs column each column represents another power of the base ONEs columnTWOs columnFOURs column EIGHTs column SIXTEENs col. THIRTYTWOs col. ONEs columnTWOs columnFOURs column EIGHTs column SIXTEENs col. THIRTYTWOs col. SIXTYFOURs col128s column Write 123 in binary…

6 10-11-10 ?

7 Conversions from binary string to decimal number: binstr = '101010' N = int( binstr, 2 ) N is now 42.

8 Conversions from binary string to decimal number: from decimal number to binary string: binstr = '101010' N = int( binstr, 2 ) N is now 42. def n2b( N ): if N<1: return '' return n2b(N/2) + str(N%2) Use this helper function: n2b( 42 ) '101010' input any integer...... and the binary string is returned

9 Hw5: binary, applied Binary ImageEncoding as raw bits just one big string of 64 characters 10101010 01010101 10101010 01010101 10101010 01010101 10101010 01010101 "1010101001010101101010100101010110101010010101011010101001010101"

10 Hw5: binary image compression Binary Image 00000000 11111111 00000000 00001111 Encoding as raw bits just one big string of 64 characters "0000000000000000111111111111111100000000000000000000000000001111" If our images tend to have long streaks of unchanging data, how might we represent it more efficiently… (but still in binary)?

11 Hw5: binary image compression Encoding as raw bits One possible idea 0100001100000111001100 0 is the first digit There are 16 of them. 1 is the next digit Again, there are 16 of them. just one big string of 64 characters problems?? 00000000 11111111 00000000 00001111 0 is the next digit There are 28 1 is the final digit There are 4

12 fixed-width image compression a FIXED-width encoding is needed 00010000100100000001110010000100 0 is the first digit There are 16 of them. 1 is the next digit Again, there are 16 of them. 7 bits: # of repeats 1st bit holds 1 pixel value 7 bits holds the # of those values in a row and so on… 7 bits: # of repeats 8-bit data block original dataoriginal image 00000000 11111111 00000000 00001111 28 zeros4 ones 8 bits for each "block"

13 If 7 bits holds the # of consecutive repetitions of data, what is the largest number of 1 s or 0 s that one block can represent? For hw5pr2, the standard images will be small (< 127 pixels) B bits? 00010000 7 bits: # of repeats 8-bit data block 7 bits? the pixel

14 hw5 pr2 def compress( I ): """ returns the RLE of the input binary image, I """ def uncompress( CI ): """ returns the binary image I from the run-length- encoded, "compressed" input, CI """ What function(s) might help here? from cs5png import * binaryIm( I, ncols, nrows ) can download and run the image-file interface (not at all necessary) for fun…

15 A start... Write a function frontNum(s). It should return the # of times the first element of the input s appears consecutively AT THE FRONT of that string: >>> frontNum('1111010') 4 >>> frontNum('00111000010') 2 Examples: def frontNum(s): What are the BEST and the WORST compression results you can get for an 8x8 input image (64 bits)? How can you change fixed-length compression so that all compressed images are smaller than their originals ? That is, how can we make compression always "work" ? EXTRA

16 Write a function frontNum(s). It should return the # of times the first element of the input s appears consecutively AT THE FRONT of that string: def frontNum(s): >>> frontNum('1111010') 4 >>> frontNum('00111000010') 2 Examples:

17 What are the BEST and the WORST compression results you can get for an 8x8 image input (64 bits)? shortest compressed representation longest compressed representation How can you change this compression algorithm so that all compressed images are smaller than their originals ? That is, how can we make compression always work ? EXTRA

18 Original ImageT = 78/255T = 120/255Adaptive T Binary images? T = 120/255 Adaptive Threshold

19 Plot of total intensity across each row of pixels What's in the image? Why is it important to have binarized first? What do these peaks mean?

20 Which way is up?

21 This landscape image is determined to contain a portrait document. Intensity profiles Which way is up? Right-side up?

22 IS 313 Initial Project Some preliminary thinking about project possibilities... VPython PyGame Python for Android Web Application ? File upload ? Python + SQL Image converter ? Library for 3d graphics Connecting to external projects: Library for 2d game building Python + ArcGIS Survey with stored results ? Other external devices Databases? Geog. displays

23 IS 313 Initial Project This project has three deadlines: 10/25 Plan and initial reading/design Using an external library? Make sure it's installed and an example works... Start with the course's final project 11/8 Update with progress 11/15 Final version of this trial project Make sure the plans and goals are reasonable, but potentially looking ahead... There should be at least one piece of added, working functionality Perhaps a revised plan for what to accomplish by 11/15 May choose to extend the initial project or completely change direction. Potentially, a revised plan for what to accomplish by 11/15

24 Computing's Initial Project?

25 The Mark 1 Grace Hopper, Howard Aiken at Harvard ran at 0.00001 MHz 5 tons, 530 miles of wiring 765,299 distinct parts! relay-based computer Addition: 0.6 seconds Multiplication: 5.7 seconds Division: 15.3 seconds http://www-03.ibm.com/ibm/history/exhibits/markI/markI_reference.html

26 print: Making programs talk to you! Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs. - Maurice Wilkes Programming: the art of debugging an empty file. - The Jargon File http://www.tuxedo.org/~esr/jargon/

27 The first bug Grace Hopper “In the days they used oxen for heavy pulling, when one ox couldn't budge a log, they didn't try to grow a larger ox. We shouldn't be trying for bigger and better computers, but for better systems of computers.” from the UNIVAC 1

28 hw5pr3 Image processing... import cs5png Images are represented by Python lists... IM = cs5png.getRGB( 'olin.png' ) newIM = invert( IM ) cs5png.saveRGB( IM )

29 hw5pr3 Creating a 4-pixel image from scratch.... PX = [ [ [255,0,0], [0,255,0] ] cs5png.saveRGB( PX ) top row 1 st column 2 nd column red, green, and blue components

30 Images... are just lists How many dimensions do those lists have? PX = [ [ [255,0,0], [0,255,0] ] [ [0,0,255], [255,255,0] ] ] dimensions ~ complexity

31 Reference vs. Value Changeable types:Unchangeable types: list string int float bool L L[0]L[1]L[2] Reference, Pointer, id L = [7,11,'hi'] x 7 11 'hi' 42 x = 42

32 “Pass By Value” def main() """ calls conform """ print " Welcome to Conformity, Inc. " fav = 7 conform(fav) print " My favorite number is", fav def conform(fav) """ sets input to 42 """ fav = 42 return fav 7 fav

33 7 “Pass By Value” def main() """ calls conform """ print " Welcome to Conformity, Inc. " fav = 7 conform(fav) print " My favorite number is", fav def conform(fav) """ sets input to 42 """ fav = 42 return fav 7 fav PASS BY VALUE “Pass by value” means that data is copied when sent to a method 42

34 Passing lists by value… def main() """ calls conform2 """ print " Welcome to Conformity, Inc. " fav = [ 7, 11 ] conform2(fav) print " My favorite numbers are", fav def conform2(fav) """ sets all of fav to 42 """ fav[0] = 42 fav[1] = 42 What gets passed by value here? fav L[0]L[1] 7 11 fav

35 Passing lists by value… def main() """ calls conform2 """ print " Welcome to Conformity, Inc. " fav = [ 7, 11 ] conform2(fav) print " My favorite numbers are", fav def conform2(fav) """ sets all of fav to 42 """ fav[0] = 42 fav[1] = 42 fav L[0]L[1] 7 11 fav can change data elsewhere! The reference is copied!

36 The conclusion You can change the contents of lists in functions that take those lists as input. Those changes will be visible everywhere. (actually, lists or any mutable objects) (immutable objects are safe, however)

37 Views of the world Engineers think their equations approximate reality.

38 Views of the world Engineers think their equations approximate reality. Physicists think reality approximates their equations.

39 Views of the world Engineers think their equations approximate reality. Physicists think reality approximates their equations. Mathematicians don't care.

40 Views of the world Axioms Definitions Creating structure from a few simple facts... Creating structure from a few simple actions... if/else while for arithmetic operations variables arrays ProofAlgorithm Engineers think their equations approximate reality. Physicists think reality approximates their equations. Mathematicians don't care. computer science

41 Lists’ flexibility Lists can hold ANY type of data A = [ 42., 75., 70. ] 42.0 75.0 70.0 float list A they don’t have to be horizontal lists!

42 42.0 75.0 70.0 double list A they don’t have to be horizontal lists! Lists’ flexibility Lists can hold ANY type of data A = [ 42., 75., 70. ] 42.0 75.0 70.0 float list A

43 Lsits’ flexibility Lists can hold ANY type of data 42.0 75.0 70.0 double list A 42 7 -11 int list A “go” “red” “sox!” String list A

44 2d lists or arrays Lists can hold ANY type of data -- including lists ! list A A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ]

45 list A 2d arrays list A[0] A[1] A[2] Lists can hold ANY type of data -- including lists ! A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ]

46 list A Jagged arrays list A[0] A[1] A[2] Lists can hold ANY type of data -- including lists ! A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ] Rows within 2d arrays need not be the same length…

47 list A A[0] A[1] A[2] Lists can hold ANY type of data -- including lists ! A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ] Rows within 2d arrays need not be the same length… We will not use jagged arrays at least in hw 10

48 Rectangular arrays list A A[0] A[1] A[2] How many rows does A have, in general ? How many columns does A have, in general ? What does each piece of the syntax A[1][2] mean ? A[1][2] = 42 A[2][3] A[0][0]

49 Creating 1d and 2d lists... def createRow( width ): """ does just that """ R = [] # start with nothing for col in range( width ): R = R + [0] return R

50 Creating 1d and 2d lists... def createRow( width ): """ does just that """ R = [] # start with nothing for col in range( width ): R = R + [0] return R def createBoard( height, width ): """ creates a 2d array! """ Bd = [] for row in range( ): return Bd

51 Problem 4 -- “Life” Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) John Conway

52 Problem 4 -- Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead)

53 Problem 4 -- Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead)

54 Problem 4 -- Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) life out there... Keep going!

55 Problem 4 -- Creating Life 0123450 12345 0 1 2 3 4 5 0 1 2 3 4 5 newB = make_next_generation( oldB ) old generation or "board" new generation or "board"

56 Problem 4 -- Creating Life 0123450 12345 0 1 2 3 4 5 0 1 2 3 4 5 newB = make_next_generation( oldB ) old generation or "board" new generation or "board"

57 Problem 4 -- Details For each generation… 0 represents an empty cell 1 represents a living cell outermost edge should always be left empty (even if there are 3 neighbors) compute all cells based on their previous neighbors before updating any of them http://www.math.com/students/wonders/life/life.html life out there...

58 Problem 2 -- to  and beyond! Are there stable life configurations? Are there oscillating life configurations? Are there self-propagating life configurations? "rocks" "plants" "animals" period 3 period 2

59 Problem 2 -- to  and beyond! Are there life configurations that expand forever? What is the largest amount of the life universe that can be filled with cells? How sophisticated can the structures in the life universe be? Google for GOLLY, Game of Life Are all feasible configurations reachable?

60 Lab, Life!, and Homework…

61 import sys for i in range(4): for j in range(8): sys.stdout.write('#') print software object representing the screen's standard output Without extra spaces… Output ######## method (function) that prints only its input

62 The not-so-subtle art of singling out the best (and worst) of anything… Computing with language Computing to the max You know this would make me hungry… if it weren't 7 pm! Battle-tested ciphers - and how to break them ! Consider literature a bunch of strings ? 'm&ms' [ 0, 42 ] a comparison comparison [ 4, 2 ] True 'True' 'coffee' > or < Drawn Inward Fall leaves when leaves fall. Seasons by Mike Maguire

63 Beyond binary … to bits themselves CS 101 Today King of ANDs Queen of ORsJack of NOTs Too many bits? Compress! Olin during the day? alien 2diner 1 faces 2diner 1 Hw #4 due Mon. 10/4 HW Notes Lab binary & decimal pr2 all your bases are belong to us! pr3 image compression Morning Aft mount 1ghost 1 seven 0ghost 0 extra image processing... class's guesses


Download ppt "What's ahead? Conway gives a whole new outlook on "loopy" ! John Conway 10/18 no class - Fall break 10/19 no new hw due 10/11 Dynamic & binary data 10/12."

Similar presentations


Ads by Google