September 27, 2019
For today
Read Chapter 5 of Think Complexity and do the reading quiz
Turn in Notebook 04
Refine your plan for the project and team; we will finalize next time
Today
Analysis of algorithms
Cellular automata
Project work/discussions
For next time:
Turn in your project proposal
Read Chapter 6 of Think Complexity and do the reading quiz
Suppose each cell in a 1-D CA has 3 states, and the size of the neighborhood is 3 cells. What is the total number of CAs of this type?
1) List comprehensions turned out not to be substantially faster in this case. Could be a Python 3 thing.
2) make_regular_graph looks good. Can we prove that n*k has to be even?
3) For the bad version of Dijkstra's algorithm, I was hoping to see evidence that it fails.
What do we think of this?
def make_regular_graph(n, k): if (k%2==1 and n%2==1): raise ValueError("bad!") ring = make_ring_lattice(n, 2*math.ceil(k/2)) if k%2 and k!=(n-1): for i in range(0, n, 2): ring.remove_edge(i, i+1) return ring
def make_regular_graph(n, k): if n < (k + 1) or (n*k)%2==1: raise ValueError('invalid combination of n and k') if k%2==0: return make_ring_lattice(n, k) else: G = make_ring_lattice(n, k-1); for node in G.nodes(): neighbor = (node + n/2) % n G.add_edge(node, neighbor) return G
To analyze Python code, you have to know the performance of basic operations. If you have a mental model of the implementation, they are easier to remember.
For each of the functions below, what is the order of growth? For functions of two strings, you can assume that both strings have length n.
def is_anagram(word1, word2):
t = list(word2)
for char in word1:
if char not in t:
return False
t.remove(char)
return len(t) == 0
def is_anagram(word1, word2):
return sorted(word1) == sorted(word2)
from collections import Counter
def is_anagram(word1, word2):
return Counter(word1) == Counter(word2)
def my_counter(word):
d = {}
for c in word:
d[c] = d.get(c, 0) + 1
return d
def is_anagram(word1, word2):
return my_counter(word1) == my_counter(word2)
You can see why analysis of algorithms can be tricky in high-level languages.
We'll do more of these next time.
Reading questions from Chapter 5
1) What was Wolfram's experiment?
2) What was the result of the experiment?
3) Why is class 3 surprising?
4) Why is class 4 surprising?
5) What is the Church-Turing thesis?
6) What is the principle of computational equivalence?
Chapter 5 introduces NumPy arrays.
And cross-correlation, which is related to convolution!
Using [4, 2, 1] as a kernel is a "trick" that comes up often:
1) The dollar store puzzle: You send your friend to the store with a shopping list. There are three items on the list, and you know that the price of each item is less than one dollar. You want to know the price of each item, but your friend will only tell you the total. How many of each item should you tell your friend to buy?
2) Godel numbering uses a similar trick, except it uses exponentiation-multiplication instead of multiplication-add.
3) We'll use variations on this trick to implement GoL and other 2D CAs.
Next Tuesday I will try to meet with all teams to
Assess your proposal
Review your plans for extension
Make helpful suggestions
For the replication, you should be prepared to present answers to these questions:
What experiment are you replicating? Who did it? Any relevant background on the people or the publication?
What question was their experiment intended to answer? Is it a prediction, explanation, or design question?
How did they go about answering it?
What was the result of the experiment?
How does this result answer the question?
Have you replicated the experiment? Any important details to report?
Did the experiment replicate? If so, how do you show that your results agree with theirs? If not, do you understand why not?
For 4 and 5, you will probably show and interpret a figure from the original paper.
For 6 and 7, you will probably show a figure you generated.
For the extension, you should be prepared to present answers to these questions:
What question will your experiment answer?
What methodological changes will you have to make?
What might the results look like?
How will you interpret the results?
For 3 and 4, you might want to draw a cartoon of 1-2 possible results.
Notice that this is a LOT of information to convey in a short meeting. The more you prepare, the more efficiently we will be able to communicate.
After we talk, try to capture this material and get it into a draft of your report.