Study E — Impact of \(p_e\) on Convergence (Large Batch)¶
Replication of Study A with a larger batch size, to assess whether the convergence behaviour as a function of the sparsity \(p_e\) is stable with larger batch size.
Data generated by: run_study_E.py
Paper section: Appendix G.3 — Additional Sparsity Analysis (Figure 23)
Parameter |
Value |
|---|---|
Problem Size \(N\) |
100 |
Num. Parallel Nodes \(P\) |
1000 |
Learning Rate \(\alpha\) |
0.1 |
Batch Size \(M\) |
1000 |
Bernouilli Prob. \(p_e\) |
[0.001, 0.1] |
Max. Steps \(S\) |
10000 |
Oracle Proportion \(p_w\) |
0.5 |
[1]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import sys
import os
import glob
# Add parent directory to path
sys.path.append('..')
from plotting.plot_utility import plot_metric_vs_param, compute_steps_to_thresholds, setup_plot_style
%matplotlib inline
setup_plot_style()
[2]:
def get_latest_study_folder(study_prefix):
pattern = f'../studies/results/{study_prefix}_*/'
folders = glob.glob(pattern)
if folders:
return max(folders) # Latest by name (timestamp-based)
return None
mode = 'auto' # Change to 'manual' to specify your own path
if mode == 'auto':
results_dir = get_latest_study_folder('E_p_e_impact_large_batch')
if results_dir is None:
raise FileNotFoundError("No Study E results found. Run run_study_E.py first.")
print(f"Auto-detected folder: {results_dir}")
else:
results_dir = '../studies/results/E_p_e_impact_large_batch_XXXXXX_XXXXXX/'
print(f"Using manual path: {results_dir}")
p_e_values = np.load(results_dir + 'p_e_values.npy')
p_diff_matrix = np.load(results_dir + 'p_diff_matrix.npy')
steps_to_convergence = np.load(results_dir + 'steps_to_convergence.npy')
print(f"\np_e range: {p_e_values[0]:.6f} to {p_e_values[-1]:.6f}")
print(f"Number of p_e values: {len(p_e_values)}")
print(f"p_diff_matrix shape: {p_diff_matrix.shape}")
Auto-detected folder: ../studies/results/E_p_e_impact_large_batch_20260420_212337/
p_e range: 0.001000 to 0.100000
Number of p_e values: 50
p_diff_matrix shape: (50, 10000)
Error \(p_\text{diff}\) vs \(p_e\) — Iso-Step Curves¶
Same as Study A but with larger batch size (1000 instead of 100). Shows a similar behaviour despite the larger batch size.
[3]:
fig, ax = plt.subplots()
plot_metric_vs_param(
p_e_values,
p_diff_matrix,
ax,
draw_best=True,
best='min',
add_min_curve=False,
xscale='log',
yscale='linear',
xlim=(1e-3, 1e-1),
ylim=(0.02, 0.51),
)
ax.axvline(x=0.01, color='blue', linestyle='--', label='$p_e=1/N$')
ax.set_xlabel('$p_e$')
ax.set_ylabel('$\\frac{1}{P \\times N}\sum|w_i-w_i^\mathrm{true}|$')
ax.axvline(x=7e-2, color='red', linestyle='-')
p = patches.Rectangle((7e-2,0), 1, 10000, linewidth=0, fill=True, fc='white', ec='red', hatch='\\\\\\\\',zorder=2, label='Improvement $<10\%$')
ax.add_patch(p)
ax.legend(loc='upper left', bbox_to_anchor=(0.025,0.975))
plt.tight_layout()
plt.show()
Steps to Convergence vs \(p_e\) — Iso-\(p_\text{diff}\) Curves¶
Each curve corresponds to a fixed convergence threshold. Shows whether the \(p_e\) beahviour remains stable under larger batch training compared to Study A.
See Paper Appendix G.3. Figure 23.
[4]:
thresholds, steps_data = compute_steps_to_thresholds(p_e_values, p_diff_matrix, n_thresholds=999)
fig, ax = plt.subplots()
plot_metric_vs_param(
p_e_values,
steps_data+1,
ax,
draw_best=True,
xscale='log',
yscale='log',
xlim=(1e-3, 1e-1),
ylim=(100, 25_000),
value_labels=thresholds,
add_min_curve=False
)
ax.axvline(x=0.01, color='blue', linestyle='--', label='$p_e=1/N$')
ax.set_xlabel('$p_e$')
ax.set_ylabel('Steps to convergence')
ax.axvline(x=7e-2, color='red', linestyle='-')
p = patches.Rectangle((7e-2,0), 1, 25000, linewidth=0, fill=True, fc='white', ec='red', hatch='\\\\\\\\',zorder=2, label='Improvement $<10\%$')
ax.add_patch(p)
ax.legend(loc='upper right', bbox_to_anchor=(0.99,0.99))
plt.tight_layout()
plt.show()