<jupyter_start><jupyter_text>D-optimal experiment design: comparing ABPG and Frank-WolfeSolve 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$.Methods compared:* Original Frank-Wolfe method* Frank-Wolfe method with away steps* Bregman Proximal Gradient (BPG) method with adaptive line search* Accelerated Bregman Proximal Gradient (ABPG) method with gain adaption<jupyter_code>cd  C:\\github\accbpg
import numpy as np
import accbpg

def compare_FW_ABPG(m, n, Nmax, Nskip):

    f, h, L, x0Kh = accbpg.D_opt_design(m, n)
    x0KY = accbpg.D_opt_KYinit(f.H)
    x0Mx = (1-1e-3)*x0KY + 1e-3*x0Kh

    _, F_FWKh, _, _, T_FWKh = accbpg.D_opt_FW(f.H, x0Kh, 1e-8, maxitrs=Nmax, verbskip=Nskip)
    _, F_FWKY, _, _, T_FWKY = accbpg.D_opt_FW(f.H, x0KY, 1e-8, maxitrs=Nmax, verbskip=Nskip)
    _, F_WAKh, _, _, T_WAKh = accbpg.D_opt_FW_away(f.H, x0Kh, 1e-8, maxitrs=Nmax, verbskip=Nskip)
    _, F_WAKY, _, _, T_WAKY = accbpg.D_opt_FW_away(f.H, x0KY, 1e-8, maxitrs=Nmax, verbskip=Nskip)
    _, F_LSKh, _, T_LSKh = accbpg.BPG(f, h, L, x0Kh, maxitrs=Nmax, linesearch=True, ls_ratio=1.5, verbskip=Nskip)
    _, F_LSKY, _, T_LSKY = accbpg.BPG(f, h, L, x0Mx, maxitrs=Nmax, linesearch=True, ls_ratio=1.5, verbskip=Nskip)
    _, F_ABKh, _, _, _, T_ABKh = accbpg.ABPG_gain(f, h, L, x0Kh, gamma=2, maxitrs=Nmax, ls_inc=1.5, ls_dec=1.5, restart=True, verbskip=Nskip)
    _, F_ABKY, _, _, _, T_ABKY = accbpg.ABPG_gain(f, h, L, x0Mx, gamma=2, maxitrs=Nmax, ls_inc=1.5, ls_dec=1.5, restart=True, verbskip=Nskip)
    
    f_vals = [F_FWKh, F_FWKY, F_WAKh, F_WAKY, F_LSKh, F_LSKY, F_ABKh, F_ABKY]
    t_vals = [T_FWKh, T_FWKY, T_WAKh, T_WAKY, T_LSKh, T_LSKY, T_ABKh, T_ABKY]
    
    return f_vals, t_vals
import matplotlib
import matplotlib.pyplot as plt

# Plot required number of iterations and time
matplotlib.rcParams.update({'font.size': 14, 'font.family': 'serif'})
matplotlib.rcParams.update({'text.usetex': True})

labels = [r"FW", r"FW KY", r"FW-away", r"FW-away KY", r"BPG-LS", r"BPG-LS KY", r"ABPG-g", r"ABPG-g KY"]
linestyles=['g-', 'g--', 'k-', 'k--', 'b-.', 'b:', 'r-', 'r--']
F1, T1 = compare_FW_ABPG(100, 10000, 100000, 10000)
plt.subplots(1, 2, figsize=(10, 4))
ax1 = plt.subplot(1, 2, 1)
accbpg.plot_comparisons(ax1, F1, labels, x_vals=[], plotdiff=True, yscale="log", xscale="linear", xlim=[-2000, 100000], ylim=[1e-6, 100], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc="no", linestyles=linestyles)
ax2 = plt.subplot(1, 2, 2)
T1 = [ts - ts.min() + 1e-3 for ts in T1]
accbpg.plot_comparisons(ax2, F1, labels, x_vals=T1, plotdiff=True, yscale="log", xscale="linear", xlim=[-1, 60], ylim=[1e-6, 100], 
                        xlabel=r"Time (sec)", ylabel=r"$F(x_k)-F_\star$", legendloc=0, linestyles=linestyles)    
plt.tight_layout(h_pad=0.5, w_pad=2)
#plt.savefig("C:\github\\accbpg\\figures\\Dopt_compareFW_m100n10000.pdf", bbox_inches="tight")
F2, T2 = compare_FW_ABPG(100, 1000, 100000, 10000)
plt.subplots(1, 2, figsize=(10, 4))
ax1 = plt.subplot(1, 2, 1)
accbpg.plot_comparisons(ax1, F2, labels, x_vals=[], plotdiff=True, yscale="log", xscale="linear", xlim=[-400, 40000], ylim=[1e-6, 100], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc="no", linestyles=linestyles)
ax2 = plt.subplot(1, 2, 2)
accbpg.plot_comparisons(ax2, F2, labels, x_vals=T2, plotdiff=True, yscale="log", xscale="linear", xlim=[-1, 30], ylim=[1e-6, 100], 
                        xlabel=r"Time (sec)", ylabel=r"$F(x_k)-F_\star$", legendloc="lower right", linestyles=linestyles)    
plt.tight_layout(h_pad=0.5, w_pad=2)
#plt.savefig("C:\github\\accbpg\\figures\\Dopt_compareFW_m100n1000.pdf", bbox_inches="tight")
F3, T3 = compare_FW_ABPG(300, 1000, 100000, 10000)
plt.subplots(1, 2, figsize=(10, 4))
ax1 = plt.subplot(1, 2, 1)
accbpg.plot_comparisons(ax1, F3, labels, x_vals=[], plotdiff=True, yscale="log", xscale="linear", xlim=[-100, 5000], ylim=[1e-8,100], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc=0, linestyles=linestyles)
ax2 = plt.subplot(1, 2, 2)
accbpg.plot_comparisons(ax2, F3, labels, x_vals=T3, plotdiff=True, yscale="log", xscale="linear", xlim=[-0.2, 60], ylim=[1e-8, 100], 
                        xlabel=r"Time (sec)", ylabel=r"$F(x_k)-F_\star$", legendloc=0, linestyles=linestyles)    
plt.tight_layout(h_pad=0.5, w_pad=2)
#plt.savefig("C:\github\\accbpg\\figures\\Dopt_compareFW_m300n1000.pdf", bbox_inches="tight")
#F4, T4 = compare_FW_ABPG(800, 2500, 100000, 10000)
F4, T4 = compare_FW_ABPG(400, 1000, 100000, 10000)
plt.subplots(1, 2, figsize=(10, 4))
ax1 = plt.subplot(1, 2, 1)
accbpg.plot_comparisons(ax1, F4, labels, x_vals=[], plotdiff=True, yscale="log", xscale="linear", xlim=[-50, 2000], ylim=[1e-6, 100], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc="no", linestyles=linestyles)
ax2 = plt.subplot(1, 2, 2)
accbpg.plot_comparisons(ax2, F4, labels, x_vals=T4, plotdiff=True, yscale="log", xscale="linear", xlim=[-1, 60], ylim=[1e-6, 100], 
                        xlabel=r"Time (sec)", ylabel=r"$F(x_k)-F_\star$", legendloc="lower right", linestyles=linestyles)    
plt.tight_layout(h_pad=0.5, w_pad=2)
#plt.savefig("C:\github\\accbpg\\figures\\Dopt_compareFW_m400n1000.pdf", bbox_inches="tight")
F5, T5 = compare_FW_ABPG(500, 1000, 100000, 10000)
plt.subplots(1, 2, figsize=(10, 4))
ax1 = plt.subplot(1, 2, 1)
accbpg.plot_comparisons(ax1, F5, labels, x_vals=[], plotdiff=True, yscale="log", xscale="linear", xlim=[-100, 1500], ylim=[1e-6, 2], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc="no", linestyles=linestyles)
ax2 = plt.subplot(1, 2, 2)
accbpg.plot_comparisons(ax2, F5, labels, x_vals=T5, plotdiff=True, yscale="log", xscale="linear", xlim=[-1, 12], ylim=[1e-6, 2], 
                        xlabel=r"Time (sec)", ylabel=r"$F(x_k)-F_\star$", legendloc="lower center", linestyles=linestyles)    
plt.tight_layout(h_pad=0.5, w_pad=2)
#plt.savefig("C:\github\\accbpg\\figures\\Dopt_compareFW_m500n1000.pdf", bbox_inches="tight")
F6, T6 = compare_FW_ABPG(350, 1000, 100000, 10000)
plt.subplots(1, 2, figsize=(10, 4))
ax1 = plt.subplot(1, 2, 1)
accbpg.plot_comparisons(ax1, F6, labels, x_vals=[], plotdiff=True, yscale="log", xscale="linear", xlim=[-50, 2500], ylim=[1e-6, 100], 
                        xlabel=r"Iteration number $k$", ylabel=r"$F(x_k)-F_\star$", legendloc="no", linestyles=linestyles)
ax2 = plt.subplot(1, 2, 2)
accbpg.plot_comparisons(ax2, F6, labels, x_vals=T6, plotdiff=True, yscale="log", xscale="linear", xlim=[-0.1, 10], ylim=[1e-6, 100], 
                        xlabel=r"Time (sec)", ylabel=r"$F(x_k)-F_\star$", legendloc="lower right", linestyles=linestyles)    
plt.tight_layout(h_pad=0.5, w_pad=2)
#plt.savefig("C:\github\\accbpg\\figures\\Dopt_compareFW_m350n1000.pdf", bbox_inches="tight")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19054280917739227, 'fraction_numerical': 0.06785114717403469, 'mean_word_length': 4.602664576802508, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '30399', 'license': 'MIT', 'n_tokens_mistral': 3527, 'n_tokens_neox': 3141, 'n_words': 559, 'path': 'ipynb/ABPGvsFW/ex_Dopt_FW_KYvsKha.ipynb', 'repo_name': 'Bhaskers-Blu-Org2/accbpg', 'size': '7148'}