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.

Slides:



Advertisements
Similar presentations
Previously… We created a simulated temperature reader which alerts if too hot or too cold… Download the solved practice to keep in sync: Thermostat.vi.
Advertisements

Digital Color 24-bit Color Indexed Color Image file compression
The Binary Numbering Systems
CS 106 Introduction to Computer Science I 02 / 29 / 2008 Instructor: Michael Eckmann.
CSC1016 Coursework Clarification Derek Mortimer March 2010.
First project Create a JApplet with 3 textfields (2 for input and one for the answer), appropriate labels, and buttons for plus, minus and times. Your.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Please pick up an attendance question and submit in 5 minutes CS 1003 Lecture #3 Sept 12, 2006 Knarig Arabshian.
Tirgul 7. Find an efficient implementation of a dynamic collection of elements with unique keys Supported Operations: Insert, Search and Delete. The keys.
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data.
Purpose Tags are the key to marking up content on your HTML page. It’s the tags that mark up sections of the page and are defined (aesthetically) on the.
Data Structures Using C++ 2E Chapter 6 Recursion.
Higher Computing Data Representation.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Data Structures Using C++ 2E Chapter 6 Recursion.
Lists in Python.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
Computer Science 111 Fundamentals of Programming I Number Systems.
Data Representation Int 2 Computing Unit 1 – Computer Systems St Kentigern’s Academy.
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
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…
CS 5 Today HW 9 (lab + 2 probs) due Sunday, 11/8 at midnight Dizzying arrays of possibilities… John Conway Carl Gauss This week’s credits: Exam 2 on Mon.,Tue.
CS190/295 Programming in Python for Life Sciences: Lecture 3 Instructor: Xiaohui Xie University of California, Irvine.
JRN 440 Adv. Online Journalism Resizing and resampling Monday, 2/6/12.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies.
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
Data Representation – Chapter 3 Section 3-1. Terminology “Digital” –Discrete, well defined values/steps –Opposite of analog –Analogy: digital is to analog.
Homework 9 Due ( M & T sections ) ( W & Th sections ) at midnight Sun., 11/3 Mon., 11/4 Problems
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
Looping and Counting Lecture 3 Hartmut Kaiser
CS 121 Today Fractals and Turtles! The Koch Curve how random…
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
Data Representation The storage of Text Numbers Graphics.
Digital Images are represented by manipulating this…
Data Representation. What is data? Data is information that has been translated into a form that is more convenient to process As information take different.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
Ionut Trestian Northwestern University
Week 9 - Monday.  What did we talk about last time?  Method practice  Lab 8.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
AP CSP: Pixelation – B&W/Color Images
Image Processing Objectives To understand pixel based image processing
EECS 110: Lec 12: Mutable Data
Binary Representation in Audio and Images
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
CMSC201 Computer Science I for Majors Lecture 12 – Lists (cont)
Modified from Sharon Guffy
Each column represents another power of the base
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Data Representation.
More Loop Examples Functions and Parameters
HMC’s Galileo Auditorium Some of Cope’s generated MP3s:
Fundamentals of Programming I Number Systems
Numbers and their bases
Ionut Trestian Northwestern University
Fundamentals of Data Representation
Template for IBI poster 36 inches in width and 48 inches in height The title occupies no more than three lines First Author1, Second Author2, Third Author1,2.
2D Array and Matrix.
Northwestern University
EECS 110: Lec 12: Mutable Data
More 2D Array and Loop Examples Functions and Parameters
2D Array and Matrix Application: Game of Life
Presentation transcript:

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?

?

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 bits name: value: '*' 42 The same bits are in each container. But why these?

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

Base 2Base tens + 2 ones 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…

?

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

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

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

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

Hw5: binary image compression Encoding as raw bits One possible idea 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?? is the next digit There are 28 1 is the final digit There are 4

fixed-width image compression a FIXED-width encoding is needed 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 zeros4 ones 8 bits for each "block"

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? bits: # of repeats 8-bit data block 7 bits? the pixel

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…

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

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(' ') 4 >>> frontNum(' ') 2 Examples:

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

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

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?

Which way is up?

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

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

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

Computing's Initial Project?

The Mark 1 Grace Hopper, Howard Aiken at Harvard ran at 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

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

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

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

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

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

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

“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

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

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

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!

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)

Views of the world Engineers think their equations approximate reality.

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

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

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

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

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

Lsits’ flexibility Lists can hold ANY type of data double list A int list A “go” “red” “sox!” String list A

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] ]

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] ]

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…

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

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]

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

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

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

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)

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)

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!

Problem 4 -- Creating Life newB = make_next_generation( oldB ) old generation or "board" new generation or "board"

Problem 4 -- Creating Life newB = make_next_generation( oldB ) old generation or "board" new generation or "board"

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 life out there...

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

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?

Lab, Life!, and Homework…

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

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

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