-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregression.py
56 lines (45 loc) · 1.51 KB
/
regression.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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import pandas as pd
import math
import random
from scipy import stats
def log_array(arr):
return np.array([math.log(e, 10) for e in arr])
def get_regression_line_coefficients(x, y):
return np.polyfit(log_array(x), log_array(y), 1)
def linear_regression():
def plot_size_vs_times_log_log(fname):
timings = pd.read_csv(fname, sep=',')
n = timings['n'].values
seconds = timings['seconds'].values
x = n
y = seconds
plt.loglog(x, y, 's', basex=2, basey=2, label=fname)
def plot_regression_lines(fname):
timings = pd.read_csv(fname, sep=',')
n = timings['n'].values
seconds = timings['seconds'].values
m, b = get_regression_line_coefficients(n, seconds)
plt.plot(x, m*x + b, label=f'{fname.rstrip(".csv")}: y ~ {round(m, 2)}x + {round(b, 2)}')
file_list = ["bubble.csv", "insertion.csv", "spin.csv", "shell5.csv", "shell3.csv", "annealing2.csv", "annealing6.csv"]
# Plot graph
plt.subplot(2, 1, 1)
for fname in file_list:
plot_size_vs_times_log_log(fname)
plt.grid(which='both')
plt.legend()
# Linear regression
x = np.array(range(6))
plt.subplot(2, 1, 2)
for fname in file_list:
plot_regression_lines(fname)
plt.legend()
plt.grid(which='both')
plt.xticks(x)
plt.yticks(np.arange(12))
plt.show()
#plt.savefig('regression.png')
plt.close()
linear_regression()