예제 #1
0
파일: conic.py 프로젝트: silky/epsilon
def transform_sigma_max(expr):
    X = only_arg(expr)
    m, n = dims(X)
    S = epi_var(expr, "sigma_max_S", size=(m+n, m+n))
    t = epi_var(expr, "sigma_max")
    t_In = expression.diag_vec(expression.multiply(expression.ones(n, 1), t))
    t_Im = expression.diag_vec(expression.multiply(expression.ones(m, 1), t))

    return t, [
        expression.eq_constraint(expression.index(S, 0, n, 0, n), t_In),
        expression.eq_constraint(expression.index(S, n, n+m, 0, n), X),
        expression.eq_constraint(expression.index(S, n, n+m, n, n+m), t_Im),
        expression.semidefinite(S)]
예제 #2
0
파일: conic.py 프로젝트: mfouda/epsilon
def transform_sigma_max(expr):
    X = only_arg(expr)
    m, n = dims(X)
    S = epi_var(expr, "sigma_max_S", size=(m + n, m + n))
    t = epi_var(expr, "sigma_max")
    t_In = expression.diag_vec(expression.multiply(expression.ones(n, 1), t))
    t_Im = expression.diag_vec(expression.multiply(expression.ones(m, 1), t))

    return t, [
        expression.eq_constraint(expression.index(S, 0, n, 0, n), t_In),
        expression.eq_constraint(expression.index(S, n, n + m, 0, n), X),
        expression.eq_constraint(expression.index(S, n, n + m, n, n + m),
                                 t_Im),
        expression.semidefinite(S)
    ]
예제 #3
0
파일: conic.py 프로젝트: silky/epsilon
def transform_norm_p(expr):
    p = expr.p
    x = only_arg(expr)
    t = epi_var(expr, "norm_p", size=(1,1))

    if p == float("inf"):
        return t, [expression.leq_constraint(x, t),
                   expression.leq_constraint(expression.negate(x), t)]

    if p == 1:
        return transform_expr(expression.sum_entries(expression.abs_val(x)))

    if p == 2:
        return t, [expression.soc_constraint(t, x)]

    r = epi_var(expr, "norm_p_r", size=dims(x))
    t1 = expression.multiply(expression.ones(*dims(x)), t)

    if p < 0:
        p, _ = power_tools.pow_neg(p)
        p = Fraction(p)
        constrs = gm_constrs(t1, [x, r], (-p/(1-p), 1/(1-p)))
    elif 0 < p < 1:
        p, _ = power_tools.pow_mid(p)
        p = Fraction(p)
        constrs = gm_constrs(r, [x, t1], (p, 1-p))
    elif p > 1:
        abs_x, constrs = transform_expr(expression.abs_val(x))
        p, _ = power_tools.pow_high(p)
        p = Fraction(p)
        constrs += gm_constrs(abs_x, [r, t1], (1/p, 1-1/p))

    constrs.append(expression.eq_constraint(expression.sum_entries(r), t))
    return t, constrs
예제 #4
0
def transform_max_entries(expr):
    x = only_arg(expr)
    m, n = dims(x)
    t = epi_var(expr, "max_entries")
    if not expr.has_axis:
        return t, [expression.leq_constraint(x, t)]
    if expr.axis == 0:
        return t, [
            expression.leq_constraint(
                x, expression.multiply(expression.ones(m, 1), t))]
    if expr.axis == 1:
        return t, [
            expression.leq_constraint(
                x, expression.multiply(t, expression.ones(1, n)))]

    raise TransformError("unknown axis attribute", expr)
예제 #5
0
파일: conic.py 프로젝트: mfouda/epsilon
def transform_max_entries(expr):
    x = only_arg(expr)
    m, n = dims(x)
    t = epi_var(expr, "max_entries")
    if not expr.has_axis:
        return t, [expression.leq_constraint(x, t)]
    if expr.axis == 0:
        return t, [
            expression.leq_constraint(
                x, expression.multiply(expression.ones(m, 1), t))
        ]
    if expr.axis == 1:
        return t, [
            expression.leq_constraint(
                x, expression.multiply(t, expression.ones(1, n)))
        ]

    raise TransformError("unknown axis attribute", expr)
예제 #6
0
파일: conic.py 프로젝트: mfouda/epsilon
def transform_norm_p(expr):
    p = expr.p
    x = only_arg(expr)
    t = epi_var(expr, "norm_p")

    if p == float("inf"):
        return t, [
            expression.leq_constraint(x, t),
            expression.leq_constraint(expression.negate(x), t)
        ]

    if p == 1:
        return transform_expr(expression.sum_entries(expression.abs_val(x)))

    if p == 2:
        if not expr.has_axis:
            return t, [
                expression.soc_constraint(t, expression.reshape(x, 1, dim(x)))
            ]
        if expr.axis == 0:
            return t, [
                expression.soc_constraint(expression.reshape(t, dim(x, 1), 1),
                                          expression.transpose(x))
            ]
        if expr.axis == 1:
            return t, [expression.soc_constraint(t, x)]

    r = epi_var(expr, "norm_p_r", size=dims(x))
    t1 = expression.multiply(expression.ones(*dims(x)), t)

    if p < 0:
        p, _ = power_tools.pow_neg(p)
        p = Fraction(p)
        constrs = gm_constrs(t1, [x, r], (-p / (1 - p), 1 / (1 - p)))
    elif 0 < p < 1:
        p, _ = power_tools.pow_mid(p)
        p = Fraction(p)
        constrs = gm_constrs(r, [x, t1], (p, 1 - p))
    elif p > 1:
        abs_x, constrs = transform_expr(expression.abs_val(x))
        p, _ = power_tools.pow_high(p)
        p = Fraction(p)
        constrs += gm_constrs(abs_x, [r, t1], (1 / p, 1 - 1 / p))

    constrs.append(expression.eq_constraint(expression.sum_entries(r), t))
    return t, constrs
예제 #7
0
파일: conic.py 프로젝트: silky/epsilon
def transform_lambda_max(expr):
    t = epi_var(expr, "lambda_max", size=(1,1))
    X = only_arg(expr)
    n = dim(X, 0)
    tI = expression.diag_vec(expression.multiply(expression.ones(n, 1), t))
    return t, [expression.psd_constraint(tI, X)]
예제 #8
0
파일: conic.py 프로젝트: mfouda/epsilon
def transform_lambda_max(expr):
    t = epi_var(expr, "lambda_max", size=(1, 1))
    X = only_arg(expr)
    n = dim(X, 0)
    tI = expression.diag_vec(expression.multiply(expression.ones(n, 1), t))
    return t, [expression.psd_constraint(tI, X)]