Added letter frequency treemap impage
[cipher-training.git] / slides / caesar-break.html
index 4d2ebfa0d01d556dbdd37599f3e4320f92fc4031..81a8396f6d7d8d67b841d5925e17c2a545e4405f 100644 (file)
@@ -112,6 +112,8 @@ How do we define "closeness"?
 
 ## Abstraction: frequency of letter counts
 
+.float-right[![right-aligned Letter frequencies](letter-frequency-treemap.png)]
+
 Letter | Count
 -------|------
 a | 489107
@@ -128,11 +130,11 @@ Use this to predict the probability of each letter, and hence the probability of
 
 ---
 
-# An infinite number of monkeys
+.float-right[![right-aligned Typing monkey](typingmonkeylarge.jpg)]
 
-What is the probability that this string of letters is a sample of English?
+# Naive Bayes, or the bag of letters
 
-## Naive Bayes, or the bag of letters
+What is the probability that this string of letters is a sample of English?
 
 Ignore letter order, just treat each letter individually.
 
@@ -146,7 +148,7 @@ Letter      | i       | f       | m       | m       | p       | ifmmp
 ------------|---------|---------|---------|---------|---------|-------
 Probability | 0.06723 | 0.02159 | 0.02748 | 0.02748 | 0.01607 | 1.76244520 × 10<sup>-8</sup>
 
-(Implmentation issue: this can often underflow, so get in the habit of rephrasing it as `\( \sum_i \log p_i \)`)
+(Implmentation issue: this can often underflow, so we rephrase it as `\( \sum_i \log p_i \)`)
 
 Letter      | h       | e       | l       | l       | o       | hello
 ------------|---------|---------|---------|---------|---------|-------
@@ -207,6 +209,8 @@ Text encodings will bite you when you least expect it.
 # Five minutes on StackOverflow later...
 
 ```python
+import unicodedata
+
 def unaccent(text):
     """Remove all accents from letters. 
     It does this by converting the unicode string to decomposed compatibility
@@ -234,8 +238,13 @@ def unaccent(text):
 
 1. Read from `shakespeare.txt`, `sherlock-holmes.txt`, and `war-and-peace.txt`.
 2. Find the frequencies (`.update()`)
-3. Sort by count 
-4. Write counts to `count_1l.txt` (`'text{}\n'.format()`)
+3. Sort by count (read the docs...)
+4. Write counts to `count_1l.txt` 
+```python
+with open('count_1l.txt', 'w') as f:
+    for each letter...:
+        f.write('text\t{}\n'.format(count))
+```
 
 ---
 
@@ -257,6 +266,8 @@ def unaccent(text):
 
 # Breaking caesar ciphers
 
+New file: `cipherbreak.py`
+
 ## Remember the basic idea
 
 ```