<jupyter_start><jupyter_text>Example: D-optimal experiment design with LIBSVM datasetsSolve the D-Optimal experiment design problem$$\begin{array}{ll}\textrm{minimize}   & F(x):=\log\left(\det\left(\sum_{i=1}^n x_i V_i V_i^T\right)\right) \\\textrm{subject to} & \sum_{i=1}^n x_i = 1, \\                     & x_i\geq 0, \quad i=1,\ldots,n\end{array}$$where $V_i\in R^m$ for $i=1,\ldots,n$.<jupyter_code># cd C:\\github\accbpg
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams.update({'font.size': 18, 'legend.fontsize':14, 'font.family': 'serif'})
# matplotlib.rcParams.update({'text.usetex': True})<jupyter_output><empty_output><jupyter_text>Compare BPG and ABPG with different values of gamma<jupyter_code>import accbpg

# Generate a D-optimal design problem from LIBSVM regression dataset

#filename = "data\\abalone.txt"
#filename = "data\\abalone_scale.txt"
#filename = "data\\bodyfat.txt"
#filename = "data\\bodyfat_scale.txt"
filename = "data\\housing.txt"
#filename = "data\\housing_scale.txt"
#filename = "data\\mpg.txt"
#filename = "data\\mpg_scale.txt"

f, h, L, x0 = accbpg.D_opt_libsvm(filename)

# Solve the problem using BPG and ABPG with different values of gamma (TSE) 
x00, F00, G00, T00 = accbpg.BPG( f, h, L, x0, maxitrs=5000, linesearch=False, ls_ratio=1.2, verbskip=1000)
x10, F10, G10, T10 = accbpg.ABPG(f, h, L, x0, gamma=1.0, maxitrs=5000, theta_eq=True, verbskip=1000)
x15, F15, G15, T15 = accbpg.ABPG(f, h, L, x0, gamma=1.5, maxitrs=5000, theta_eq=True, verbskip=1000)
x20, F20, G20, T20 = accbpg.ABPG(f, h, L, x0, gamma=2.0, maxitrs=5000, theta_eq=True, verbskip=1000)
x22, F22, G22, T22 = accbpg.ABPG(f, h, L, x0, gamma=2.2, maxitrs=5000, theta_eq=True, verbskip=1000)
# Plot the objective gap and estimated gains for triangle scaling
fig, _ = plt.subplots(1, 2, figsize=(11, 4))

labels = [r"BPG", r"ABPG $\gamma=1.0$", r"ABPG $\gamma=1.5$", r"ABPG $\gamma=2.0$", r"ABPG $\gamma=2.2$"]
styles = ['k:', 'g-', 'b-.', 'k-', 'r--']
dashes = [[1,2], [], [4,2,1,2], [], [4,2]]

ax1 = plt.subplot(1, 2, 1)
y_vals = [F00, F10, F15, F20, F22]
accbpg.plot_comparisons(ax1, y_vals, labels, x_vals=[], plotdiff=True, yscale="log", xlim=[-10, 3000], ylim=[5e-4, 20], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc="upper right", 
                        linestyles=styles, linedash=dashes)
plt.title('housing')

ax2 = plt.subplot(1, 2, 2)
y_vals = [G10, G15, G20, G22]
accbpg.plot_comparisons(ax2, y_vals, labels[1:], x_vals=[], plotdiff=False, yscale="log", xlim=[-10, 3000], ylim=[], 
                        xlabel=r"Iteration number $k$", ylabel=r'$\hat{G}_k$', legendloc="upper right", 
                        linestyles=styles[1:], linedash=dashes[1:])
plt.title('housing')

plt.tight_layout(w_pad=4)
plt.show()
# pad = 0.05
# extent = ax1.get_tightbbox(fig.canvas.renderer).expanded(1+pad, 1+pad).transformed(fig.dpi_scale_trans.inverted())
# fig.savefig('./figures/housing_gamma.pdf', format='pdf', bbox_inches=extent)
# extent = ax2.get_tightbbox(fig.canvas.renderer).expanded(1+pad, 1+pad).transformed(fig.dpi_scale_trans.inverted())
# fig.savefig('./figures/housing_gamma_gain.pdf', format='pdf', bbox_inches=extent)<jupyter_output><empty_output><jupyter_text>Comparing BPG with line search and adaptive ABPG algorithms<jupyter_code># Solve the problem using BPG w/o line seach and adaptive ABPG with gamma=2 (TSE) 
x00, F00, G00, T00 = accbpg.BPG( f, h, L, x0, maxitrs=5000, linesearch=False, verbskip=1000)
xLS, FLS, GLS, TLS = accbpg.BPG( f, h, L, x0, maxitrs=5000, linesearch=True, ls_ratio=1.2, verbskip=1000)
x20, F20, G20, T20 = accbpg.ABPG(f, h, L, x0, gamma=2.0, maxitrs=5000, theta_eq=True, verbskip=1000)
x2e, F2e, Gamma2e, G2e, T2e = accbpg.ABPG_expo(f, h, L, x0, gamma0=3, maxitrs=5000, theta_eq=True, Gmargin=100, verbskip=1000)
x2g, F2g, G2g, Gdiv2g, Gavg2g, T2g = accbpg.ABPG_gain(f, h, L, x0, gamma=2, maxitrs=5000, G0=0.1, theta_eq=True, verbskip=1000)
# Plot the objective gap and estimated gains for triangle scaling
fig, _ = plt.subplots(1, 2, figsize=(11, 4))

labels = [r"BPG", r"BPG-LS", r"ABPG", r"ABPG-e", r"ABPG-g"]
styles = ['k:', 'g-', 'b-.', 'k-', 'r--']
dashes = [[1,2], [], [4,2,1,2], [], [4,2]]

ax1 = plt.subplot(1, 2, 1)
y_vals = [F00, FLS, F20, F2e, F2g]
accbpg.plot_comparisons(ax1, y_vals, labels, x_vals=[], plotdiff=True, yscale="log", xscale="log", xlim=[1, 3000], ylim=[5e-4, 20], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc="lower left", 
                        linestyles=styles, linedash=dashes)
plt.title('housing')

ax2 = plt.subplot(1, 2, 2)
y_vals = [GLS, G20, G2e, G2g]
accbpg.plot_comparisons(ax2, y_vals, labels[1:], x_vals=[], plotdiff=False, yscale="log", xlim=[0, 3000], ylim=[], 
                        xlabel=r"Iteration number $k$", ylabel=r'$\hat{G}_k$', legendloc="upper right", 
                        linestyles=styles[1:], linedash=dashes[1:])
plt.title('housing')

plt.tight_layout(w_pad=4)
plt.show()
# pad = 0.05
# extent = ax1.get_tightbbox(fig.canvas.renderer).expanded(1+pad, 1+pad).transformed(fig.dpi_scale_trans.inverted())
# fig.savefig('./figures/housing_adapt_loglog.pdf', format='pdf', bbox_inches=extent)
# extent = ax2.get_tightbbox(fig.canvas.renderer).expanded(1+pad, 1+pad).transformed(fig.dpi_scale_trans.inverted())
# fig.savefig('./figures/housing_adapt_gain.pdf', format='pdf', bbox_inches=extent)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18748860113076782, 'fraction_numerical': 0.060186029545869046, 'mean_word_length': 4.803174603174603, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '404363', 'license': 'MIT', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2295, 'n_words': 460, 'path': 'ipynb/ex_Dopt_LIBSVM.ipynb', 'repo_name': 'Bhaskers-Blu-Org2/accbpg', 'size': '5483'}