def test_profit_q(): E = ell(r, np.array([0., 0.])) P = profit_q_oracle(params, a, v) _, _, ell_info = cutting_plane_q(P, E, 0.) assert ell_info.feasible assert ell_info.num_iters == 28 return ell_info.num_iters
def run_firfilter(no_trick, duration=0.000001): """[summary] Arguments: no_trick ([type]): [description] Keyword Arguments: duration (float): [description] (default: {0.000001}) Raises: Exception: [description] """ h0 = np.zeros(n) # initial x0 E = ell(10., h0) E.no_defer_trick = no_trick P = my_oracle() prob1 = Problem(E, P) prob1.solve(100.) time.sleep(duration) print('Problem status:', prob1.status) if prob1.status != 'optimal': raise Exception('ELL Error') print("optimal value", prob1.optim_value) assert prob1.status == 'optimal' return prob1._solver_stats.num_iters
def test_case_infeasible2(): """[summary] """ x0 = np.array([1., 1.]) # initial x0 E = ell(10., x0) P = my_quasicvx_oracle _, _, ell_info = cutting_plane_dc(P, E, -100) # wrong initial best-so-far assert not ell_info.feasible
def test_case_feasible(): """[summary] """ x0 = np.array([0., 0.]) # initial x0 E = ell(10., x0) P = my_oracle _, _, ell_info = cutting_plane_dc(P, E, float('-inf')) assert ell_info.feasible
def lsq_corr_core(Y, n, Q): x = np.zeros(n) # cannot all zeros x[0] = 1. E = ell(256., x) P = bsearch_adaptor(Q, E) normY = np.linalg.norm(Y, 'fro') _, bs_info = bsearch(P, [0., normY * normY]) return P.x_best, bs_info.num_iters, bs_info.feasible
def test_profit_rb(): e1 = 0.003 e2 = 0.007 e3 = e4 = e5 = 1. E = ell(r, np.array([0., 0.])) P = profit_rb_oracle(params, a, v, (e1, e2, e3, e4, e5)) _, _, ell_info = cutting_plane_dc(P, E, 0.) assert ell_info.feasible assert ell_info.num_iters == 42
def test_case_infeasible1(): """[summary] """ x0 = np.array([100., 100.]) # wrong initial guess, E = ell(10., x0) # or ellipsoid is too small P = my_quasicvx_oracle _, _, ell_info = cutting_plane_dc(P, E, 0.) assert not ell_info.feasible assert ell_info.status == CUTStatus.nosoln # no sol'n
def test_case_infeasible(): """[summary] """ x0 = np.array([100., 100.]) # wrong initial guess E = ell(10., x0) P = my_oracle2 ell_info = cutting_plane_feas(P, E) assert ell_info.status == CUTStatus.nosoln # no sol'n assert ell_info.num_iters == 1 # small assert not ell_info.feasible
def test_case_feasible(): """[summary] """ x0 = np.array([0., 0.]) # initial guess E = ell(10., x0) P = my_oracle2 ell_info = cutting_plane_feas(P, E) assert ell_info.feasible assert ell_info.status == CUTStatus.success print(ell_info.num_iters, ell_info.status)
def test_case_feasible(): """[summary] """ x0 = np.array([1., 1.]) # initial x0 E = ell(10., x0) P = my_quasicvx_oracle xb, fb, ell_info = cutting_plane_dc(P, E, 0.) assert ell_info.feasible assert fb == approx(-0.4288673396685956) assert xb[0] == approx(0.501315956) assert xb[1] == approx(1.650886769)
def test_optscaling(): """[summary] Keyword Arguments: duration (float): [description] (default: {0.000001}) Returns: [type]: [description] """ x0 = np.array([cmax, cmin]) t = cmax - cmin E = ell(1.5 * t, x0) dist = list(0 for _ in G) P = optscaling_oracle(G, dist, get_cost) _, _, ell_info = cutting_plane_dc(P, E, float('inf')) # fmt = '{:f} {} {} {}' # print(np.exp(xb)) # print(fmt.format(np.exp(fb), niter, feasible, status)) assert ell_info.feasible
def mle_corr_core(Y: Arr, n: int, P: Callable): """[summary] Arguments: Y (Arr): [description] n (int): [description] P (Callable): [description] Returns: [type]: [description] """ x = np.zeros(n) x[0] = 1. E = ell(50., x) # E.use_parallel_cut = False # options = Options() # options.max_it = 2000 # options.tol = 1e-8 xb, _, ell_info = cutting_plane_dc(P, E, float('inf')) # print(num_iters, feasible, status) return xb, ell_info.num_iters, ell_info.feasible
def lsq_corr_core2(Y: Arr, n: int, P: Callable): """[summary] Arguments: Y (Arr): [description] n (int): [description] P (Callable): [description] Returns: [type]: [description] """ normY = np.linalg.norm(Y, 'fro') normY2 = 32 * normY * normY val = 256 * np.ones(n + 1) val[-1] = normY2 * normY2 x = np.zeros(n + 1) # cannot all zeros x[0] = 1. x[-1] = normY2 / 2 E = ell(val, x) xb, _, ell_info = cutting_plane_dc(P, E, float('inf')) return xb[:-1], ell_info.num_iters, ell_info.feasible
def run_lmi(oracle, duration=0.000001): """[summary] Arguments: oracle ([type]): [description] Keyword Arguments: duration (float): [description] (default: {0.000001}) Returns: [type]: [description] """ x0 = np.array([0., 0., 0.]) # initial x0 E = ell(10., x0) P = my_oracle(oracle) _, _, ell_info = cutting_plane_dc(P, E, float('inf')) time.sleep(duration) # fmt = '{:f} {} {} {}' # print(fmt.format(fb, niter, feasible, status)) # print(xb) assert ell_info.feasible return ell_info.num_iters