import numpy as np
from matplotlib import pyplot as plt
[docs]
def plot_regression(
x,
y,
coeffs,
prediction_xs=None,
):
plt.scatter(x, y, color="blue", label="Measured points")
# Generate smooth x values for plotting the regression curve
max_x = max(prediction_xs) if prediction_xs is not None else max(x)
x_smooth = np.linspace(0, max_x, 500)
y_smooth = coeffs[0] * (x_smooth ** 2) + coeffs[1] * x_smooth + coeffs[2]
plt.plot(x_smooth, y_smooth, color="red", label="Regression curve", linestyle="--")
if prediction_xs is not None:
prediction_ys = (
coeffs[0] * (prediction_xs ** 2) + coeffs[1] * prediction_xs + coeffs[2]
)
plt.scatter(
prediction_xs, prediction_ys, color="green", label="Predictions", marker="x"
)
plt.xlabel("Number of Texts")
plt.ylabel("Average Time (s)")
plt.title("Polynomial Regression of Measurement Times")
plt.legend()
plt.grid(True)
plt.show()
[docs]
def plot_scatter(x1s, y1s, label1, x2s, y2s, label2):
plt.scatter(x1s, y1s, color="red", label=label1)
plt.scatter(x2s, y2s, color="green", label=label2)
plt.xlabel("Number of Texts")
plt.ylabel("Independent Set Size")
plt.title("Comparison Optimal Greedy")
plt.legend()
plt.grid(True)
plt.show()
[docs]
class LinRegPredictor:
[docs]
def __init__(self, coeffs):
self.coeffs: list[int] = coeffs
[docs]
def predict(self, x):
return self.coeffs[0] * (x ** 2) + self.coeffs[1] * x + self.coeffs[2]
[docs]
def get_quadratic_coeff(self):
return self.coeffs[0]