-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfit.py
More file actions
25 lines (20 loc) · 699 Bytes
/
fit.py
File metadata and controls
25 lines (20 loc) · 699 Bytes
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
import os
import matplotlib.pyplot as plt
import scipy.optimize
from utils import RESULTS_PATH
import logging
def linear(x, *params):
a, b = params
return a * x + b
def fit_linear(x_values, y_values, title):
# print("Do fit")
(a, b), _ = scipy.optimize.curve_fit(linear, x_values, y_values, p0=[2, 1])
plt.figure()
# plt.title(f"Error rates of {title}; slope %.3f" % a)
logging.info(f"Error rates of {title}; slope %.3f" % a)
plt.scatter(x_values, y_values, marker="*")
plt.plot(x_values, linear(x_values, a, b))
plt.xlabel("$log_{10}(N)$")
plt.ylabel("$log_{10}($error$)$")
plt.savefig(os.path.join(RESULTS_PATH, f"{title}.png"))
plt.show()