Changed linear regression to not account for log axes

This commit is contained in:
judsonupchurch 2025-04-01 00:12:36 +00:00
parent 867553353b
commit a1c931480f
44 changed files with 12 additions and 12 deletions

View File

@ -43,7 +43,7 @@ def replicate_base_loss(theta_array, desired_theta, base_key):
# ---------------------------------------------------------------------
# Helper: safe regression function (handles log transforms, filters invalid data)
# ---------------------------------------------------------------------
def safe_compute_best_fit(x, y, log_x=False, log_y=True):
def safe_compute_best_fit(x, y, log_x=False, log_y=False):
"""
Computes a best-fit line using linear regression, optionally on log(x) and/or log(y).
Returns:
@ -215,7 +215,7 @@ def process_condition(condition_name):
ax_top.set_ylabel(f"Final Loss @ epoch {final_epoch}")
ax_top.set_title(f"{condition_name}: Final Loss vs. Exponent")
# best-fit line
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["final_loss"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["final_loss"], log_x=False, log_y=False)
if xs is not None:
ax_top.plot(xs, y_fit, "k--", label=f"slope={slope:.3f}, int={intercept:.3f}, R²={R2:.3f}")
ax_top.legend(fontsize=8)
@ -236,7 +236,7 @@ def process_condition(condition_name):
ax_bot.set_ylabel("Epochs to Convergence")
ax_bot.set_title(f"{condition_name}: Convergence vs. Exponent")
# best-fit line
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["epochs_to_convergence"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["epochs_to_convergence"], log_x=False, log_y=False)
if xs is not None:
ax_bot.plot(xs, y_fit, "k--", label=f"slope={slope:.3f}, int={intercept:.3f}, R²={R2:.3f}")
ax_bot.legend(fontsize=8)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 KiB

After

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 KiB

After

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

After

Width:  |  Height:  |  Size: 280 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 KiB

After

Width:  |  Height:  |  Size: 275 KiB

View File

@ -43,7 +43,7 @@ def replicate_base_loss(theta_array, desired_theta, base_key):
# ---------------------------------------------------------------------
# Helper: safe regression function (handles log transforms, filters invalid data)
# ---------------------------------------------------------------------
def safe_compute_best_fit(x, y, log_x=False, log_y=True):
def safe_compute_best_fit(x, y, log_x=False, log_y=False):
"""
Computes a best-fit line using linear regression, optionally on log(x) and/or log(y).
Returns:
@ -215,7 +215,7 @@ def process_condition(condition_name):
ax_top.set_ylabel(f"Final Loss @ epoch {final_epoch}")
ax_top.set_title(f"{condition_name}: Final Loss vs. Exponent")
# best-fit line
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["final_loss"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["final_loss"], log_x=False, log_y=False)
if xs is not None:
ax_top.plot(xs, y_fit, "k--", label=f"slope={slope:.3f}, int={intercept:.3f}, R²={R2:.3f}")
ax_top.legend(fontsize=8)
@ -236,7 +236,7 @@ def process_condition(condition_name):
ax_bot.set_ylabel("Epochs to Convergence")
ax_bot.set_title(f"{condition_name}: Convergence vs. Exponent")
# best-fit line
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["epochs_to_convergence"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["Exponent"], df["epochs_to_convergence"], log_x=False, log_y=False)
if xs is not None:
ax_bot.plot(xs, y_fit, "k--", label=f"slope={slope:.3f}, int={intercept:.3f}, R²={R2:.3f}")
ax_bot.legend(fontsize=8)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 267 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 KiB

After

Width:  |  Height:  |  Size: 273 KiB

View File

@ -127,7 +127,7 @@ def find_convergence_epoch(data_dict, desired_theta, threshold):
# ---------------------------------------------------------------------
# Helper: Compute best-fit line (with R^2) for scatter plot data.
# ---------------------------------------------------------------------
def safe_compute_best_fit(x, y, log_x=False, log_y=True):
def safe_compute_best_fit(x, y, log_x=False, log_y=False):
"""
Computes the best-fit line using linear regression.
Filters out NaN and non-positive values if log transforms are used.
@ -256,7 +256,7 @@ for cond_name in all_subdirs:
axes[0].set_ylabel(f"Loss at Epoch {final_epoch}")
axes[0].set_yscale("log")
axes[0].set_title(f"{cond_name}: Loss vs. $t_{{median}}$")
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["final_loss"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["final_loss"], log_x=False, log_y=False)
if xs is not None:
axes[0].plot(xs, y_fit, "k--", label=f"Fit: slope={slope:.3f}, int={intercept:.3f}\n$R^2$={R2:.3f}")
axes[0].legend(fontsize=8)
@ -273,7 +273,7 @@ for cond_name in all_subdirs:
axes[1].set_ylabel("Epochs to Convergence")
axes[1].set_yscale("log")
axes[1].set_title(f"{cond_name}: Convergence vs. $t_{{median}}$")
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["epochs_to_convergence"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["epochs_to_convergence"], log_x=False, log_y=False)
if xs is not None:
axes[1].plot(xs, y_fit, "k--", label=f"Fit: slope={slope:.3f}, int={intercept:.3f}\n$R^2$={R2:.3f}")
axes[1].legend(fontsize=8)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 387 KiB

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 366 KiB

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 KiB

After

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 KiB

After

Width:  |  Height:  |  Size: 392 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 KiB

After

Width:  |  Height:  |  Size: 390 KiB

View File

@ -127,7 +127,7 @@ def find_convergence_epoch(data_dict, desired_theta, threshold):
# ---------------------------------------------------------------------
# Helper: Compute best-fit line (with R^2) for scatter plot data.
# ---------------------------------------------------------------------
def safe_compute_best_fit(x, y, log_x=False, log_y=True):
def safe_compute_best_fit(x, y, log_x=False, log_y=False):
"""
Computes the best-fit line using linear regression.
Filters out NaN and non-positive values if log transforms are used.
@ -256,7 +256,7 @@ for cond_name in all_subdirs:
axes[0].set_ylabel(f"Loss at Epoch {final_epoch}")
axes[0].set_yscale("log")
axes[0].set_title(f"{cond_name}: Loss vs. $t_{{median}}$")
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["final_loss"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["final_loss"], log_x=False, log_y=False)
if xs is not None:
axes[0].plot(xs, y_fit, "k--", label=f"Fit: slope={slope:.3f}, int={intercept:.3f}\n$R^2$={R2:.3f}")
axes[0].legend(fontsize=8)
@ -273,7 +273,7 @@ for cond_name in all_subdirs:
axes[1].set_ylabel("Epochs to Convergence")
axes[1].set_yscale("log")
axes[1].set_title(f"{cond_name}: Convergence vs. $t_{{median}}$")
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["epochs_to_convergence"], log_x=False, log_y=True)
xs, y_fit, slope, intercept, R2 = safe_compute_best_fit(df["t_median"], df["epochs_to_convergence"], log_x=False, log_y=False)
if xs is not None:
axes[1].plot(xs, y_fit, "k--", label=f"Fit: slope={slope:.3f}, int={intercept:.3f}\n$R^2$={R2:.3f}")
axes[1].legend(fontsize=8)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 KiB

After

Width:  |  Height:  |  Size: 374 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 341 KiB

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 338 KiB

After

Width:  |  Height:  |  Size: 356 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 KiB

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 384 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 KiB

After

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 KiB

After

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

After

Width:  |  Height:  |  Size: 280 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 KiB

After

Width:  |  Height:  |  Size: 275 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 267 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 KiB

After

Width:  |  Height:  |  Size: 273 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 387 KiB

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 366 KiB

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 KiB

After

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 KiB

After

Width:  |  Height:  |  Size: 392 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 KiB

After

Width:  |  Height:  |  Size: 390 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 KiB

After

Width:  |  Height:  |  Size: 374 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 341 KiB

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 338 KiB

After

Width:  |  Height:  |  Size: 356 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 KiB

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 384 KiB