Presentation is loading. Please wait.

Presentation is loading. Please wait.

HMC’s Galileo Auditorium Some of Cope’s generated MP3s:

Similar presentations


Presentation on theme: "HMC’s Galileo Auditorium Some of Cope’s generated MP3s:"— Presentation transcript:

1 HMC’s Galileo Auditorium Some of Cope’s generated MP3s:
Experiments in Musical Intelligence I began Experiments in Musical Intelligence in 1981 as the result of a composer's block. My initial idea involved creating a computer program which would have a sense of my overall musical style and the ability to track the ideas of a current work such that at any given point I could request a next note, next measure, next ten measures, and so on. My hope was that this new music would not just be interesting but relevant to my style and to my current work. Having very little information about my style, however, I began creating computer programs which composed complete works in the styles of various classical composers, about which I felt I knew something more concrete. Since the early days of Experiments in Musical Intelligence, many audiences have heard its output in the styles of classical composers. The works have delighted, angered, provoked, and terrified those who have heard them. I do not believe that the composers and audiences of the future will have the same reactions. Ultimately, the computer is just a tool with which we extend our minds. The music our algorithms compose are just as much ours as the music created by the greatest of our personal human inspirations. Nelson Series Talk Wed, 10/ :00 pm HMC’s Galileo Auditorium Some of Cope’s generated MP3s: arts.ucsc.edu/faculty/cope/mp3page.htm David Cope, UC Santa Cruz

2 Still seeking a costume?
Week 9 in CS 5 Lab: M-Z A dizzying array of possibilities… HW 9 (2 probs) due Sunday, 10/31 at midnight M/T due Monday, 11/1 at midnight W/Th Reading: Week 9’s online notes Recitation for HW9 -- Friday 10/29 This week’s credits: John Conway Still seeking a costume? Carl Gauss

3 “Pass By Value” 7 public static void main(String[] args) {
H.pl(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.pl(fav + “ is my favorite, too!”); } public static void conform(int fav) fav = 42; return; 7 int fav int fav

4 “Pass by value” means that data is copied when sent to a method
public static void main(String[] args) { H.pl(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.pl(fav + “ is my favorite, too!”); } public static void conform(int fav) fav = 42; return; 7 int fav PASS BY VALUE 7 42 int fav “Pass by value” means that data is copied when sent to a method

5 Passing Arrays by Value
public static void main(String[] args) { H.pl(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.pl(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav[0] = 42; fav[1] = 42; return; int[] fav fav[0] fav[1] int[] fav

6 Passing Arrays by Value
public static void main(String[] args) { H.pl(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.pl(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav[0] = 42; fav[1] = 42; return; int[] fav fav[0] fav[1] can change data elsewhere! int[] fav

7 Views of the world

8 Views of the world Engineers think their equations are an approximation to reality.

9 Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations.

10 Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care. 

11 Creating structure from a few simple facts...
Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple facts... ? Axioms Definitions 20˚ 10˚ 60˚ Proof 70˚

12 The John Conway Challenge….
? 20˚ 10˚ 60˚ 70˚ (without using trig)

13 Views of the world Proof Algorithm
Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple actions ... Creating structure from a few simple facts... for arrays variables Axioms while Definitions arithmetic operations if/else Proof Algorithm

14 they don’t have to be horizontal lists!
Arrays’ flexibility Arrays can be of ANY type double[] A; 42.0 75.0 70.0 A = new double[3]; double[] double double double A they don’t have to be horizontal lists!

15 they don’t have to be horizontal lists!
Arrays’ flexibility Arrays can be of ANY type double[] A; 42.0 75.0 70.0 A = new double[3]; double[] double double double A 42.0 double[] double they don’t have to be horizontal lists! A 75.0 double 70.0 double

16 Arrays’ flexibility Arrays can be of ANY type double[] A; int[] A;
42.0 75.0 70.0 A = new double[3]; double[] double double double A int[] A; 42 7 -11 A = new int[3]; int[] int int int A String[] A; “go” “red” “sox!” A = new String[3]; String[] String String String A

17 2d arrays Arrays can be of ANY type -- so what type of array is A ?
double[][] A; double[][] A

18 A is an array of double arrays!
2d arrays Arrays can be of ANY type -- even other arrays! double[][] A; A is an array of double arrays! double[][] A

19 2d arrays Arrays can be of ANY type -- even other arrays!
double[][] A; A = new double[3][]; double[] double[][] A[0] A double[] A[1] double[] A[2]

20 Jagged arrays Rows of 2d arrays need not be the same length!
double[][] A; A = new double[3][]; double[] double[][] A[0] double double double double A double[] A[1] double double double[] A[2] double double double double double A[0] = new double[4]; A[1] = new double[2]; A[2] = new double[5];

21 We will not use jagged arrays
Rows of 2d arrays need not be the same length! double[][] A; A = new double[3][]; double[] double[][] A[0] double double double double A double[] A[1] double double double[] A[2] double double double double double A[0] = new double[4]; A[1] = new double[2]; A[2] = new double[5];

22 Rectangular arrays But there’s a shortcut to creating them if they are... double[][] A; rows cols A = new double[3][4]; double[] double[][] double double double double A[0] A double[] double double double double A[1] double[] A[2] double double double double

23 double[][] A = new double[3][4];
2d arrays Getting at individual elements: rows cols double[][] A = new double[3][4]; double[] double[][] double double double double A[0] A A[0][0] double[] double double double double A[1] double[] A[2] double double double double A[2][3] A[1][2] = 10.0

24 these will be variables
2d arrays: Input public static void main(String[] args) { double[][] A = new double[3][4]; H.pl(“Input your values:”) for (int r=0 ; r<3 ; ++r) for (int c=0 ; c<4 ; ++c) A[r][c] = H.nd(); } these will be variables no i or j ?

25 how do we find the number of rows and the number of columns?
2d arrays: Input Method public static void enterValues(double[][] A) { H.pl(“Input your values:”); for (int r=0 ; r < ; ++r) for (int c=0 ; c < ; ++c) A[r][c] = H.nd(); } how do we find the number of rows and the number of columns? number of rows number of columns

26 number of columns in row r
2d arrays: Output public static void print(double[][] A) { for (int r = 0; r < A.length; ++r) for (int c = 0; c < A[r].length; ++c) H.p( } number of rows number of columns in row r I/O formatting reference:

27 Problem 1 An array of array handlers... Initial Setup Menu Methods
Get the number of rows and columns Create an array of the appropriate number of elements (doubles). Get initial values from the user into the array. printMenu enterValues print multRow addRowaIntoRowb addMxRowaIntoRowb solve Menu (0) Change the values in the array (1) Print the array (2) Multiply an array row (3) Add one row to another (4) Add a multiple of one row to another (5) Solve! (9) Quit Which choice would you like? Methods

28 What are the resulting values in A?
Before “Quiz” row 0 Starting with the 2d array A shown here, what are the values in A after running this code? row 1 row 2 col 0 col 1 col 2 col 3 public static void mysteryMethod(int[][] A) { for (int r = 0 ; r < A.length ; ++r) for (int c = 0 ; c < A[r].length ; ++c) if (r == c) A[r][c] = 42; } else A[r][c] = A[r][c] + 1; } // end of mystery method A After What are the resulting values in A?

29 “Quiz” A A example before example after 0.00 1.00 0.00 1.00
row 0 Write a method that adds two times the values in row #1 into the values in row #2. The values in row #1 should not change! (The values in row #0 also don’t change!) row 1 two of row 1 are to be added to row 2 row 2 row 0 row 1 row 2 A example after public static void addTwoOfRow1IntoRow2(double[][] A) { }

30 Adding one row to another...
Before A After public static void addRowaIntoRowb(double[][] A, int ra, int rb) { }

31 Adding one row to another...
Before A After 2 public static void addRowaIntoRowb(double[][] A, int ra, int rb) { }

32 Problem 1 An array of array handlers... Initial Setup Menu Methods
Get the number of rows and columns Create an array of the appropriate number of elements (doubles). Get initial values from the user into the array. printMenu enterValues print multRow addRowaIntoRowb addMxRowaIntoRowb solve Menu (0) Change the values in the array (1) Print the array (2) Multiply an array row (3) Add one row to another (4) Add a multiple of one row to another (5) Solve! (9) Quit Which choice would you like? Methods

33 Gaussian Elimination Goal: Find p,n,q 2p + 3n + -1q = -8.00
Carl Gauss is so money! 2p n q = -3p n q = 1p n q = Goal: Find p,n,q

34 Gaussian Elimination Goal: get 1s along the diagonal Find p,n,q
get 0s elsewhere on the left 1p n q = 0p n q = 0p n q =

35 Gaussian Elimination Goal: get 1s along the diagonal Find p,n,q
Carl Gauss is money. 2p n q = -3p n q = 1p n q = get 1s along the diagonal Goal: Find p,n,q get 0s elsewhere on the left 1p n q = 0p n q = 0p n q = Using only row operations (our methods) ! Just the array is necessary ! We can get rid of the variables... where to start?

36 Solve multiply Row 0 by 0.5

37 a hint as to the direction to head next… !
Solve multiply Row 0 by 0.5 a hint as to the direction to head next… !

38 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2
Solve multiply Row 0 by 0.5 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2

39 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2
Solve multiply Row 0 by 0.5 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 add a multiple of Row 1 to Row 0 multiply Row 1 by 1/ add a multiple of Row 1 to Row 2

40 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2
Solve multiply Row 0 by 0.5 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 add a multiple of Row 1 to Row 0 multiply Row 1 by 1/ add a multiple of Row 1 to Row 2 same for other columns and so on...

41 Problem 2 -- “Life” Grid World black cells are alive
John Conway Grid World black cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors 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) white cells are empty

42 Problem 2 -- Life Grid World black cells are alive Evolutionary rules
Everything depends on a cell’s eight neighbors 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) white cells are empty

43 Problem 2 -- Life Grid World black cells are alive Evolutionary rules
Everything depends on a cell’s eight neighbors 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) white cells are empty

44 Problem 2 -- Life Grid World Pair Program black cells are alive
Evolutionary rules Everything depends on a cell’s eight neighbors 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) Keep going! white cells are empty life out there...

45 Problem 2 -- Creating Life
update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

46 Problem 2 -- Creating Life
update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

47 Problem 2 -- Details update(int[][] last, int[][] next)
new generation old generation 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

48 Problem 2 -- Details What will this do?
public static void update(int[][] last, int[][] next) { for (int r=1 ; r<last.length-1 ; ++r) for (int c=1 ; c<last[r].length-1 ; ++c) int oldvalue = last[r][c]; if (oldvalue == 0) // look at last next[r][c] = 1; // assign to next else next[r][c] = 0; }

49 How does this change things?
Problem 2 -- Details How does this change things? public static void update(int[][] last, int[][] next) { for (int r=1 ; r<last.length-1 ; ++r) for (int c=1 ; c<last[r].length-1 ; ++c) int oldvalue = last[r-1][c-1]; if (oldvalue == 0) next[r][c] = 1; else next[r][c] = 0; }

50 Problem 2 – Multi-species Life (!)
updateMulti(int[][] last, int[][] next) Create a set of rules to evolve two species of cells (plus empty). The Challenge Give both species a good chance of survival in the same environment. more species are OK, too… 1 2 stability is an open biological question…

51 Lab this week Lab: M-Z Problem 1: Gaussian Elimination
printMenu enterValues print multRow addRowaToRowb addMxRowaToRowb solve You’ll need to write (and use) Problem 2: Life and Multi-species Life! 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5 public void update(int[][] last, int[][] next) public void updateMulti(int[][] last, int[][] next) A matrix-inverse feature for Problem 1 ... Extra Credit: Doughnut Life for Problem 2 …

52 What are the resulting values in A?
Before “Quiz” row 0 Starting with the 2d array A shown here, what are the values in A after running this code? row 1 row 2 col 0 col 1 col 2 col 3 public static void mysteryMethod(int[][] A) { for (int r = 0 ; r < A.length ; ++r) for (int c = 0 ; c < A[r].length ; ++c) if (r == c) A[r][c] = 42; } else A[r][c] = A[r][c] + 1; } // end of mystery method A After What are the resulting values in A?

53 “Quiz” A A example before example after 0.00 1.00 0.00 1.00
row 0 Write a method that adds two times the values in row #1 into the values in row #2. The values in row #1 should not change! (The values in row #0 also don’t change!) row 1 two of row 1 are to be added to row 2 row 2 row 0 row 1 row 2 A example after public static void addTwoOfRow1IntoRow2(double[][] A) { }

54 Watch out! public static void main(String[] args) {
H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav + “ and ” + fav + “! Me too!”); } int[] fav fav[0] fav[1] What will happen here?!

55 Watch out! public static void main(String[] args) {
H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav = new int[2]; fav[0] = 42; fav[1] = 42; return; int[] fav fav[0] fav[1] int[] fav

56 Still seeking a costume?
This week in IS 313 A dizzying array of possibilities... HW 7 (2 problems) due Thursday, 11/7 at midnight Reading: Week 9’s online notes This week’s credits: John Conway Still seeking a costume? Carl Gauss

57 Survival of the stablest
The Questions of Life... what are stable “life” forms? how densely can they grow? can they be unbounded spatially? how fast can they travel? can they grow forever?

58 “Pass By Value” public static void main(String[] args) {
H.out.println(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.out.println(fav + “ is my favorite, too!”); }

59 3.14 7

60

61

62 int age

63 A method for multiplying columns:
Using 2d arrays arr Before arr After A method for multiplying columns: MONUMENTAL COLUMNS HANDLED MONUMENTALLY WELL. The eight massive Corinthian columns at the National Building Museum in Washington, D.C., are among the largest interior columns in the world: 75 ft. high and 8 ft. in dia., the columns have a brick core (over 70,000 bricks each!) covered with stucco.

64 Solving ?! Gaussian Elimination Goal: get 1s along the diagonal
2p n q = -3p n q = 1p n q = Gaussian Elimination get 1s along the diagonal Goal: Find p,n,q get 0s elsewhere on the left 1.00p n q = -3.00p n q = 1.00p n q = multiply the zeroth row (R0) by 0.5 1.00p n q = 0.00p n q = -0.00p n q = add 3 times R0 to R1 add -1 times R0 to R2

65 Solved ! 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00
multiply R1 by 1 / 3.5 1.00p n q = 0.00p n q = -0.00p n q = add -1.5 times R1 to R0 add 10.5 times R1 to R2 1.00p n q = 0.00p n q = -0.00p n q = add 3 times R0 to R1 add -1 times R0 to R2 continue... 1.00p n q = 0.00p n q = -0.00p n q = only the array is necessary !

66 Solved ! 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00
multiply R1 by 1 / 3.5 1.00p n q = 0.00p n q = -0.00p n q = add -1.5 times R1 to R0 add 10.5 times R1 to R2 1.00p n q = 0.00p n q = -0.00p n q = add 3 times R0 to R1 add -1 times R0 to R2 continue... 1.00p n q = 0.00p n q = -0.00p n q = only the array is necessary !

67 Still seeking a costume?
This week in IS 313 A dizzying array of possibilities... HW 7 (2 problems) due Thursday, 11/8 at midnight Reading: Week 9’s online notes Also: threads and Life ! John Conway Still seeking a costume? Carl Gauss

68 “Pass by value” means that data is copied when sent to a method
public static void main(String[] args) { H.out.println(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.out.println(fav + “ is my favorite, too!”); } public static void conform(int fav) fav = 42; 7 int fav PASS BY VALUE 7 42 int fav “Pass by value” means that data is copied when sent to a method

69 Passing Arrays by Value
public static void main(String[] args) { H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav[0] = 42; fav[1] = 42; return;

70 Watch out! public static void main(String[] args) {
H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav = new int[2]; fav[0] = 42; fav[1] = 42; return;

71 Creating structure from a few simple facts...
Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple facts... ? Axioms Definitions 20˚ 10˚ 60˚ Proof 70˚

72 Views of the world Proof Algorithm
Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple actions... Creating structure from a few simple facts... for arrays variables Axioms while Definitions arithmetic operations if/else Proof Algorithm

73 Jagged arrays Rows of 2d arrays need not be the same length!
double[][] arr; arr = new double[3][]; arr[0] = new double[4]; arr[1] = new double[2]; arr[2] = new double[5]; double[] double[][] double double double double arr[0] arr double[] double double arr[1] double[] arr[2] double double double double double

74 Rectangular arrays But there’s a shortcut to creating them if they are... double[][] arr; arr = new double[3][4]; double[] double[][] double double double double arr[0] arr double[] double double double double arr[1] double[] arr[2] double double double double

75 more likely to be variables
2d arrays: Input public static void main(String[] args) { double[][] arr = new int[3][4]; for (int r=0 ; r<3 ; ++r) for (int c=0 ; c<4 ; ++c) arr[r][c] = H.in.nextDouble(); } more likely to be variables no i or j ?

76 how do we find the number of rows and the number of columns?
2d arrays: Input Method public static void enterArray(double[][] arr) { for (int r=0 ; r < ; ++r) for (int c=0 ; c < ; ++c) arr[r][c] = H.in.nextDouble(); } how do we find the number of rows and the number of columns? number of rows number of columns

77 Problem 1 An array of array handlers... Initial Setup Menu Methods
Get the number of rows and columns Create an array of the appropriate number of elements (doubles). Get initial values from the user into the array. printMenu enterArray printArray multRow addR1ToR2 addMR1ToR2 solve Menu (0) Change the values in the array (1) Print the array (2) Multiply an array row (3) Add one row to another (4) Add a multiple of one row to another (5) Solve! (9) Quit Which choice would you like? Methods

78 Adding one row to another...
arr Before arr After public static void addR1ToR2(double[][] arr, int rFrom, int rTo) { }

79 Only the array is necessary ! We can get rid of the variables...
Gaussian Elimination Carl Gauss is so money! 2p n q = -3p n q = 1p n q = get 1s along the diagonal Goal: Find p,n,q get 0s elsewhere on the left 1p n q = 0p n q = 0p n q = Only the array is necessary ! We can get rid of the variables...

80 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2
Solve multiply Row 0 by 0.5 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 repeat for column 2 and column 3 and so on...

81 Problem 2 -- “Life” Grid World black cells are alive
John Conway Grid World black cells are alive Evolutionary rules Everything depends on one’s eight neighbors 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) white cells are empty

82 Problem 2 -- Life Grid World black cells are alive Evolutionary rules
Everything depends on one’s eight neighbors 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) white cells are empty

83 Problem 2 -- Life Grid World black cells are alive Evolutionary rules
Everything depends on one’s eight neighbors 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) white cells are empty

84 Problem 2 -- Life Grid World black cells are alive Evolutionary rules
Everything depends on one’s eight neighbors 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) Keep going! white cells are empty life out there...

85 Problem 2 -- Creating Life
public void update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

86 Problem 2 -- Creating Life
public void update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

87 Problem 2 -- Details public void update(int[][] last, int[][] next)
new generation old generation For each generation… 0 represents an empty cell 1 represents a living cell outermost edge should always be empty (even if there are 3 neighbors) compute all cells based on their previous neighbors before updating any of them


Download ppt "HMC’s Galileo Auditorium Some of Cope’s generated MP3s:"

Similar presentations


Ads by Google