To be or not to be

"Ford!" he said, "there’s an infinite number of monkeys outside who want to talk to us about this script for Hamlet they’ve worked out."

— Douglas Adams
The Hitchhiker's Guide to the Galaxy

It’s been hypothesized that an infinite number of monkeys could, eventually, type out the complete works of Shakespeare, even if hitting keys randomly. Via a "genetic algorithm" (GA) can we do better by helping a population of initially random strings evolve toward Shakespearean strings. Indeed, read through https://medium.com/generative-design/evolving-design-b0941a17b759 to learn how, stopping just before Optimality in multi-objective optimization. Via the Python code therein, excerpted below (with some corrections) as dna.py and script.py, does the author demonstrate how an initially random 18-character string can be evolved into "to be or not to be" (a phrase from Act III of Hamlet) after just 38 "generations" (i.e., iterations of generation, selection, crossover, and mutation). Notice how DNA, a class (not unlike Week 8's implementation of Student), actually represents an 18-character string, calling those characters genes, implemented as list, initialized with random characters via __init__.

Answer the below in shakespeare.md.

That is the question These are the questions

4.1 (1 point)

How many DNA objects (i.e., strings) does script.py initially generate?

4.2 (2 points)

Explain in English the algorithm with which update_fitness in dna.py calculates a string’s "fitness" (i.e., score).

4.3 (2 points)

If target is to be or not to be, as in dna.py, what is the fitness of KoMQ%25"zHnGt1whXY, as would be computed by update_fitness?

4.4 (2 points)

In no more than two sentences (not code), propose how edit distance could be used instead to calculate a string’s fitness.

4.5 (2 points)

In your own words, why does script.py "mutate" some of the characters in strings?

Debrief

  1. Which resources, if any, did you find helpful in answering this problem’s questions?

  2. About how long, in minutes, did you spend on this problem’s questions?