def infer_domain(f, gts, eqs, check_feas=True): """ Identify a subset of the constraints in ``gts`` and ``eqs`` which can be incorporated into conditional SAGE relaxations for signomials. Construct a SigDomain object from the inferred constraints. Parameters ---------- f : Signomial The objective in a desired SAGE relaxation. This parameter is only used to determine the dimension of the set defined by constraints in ``gts`` and ``eqs``. gts : list of Signomials For every ``g in gts``, there is a desired constraint that variables ``x`` satisfy ``g(x) >= 0``. eqs : list of Signomials For every ``g in eqs``, there is a desired constraint that variables ``x`` satisfy ``g(x) == 0``. check_feas : bool Indicates whether or not to verify that the returned SigDomain is nonempty. Returns ------- X : SigDomain or None """ conv_gt = con_gen.valid_posynomial_inequalities(gts) conv_eqs = con_gen.valid_monomial_equations(eqs) cl_cons = con_gen.clcons_from_standard_gprep(f.n, conv_gt, conv_eqs) if len(cl_cons) > 0: sigdom = SigDomain(f.n, coniclifts_cons=cl_cons, gts=conv_gt, eqs=conv_eqs, check_feas=check_feas) return sigdom else: return None
def test_conditional_sage_dual_1(self): n, m = 2, 6 x = Variable(shape=(n, ), name='x') cons = [1 >= vector2norm(x)] gts = [lambda z: 1 - np.linalg.norm(z, 2)] eqs = [] sigdom = SigDomain(n, coniclifts_cons=cons, gts=gts, eqs=eqs) np.random.seed(0) x0 = np.random.randn(n) x0 /= 2 * np.linalg.norm(x0) alpha = np.random.randn(m, n) c = np.array([1, 2, 3, 4, -0.5, -0.1]) v0 = np.exp(alpha @ x0) v = Variable(shape=(m, ), name='projected_v0') t = Variable(shape=(1, ), name='epigraph_var') sage_constraint = sage_cones.DualSageCone(v, alpha, name='test', X=sigdom, c=c) epi_constraint = vector2norm(v - v0) <= t constraints = [sage_constraint, epi_constraint] prob = Problem(CL_MIN, t, constraints) prob.solve(solver='ECOS') v0 = sage_constraint.violation(norm_ord=1, rough=False) assert v0 < 1e-6 v1 = sage_constraint.violation(norm_ord=np.inf, rough=True) assert v1 < 1e-6 val = prob.value assert val < 1e-7
def test_infeasible_sig_domain(self): x = cl.Variable() cons = [x <= -1, x >= 1] try: dom = SigDomain(1, coniclifts_cons=cons) assert False except RuntimeError as err: err_str = str(err) assert 'seem to be infeasible' in err_str A = np.ones(shape=(2, 2)) b = np.array([0, 1]) K = [cl.Cone('0', 2)] try: dom = SigDomain(2, AbK=(A, b, K)) assert False except RuntimeError as err: err_str = str(err) assert 'seem to be infeasible' in err_str pass