Fixed typos, changed 'find parameters' output formatting
[cipher-tools.git] / find_best_caesar_break_parameters-2.py
index 88ca06c3f806288a0352c605c62650e4f00d3396..88de1dc8da1515679ca8b732162523a280ec37c9 100644 (file)
@@ -4,8 +4,6 @@ from cipher import *
 from cipherbreak import *
 import itertools
 
-print('Loading...')
-
 corpus = sanitise(''.join([open('shakespeare.txt', 'r').read(), 
     open('sherlock-holmes.txt', 'r').read(), 
     open('war-and-peace.txt', 'r').read()]))
@@ -15,9 +13,9 @@ euclidean_scaled_english_counts = norms.euclidean_scale(english_counts)
 
 metrics = [{'func': norms.l1, 'name': 'l1'}, 
     {'func': norms.l2, 'name': 'l2'},
-    {'func': norms.l3, 'name': 'l2'},
+    {'func': norms.l3, 'name': 'l3'},
     {'func': norms.cosine_distance, 'name': 'cosine_distance'},
-    {'func': norms.harmonic_mean, 'name': 'harminic_mean'},
+    {'func': norms.harmonic_mean, 'name': 'harmonic_mean'},
     {'func': norms.geometric_mean, 'name': 'geometric_mean'},
     {'func': norms.inverse_log_pl, 'name': 'inverse_log_pl'}]
 scalings = [{'corpus_frequency': normalised_english_counts, 
@@ -55,8 +53,13 @@ def eval_one_parameter_set(metric, scaling, message_length):
 
 def show_results():
     with open('caesar_break_parameter_trials.csv', 'w') as f:
-        for (k, v) in scores.items():
-            print(str(k)[1:-1], v, sep=",", file=f)
+        print(',message_length', file = f)
+        print('metric+scaling,', ','.join([str(l) for l in message_lengths]), file = f)
+        for (metric, scaling) in itertools.product(metrics, scalings):
+            print('{}:{}'.format(metric['name'], scaling['name']), end='', file=f)
+            for l in message_lengths:
+                print(',', scores[(metric['name'], scaling['name'], l)] / trials, end='', file=f)
+            print('', file = f)
 
 eval_all()
 show_results()