<jupyter_start><jupyter_text>Generate inner problem to inerface with solvers<jupyter_code>ip = TwoStage_SMPS_InnerProblem('./smpspy/benchmark_problems/2_caroe_schultz/caroe_schultz_100')<jupyter_output>Parsing nominal model information from ./smpspy/benchmark_problems/2_caroe_schultz/caroe_schultz_100.cor and .tim ...
Parsing stochastic information from ./smpspy/benchmark_problems/2_caroe_schultz/caroe_schultz_100.sto ...
Stochastic model is of type SCENARIOS DISCRETE<jupyter_text>Confirm that the det. equivalent solves with objective 62.29 (as in paper)<jupyter_code>deterministic_equivalent = ip.stoch_model.generate_deterministic_equivalent()
deterministic_equivalent.optimize()
UGM_EPS = 1.0
SGM_S_0 = 1.0

upgm = UPGM(ip.oracle, ip.projection_function, dimension=ip.dimension, epsilon=UGM_EPS, averaging=True)
udgm = UDGM(ip.oracle, ip.projection_function, dimension=ip.dimension, epsilon=UGM_EPS, averaging=True)
ufgm = UFGM(ip.oracle, ip.projection_function, dimension=ip.dimension, epsilon=UGM_EPS, averaging=True)
sgm_const = SGM(ip.oracle, ip.projection_function, dimension=ip.dimension, stepsize_0=1.0, stepsize_rule='constant') 

upgm_logger = GenericDualMethodLogger(upgm)
udgm_logger = GenericDualMethodLogger(udgm)
ufgm_logger = GenericDualMethodLogger(ufgm)
sgm_const_logger = GenericDualMethodLogger(sgm_const)
for i in range(50):
    sgm_const.dual_step()
#     upgm.dual_step()
#     udgm.dual_step()
#     ufgm.dual_step()<jupyter_output><empty_output><jupyter_text>Constants of the bound:* $p^{\mathrm{max}}_{\mathrm{UB}} = 0$* $\rho = 2.5$* $d_{\mathrm{LB}} = d(0) = -70.57851239671679$Imply that $\| \lambda^\star \|_2 \leq 28.23$. In our experiments we find that $\| \lambda_{k=\mathrm{end}} \|_2 = 0.52$, bound verified.<jupyter_code>import gurobipy as gb
import numpy as np
# find p_UB^max
deterministic_equivalent.setObjective(0, sense=gb.GRB.MINIMIZE)
deterministic_equivalent.optimize()
# find all the constants
_, d_0, _= ip.oracle(lambda_k=np.zeros(ip.dimension))
# print(d_0)
RHO = 2.5
R_D = (0-d_0)/RHO
# print(R_D)
D_X = np.linalg.norm([5,5])
analytic_bound_ugm = [UGM_EPS/2.0 + (4*(D_X*R_D)**2)/(UGM_EPS*(k+1)) for k in range(len(sgm_const_logger.d_k_iterates))]
analytic_bound_sgm_const = [(R_D+ D_X**2*(k+1)*SGM_S_0)/(2*(k+1)*SGM_S_0) for k in range(len(sgm_const_logger.d_k_iterates))]
# analytic_bound_sgm_1k = [(R_D+ D_X**2*k*SGM_S_0)/(2*k*SGM_S_0) for k in range(len(upgm_logger.d_k_iterates))]<jupyter_output><empty_output><jupyter_text>Plot it<jupyter_code>import matplotlib.pyplot as plt
%matplotlib notebook
# Compute d^best_k for subgradient
sgm_const_logger.d_k_best = [sgm_const_logger.d_k_iterates[1],]
for k, d_k in enumerate(sgm_const_logger.d_k_iterates[2:]):
    sgm_const_logger.d_k_best.append(max(sgm_const_logger.d_k_best[-1], d_k))
fig = plt.figure()
ax = fig.add_subplot(111)
# ax.plot(method_logger.d_k_iterates, marker='o', color='black', ls='')
# ax.plot([max(upgm_logger.d_k_iterates)-d_k for d_k in upgm_logger.d_k_iterates])
# ax.plot([max(udgm_logger.d_k_iterates)-d_k for d_k in udgm_logger.d_k_iterates])
# ax.plot([max(ufgm_logger.d_k_iterates)-d_k for d_k in ufgm_logger.d_k_iterates])
ax.plot([max(sgm_const_logger.d_k_iterates[1:])-d_k for d_k in sgm_const_logger.d_k_best])
ax.plot(analytic_bound_ugm, '--')
ax.plot(analytic_bound_sgm_const, '-.')

ax.set_yscale('symlog')
ax.set_yscale('symlog')
ax.set_ylabel('$d^\star - d(\lambda_k)$')
ax.set_xlabel('iteration $k$')
ax.legend(['UPGM','UDGM','UFGM','Analytic Bound'])
analytic_bound_sgm_const<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14321890827236916, 'fraction_numerical': 0.024479459763646596, 'mean_word_length': 7.5047846889952154, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '441382', 'license': 'MIT', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1476, 'n_words': 215, 'path': 'notebooks/Dual Methods Performance-3 Analytic Bounds.ipynb', 'repo_name': 'robin-vjc/smpspy', 'size': '3554'}