In [30]:
# Set up infrastructure and basic problem parameters
import multiprocessing as mp
import numpy as np
import datetime, os
from ContNoRegret.Domains import nBox, UnionOfDisjointnBoxes, DifferenceOfnBoxes, unitbox, hollowbox
from ContNoRegret.LossFunctions import random_PolynomialLosses, random_AffineLosses, random_QuadraticLosses
from ContNoRegret.NoRegretAlgos import ContNoRegretProblem
from ContNoRegret.utils import CNR_worker, plot_results, save_results, circular_tour
from ContNoRegret.animate import save_animations
from ContNoRegret.Potentials import (ExponentialPotential, IdentityPotential, pNormPotential, CompositePotential,
ExpPPotential, PExpPotential, HuberPotential, LogtasticPotential, FractionalLinearPotential)
tmpfolder = '/Volumes/tmp/'
T = 100 # Time horizon
M = 10.0 # Uniform bound on the function (in the dual norm)
L = 5.0 # Uniform bound on the Lipschitz constant
N = 2500 # Number of parallel algorithm instances
Ngrid = 250000 # Number of gridpoints for the sampling step
H = 0.1 # strict convexity parameter (lower bound on evals of Q)
inf_to_2 = {'affine':[], 'quad_cvx':[], 'quad_noncvx':[], 'polynomial':[]}
inf_to_1 = {'affine':[], 'quad_cvx':[], 'quad_noncvx':[], 'polynomial':[]}
for n in np.arange(2,5):
dom = unitbox(n)
lossfuncs = {}
# Now create some random loss functions
lossfuncs['affine'], M = random_AffineLosses(dom, L, T)
mus = dom.sample_uniform(T)
lossfuncs['quad_cvx'], M, lambdamax = random_QuadraticLosses(dom, mus, L, M, pd=True)
lossfuncs['quad_noncvx'], M, lambdamax = random_QuadraticLosses(dom, mus, L, M, pd=False)
lossfuncs['polynomial'] = random_PolynomialLosses(dom, T, M, L, 4, [0,1,2,3,4])
for key in inf_to_2.keys():
# compute bounds on the norms
normbounds = {'{}'.format(p): [lossfunc.norm(p, tmpfolder=tmpfolder) for lossfunc in lossfuncs[key]] for p in [1,2,np.Infinity]}
# compute ratios
inf_to_2[key].append(np.max(np.array(normbounds['inf'])/np.array(normbounds['2'])))
inf_to_1[key].append(np.max(np.array(normbounds['inf'])/np.array(normbounds['1'])))
In [28]:
np.min(inf_to_2), np.average(inf_to_2), np.max(inf_to_2)
Out[28]:
In [29]:
np.min(inf_to_1), np.average(inf_to_1), np.max(inf_to_1)
Out[29]:
In [31]:
inf_to_2
Out[31]:
In [32]:
inf_to_1
Out[32]:
In [33]:
import matplotlib.pyplot as plt
In [34]:
plt.plot(inf_to_2)
In [ ]: