-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_driver.py
122 lines (95 loc) · 4.07 KB
/
analysis_driver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from lib.analysisLib import *
import csv
import matplotlib.pyplot as plt
from os.path import isdir
from os import mkdir
from datetime import datetime
import config
# TODO #####################
# * Need to make a test config. Will be config.py
# to replace the garbage below cluttering up the driver.
def fixed_domain_plots(domain, min_codomain, max_codomain, num_tests, codomain_skip=5):
per_dat_points = []
co_dat_points = []
codomain = min_codomain
for codomain in range(min_codomain, max_codomain + 1, codomain_skip):
actual_per, _ = test(domain, codomain, num_tests)
per_dat_points.append(actual_per)
co_dat_points.append(codomain)
plt.ylim(0, 105)
plt.scatter(co_dat_points, per_dat_points)
plt.title("Fixed Domain Plot, k = " + str(domain) + ", Number of Tests: " + str(num_tests))
plt.xlabel("Codomain Size")
plt.ylabel("% Actual Injective")
savepath = config.fixed_domain + str(datetime.now()) + '/'
if not isdir(config.fixed_domain):
mkdir(config.fixed_domain)
if not isdir(savepath):
mkdir(savepath)
plt.savefig(savepath + "d" + str(domain) + "tests" + str(num_tests) + ".png")
plt.clf()
def theoretical_fixed_domain(domain, min_codomain, max_codomain, codomain_skip=5):
per_dat_points = []
co_dat_points = []
for codomain in range(min_codomain, max_codomain + 1, codomain_skip):
per_dat_points.append(theoretical_prob_injective(domain, codomain))
co_dat_points.append(codomain)
if not isdir(config.theo_fixed_domain):
mkdir(config.theo_fixed_domain)
savepath = config.theo_fixed_domain + str(datetime.now()) + '/'
if not isdir(savepath):
mkdir(savepath)
plt.ylim(0, 105)
plt.scatter(co_dat_points, per_dat_points)
plt.title('Theoretical Fixed Domain Plot, k = ' + str(domain))
plt.xlabel('Codomain Size')
plt.ylabel('Probability of Injectiveness')
plt.savefig(savepath + 'd' + str(domain) + '.png')
plt.clf()
def fixed_r_plots(min_r, max_r, min_domain, max_domain, num_tests, domain_skip=5):
savepath = config.fixed_r + str(datetime.now()) + '/'
if not isdir(config.fixed_r):
mkdir(config.fixed_r)
if not isdir(savepath):
mkdir(savepath)
for r in range(min_r, max_r + 1): # the ratio codomain/domain
per_dat_points = []
dom_dat_points = []
for domain in range(min_domain, max_domain + 1, domain_skip):
actual_per, actual_count = test(domain, r*domain, num_tests)
# data points
per_dat_points.append(actual_per)
dom_dat_points.append(domain)
plt.ylim(0, 105)
plt.scatter(dom_dat_points, per_dat_points)
plt.title("Fixed r Plot, r = " + str(r) + ", Number of Tests: " + str(num_tests))
plt.xlabel("Domain Size")
plt.ylabel("% Actual Injective")
plt.savefig(savepath + "r" + str(r) + "tests" + str(num_tests) + ".png")
plt.clf()
def theoretical_fixed_r(min_r, max_r, min_domain, max_domain, domain_skip=5):
r = min_r
if not isdir(config.theo_fixed_r):
mkdir(config.theo_fixed_r)
savepath = config.theo_fixed_r + str(datetime.now()) + '/'
if not isdir(savepath):
mkdir(savepath)
for r in range(min_r, max_r + 1):
per_dat_points = []
dom_dat_points = []
for domain in range(min_domain, max_domain + 1, domain_skip):
per_dat_points.append(theoretical_prob_injective(domain, r*domain))
dom_dat_points.append(domain)
plt.ylim(0, 105)
plt.scatter(dom_dat_points, per_dat_points)
plt.title("Theoretical Fixed r Plot, r = " + str(r))
plt.xlabel("Domain Size")
plt.ylabel("Probabilty of Injectiveness")
plt.savefig(savepath + "r" + str(r) + ".png")
plt.clf()
# Reading in the config and running tests #########################################
# func = name of function to call from config.py
# idx = index of function -> parameters
for idx, func in enumerate(config.tests_to_run):
globals()[func](*config.test_params[idx])
print(idx, func)