Creating new worlds inside the computer COS 116: 2/10/2011 Sanjeev Arora.

Slides:



Advertisements
Similar presentations
ZeusBerthaAmyDianeErikaClare YanceyAmyClareDianeBerthaErika XavierBerthaClareErikaDianeAmy WyattDianeAmyBerthaClareErika VictorBerthaDianeAmyErikaClare.
Advertisements

Piyush Kumar (Lecture 3: Stable Marriage) Welcome to COT5405.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 2.
Matching Theory.
Matching problems Toby Walsh NICTA and UNSW. Motivation Agents may express preferences for issues other than a collective decision  Preferences for a.
CSC 430 Lecture1: Introduction and Python Primer.
Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2010 Adam Finkelstein.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Creating new worlds inside the computer COS 116: 2/14/2008 Sanjeev Arora.
ZeusBerthaAmyDianeErikaClare YanceyAmyClareDianeBerthaErika XavierBerthaClareErikaDianeAmy WyattDianeAmyBerthaClareErika VictorBerthaDianeAmyErikaClare.
Lecture 6 CSE 331 Sep 14. A run of the GS algorithm Mal Wash Simon Inara Zoe Kaylee.
Lecture 4 CSE 331 Sep 9, Blog posts for lectures Starts from today See Sep 8 post on the blog.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne COS 423: Theory of Algorithms Princeton University Spring, 2001 Kevin Wayne.
“It ain’t no good if it ain’t snappy enough.” (Efficient Computations) COS 116: 2/19/2008 Sanjeev Arora.
Lecture 5 CSE 331 Sep 11, HW 1 out today Will be handed out at the END of the lecture Read the homework policy document carefully START EARLY! ©ehow.com.
What computers just cannot do. COS 116: 2/28/2008 Sanjeev Arora.
Lecture 8 CSE 331 Sep 18, Homeworks Hand in your HW 1 HW 2 and solutions to HW 1 out at the end of class Not naming your collaborators is same as.
Lecture 8 CSE 331 Sep 17, HW 1 due today Place Q1 and Q2 in separate piles I will not accept HWs after 1:15pm.
Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2012 Adam Finkelstein.
Creating new worlds inside the computer COS 116, Spring 2012 Adam Finkelstein.
Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity.
Lecture 6 CSE 331 Sep 10, Homeworks HW 1 posted online: see blog/piazza Pickup graded HW 0 in TA OHs.
CSC 430 Lecture1: Introduction and Python Primer.
The Stable Marriage Problem
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 1.
1 Chapter 1 Introduction: Some Representative Problems Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Stable Matching Problem Goal. Given n men and n women, find a "suitable" matching. n Participants rate members of opposite sex. n Each man lists women.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013.
CS 484 – Artificial Intelligence1 Announcements Lab 4 due today, November 8 Homework 8 due Tuesday, November 13 ½ to 1 page description of final project.
1 Chapter 13 Artificial Life: Learning through Emergent Behavior.
Topic 26 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable.
Programming Principles Chapter 1. Objectives Discuss the program design process. Introduce the Game of Life. Discuss object oriented design. – Information.
Lecture 2 CSE 331. Day 1 Survey On UBlearns Day 1 Survey (talking points) Security MS PhD for research Building PC’s for 442 It’s ok to play games –
Lecture 5 CSE 331 Sep 11, Submit the form I’ll need confirmation in writing. No graded material will be handed back till I get this signed form.
“It ain’t no good if it ain’t snappy enough.” (Efficient Computations) COS 116, Spring 2011 Sanjeev Arora.
1 The Stable Marriage Problem Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij.
1 Chapter 1 Introduction: Some Representative Problems Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Design & Co-design of Embedded Systems Final Project: “The Match Maker” Second Phase Oral Presentation Safa S. Mahmoodian.
The Stable Marriage Problem
Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2011 Sanjeev Arora.
CSCI 256 Data Structures and Algorithm Analysis lecture 1 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Fair Shares.
CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Market Design and Analysis Lecture 2 Lecturer: Ning Chen ( 陈宁 )
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
COMP9007: Algorithms Stable Matching. What's in an algorithm? Algorithms can have huge impact For example – A report to the White House from 2010 includes.
Matching Boys Girls A B C D E
Stable Matching.
Chapter 1 Introduction: Some Representative Problems
Stable Marriage Problem
Introduction to the Design and Analysis of Algorithms
The Stable Marriage Problem
CSE 421: Introduction to Algorithms
Lecture 5 CSE 331 Sep 10, 2010.
Lecture 6 CSE 331 Sep 11, 2017.
S. Raskhodnikova; based on slides by K. Wayne
CSE 421: Introduction to Algorithms
1.1 A First Problem: Stable Matching
Discrete Math for CS CMPSC 360 LECTURE 9 Last time: Strong induction
Lecture 5 CSE 331 Sep 6, 2013.
Lecture 5 CSE 331 Sep 7, 2012.
Chapter 1 Introduction: Some Representative Problems
Lecture 6 CSE 331 Sep 12, 2011.
Lecture 6 CSE 331 Sep 12, 2016.
Lecture 7 CSE 331 Sep 10, 2014.
Richard Anderson Winter 2019 Lecture 1
Piyush Kumar (Lecture 3: Stable Marriage)
Lecture 5 CSE 331 Sep 9, 2011.
Lecture 7 CSE 331 Sep 11, 2013.
Presentation transcript:

Creating new worlds inside the computer COS 116: 2/10/2011 Sanjeev Arora

Pseudocode Simple instructions: involve +, -, ×, ÷ Compound instructions  Conditionals  Loops No need to sweat over exact wording during exams (unless it changes meaning!)

Algorithm defn; revisited “Pseudocode for turning a set of inputs into outputs in a finite amount of time” Questions to think about:  What class of computational tasks can be solved by algorithms?  How dependent is this class on the exact definition of pseudocode?

Today’s topic: Creating new worlds inside the computer. “simulation”

Conway’s Game of life Rules: At each step, in each cell  Survival: Critter survives if it has 2 or 3 neighbors.  Death: Critter dies if it has 1 or fewer neighbors, or more than 3.  Birth: New critter is born if cell is currently empty and 3 neighboring cells have critters.

Should use: n x n array A (for desired n) A[i, j] = 1 means critter lives in square, 0 means empty square Discussion Time How would you write pseudocode that simulates Game of Life?

Pseudocode for each step Do for i = 1 to n { Do for j = 1 to n { neighbors  A[i – 1, j - 1] + A[i – 1, j] + A[i – 1,j + 1] + A[i, j – 1] + A[i, j + 1] + A[i + 1, j – 1] + A[i + 1, j] + A[i + 1, j + 1] if ( neighbors = 2 OR neighbors = 3 ) then { B[i, j]  1 } else if ( neighbors = 1 … ) …etc. //see handout; Example 3// } Do for i = 1 to n { Do for j = 1 to n { A[i,j]  B[i,j] } }

Moral of the Game of Life? Simple local behavior can lead to complex global behavior (cf. Brian Hayes article on blackboard)

Physics of snow crystals “Cooling” – reduce amount of molecular motion Crystal growth: capture of nearby floating molecules Water vaporWater Snow crystals cooling further cooling

Next..

Discussion Time How does weather prediction happen? Why can’t we predict the weather a month from today?

Twister simulation Divide region into 3D grid Identify laws of physics for air Navier Stokes equations: How does a block of air move when certain pressure, temperature and velocity differentials exist on its boundary?

Simulator pseudocode Initialize Grid using data from observations: surface and aircraft measurements, radar (NEXRAD) readings, etc. Do for i = 1 to n { Do for j = 1 to n { Do for k = 1 to n { Update state of Grid[i, j, k] } } 10ºC, 15 psi, 20% humidity 11ºC, 15 psi, 23% humidity etc.

Other examples of simulation [Turk 91] following: Weather forecasting Protein folding How patterns arise in plants and animals Animation

Display Q: How to display result of simulation? A: Computer graphics (later in course) [Enright and Fedkiw 02]

Bigger questions Can computer simulation be replaced by a “theory of weather”? A “theory of tornadoes”? Is there a “theory” that answers this type of problem:  Given: A starting configuration in the game of life  Output: “Yes” if the cell at position (100, 100) is ever occupied, “No” otherwise Alan TuringAlbert Einstein

Actually, reverse trend: “theory of matter” (particle physics) is becoming computational. Hayes (reading this week): The universe as a “cellular automaton” 1670 F = ma Today

Peeking ahead: Game of life is actually a “computer.” A computer can simulate another computer (e.g., a Classic Mac simulator on a PC). Will explore the implications of this in a future lecture.

What does this pseudocode do? Write on a piece of paper and hand it in. n items, stored in array A Variables are i, S. S  0 Do for i = 1 to [n/2] { S  S + A[2*i]; }

Stable Matching Problem Problem: Given N men & N women, find “suitable” matching  Everyone lists their preferences from best to worst. ZeusBerthaAmyDianeErikaClare YanceyAmyClareDianeBerthaErika XavierBerthaClareErikaDianeAmy WyattDianeAmyBerthaClareErika VictorBerthaDianeAmyErikaClare Man 1 st 2 nd 3 rd 4 th 5 th Men’s Preference List worstbest

Stable Matching Problem ErikaYanceyZeusWyattXavierVictor DianeVictorYanceyZeusXavierWyatt ClareWyattYanceyXavierZeusVictor BerthaXavierYanceyWyattVictorZeus AmyZeusWyattVictorYanceyXavier Woman 1 st 2 nd 3 rd 4 th 5 th Women’s Preference List worstbest Problem: Given N men & N women, find “suitable” matching  Everyone lists their preferences from best to worst.

Stable matching: definition There is no pair such that they prefer each other more than their current partners.

Lavender assignment is a possible matching. Are there any unstable pairs? Men’s Preference List Women’s Preference List Zeus Yancey Xavier Man A B A 1 st B A B 2 nd C C C 3 rd Clare Bertha Amy Woman X X Y 1 st Y Y X 2 nd Z Z Z 3 rd  Yes. Bertha and Xavier form an unstable pair. They would prefer each other to current partners. B X A man & woman are currently unstable if they prefer each other more than their current partner

Example Green assignment is a stable matching. A B A CX X Y Y Y X Z Z Z Men’s Preference List Women’s Preference List Zeus Yancey Xavier Man1 st B A B 2 nd C C 3 rd Clare Bertha Amy Woman1 st 2 nd 3 rd

Example Gray assignment is also a stable matching. AX X Y Y Z Z Men’s Preference List Women’s Preference List Zeus Yancey Xavier Man1 st A B 2 nd C C 3 rd Clare Bertha Amy Woman1 st 2 nd 3 rd B A B C X Y Z

Propose-And-Reject Algorithm Guarantees a stable matching. Initialize each person to be free. while (some man m is free and hasn't proposed to every woman) { w = first woman on m's list to whom he has not yet proposed if (w is free) assign m and w to be engaged else if (w prefers m to her fiancé f) assign m and w to be engaged, and f to be free else w rejects m } Gale-Shapley Algorithm (men propose)

Extensions Unacceptable partners  Every woman is not willing to marry every man, and vice versa.  Some participants declare others as “unacceptable.” Sets of unequal size  Unequal numbers of men and women, e.g. 100 men & 90 women Limited Polygamy  e.g., Bill wants to be matched with 3 women.

Matching Residents to Hospitals Hospitals ~ Men (limited polygamy allowed). Residents ~ Women (more than hospitals) Started just after WWII (before computer usage). Ides of March, 13,000+ residents are matched. Rural hospital dilemma.  Certain hospitals (mainly in rural areas) were unpopular and declared unacceptable by many residents.  How to find stable matching that benefits rural hospitals?

Assignment for Valentine’s day (write on piece of paper and bring to class on Tues; participation grade) Try Gale-Shapley algorithm for previously-shown Amy-Erica / Victor-Zeuss preference lists, but vary the order of choosing man m. Does this affect the outcome? Try the version where women propose. Does this affect the outcome? Bonus question: Try to justify this statement The Gale-Shapley algorithm finishes at some point, and when it finishes, there are no unstable pairs.

Other homework Readings for this week (on blackboard): (i) Brian Hayes article; first 5 pages (ii) Brooks HW 1: Will be on website and has to be submitted in Class next Thurs