コード例 #1
0
m = 40
n = 2

A = np.zeros((m, n))
b = np.zeros(m)

for i in range(m):
    a = np.random.randn(n)
    a = a / np.linalg.norm(a)
    bi = 1 + np.random.rand(1)

    A[i, :] = a
    b[i] = bi

q = QCML()
q.parse('''
        dimensions m n
        variables x(n) r
        parameters A(m,n) b(m)
        maximize r
        A*x + r <= b
        ''')
q.canonicalize()
q.dims = {'m': m, 'n': n}
q.codegen("python")
socp_data = q.prob2socp(locals())

# stuffed variable size
n = socp_data['G'].shape[1]
コード例 #2
0
ファイル: cbp.py プロジェクト: voidoutpost/qcml
    parser.add_argument('-n',
                        type=int,
                        help='Number of templates in dictionary')
    parser.add_argument(
        '-c',
        '--codegen',
        help='Codegen type to use (python, matlab, or C; default python)',
        default='python')
    args = parser.parse_args()
    m, n = (args.m, args.n)

    print "Running CBP example...."

    # TODO: takeaways from this example: "diag" constructor?

    p = QCML(debug=True)
    p.parse("""
        dimensions m n
        variable c(n)
        variable u(n)
        variable v(n)
        parameter noise positive
        parameter lambda(n)
        parameter data(m)
        parameter dictc(m,n)
        parameter dictu(m,n)
        parameter dictv(m,n)
        parameter radii(n,n)    # diagonal matrix
        parameter rctheta(n,n)  # diagonal matrix
        minimize noise*norm(data - (dictc*c + dictu*u + dictv*v)) + lambda'*c
        subject to
コード例 #3
0
ファイル: tone_mapping.py プロジェクト: voidoutpost/qcml
s_right = np.sign(diff_right)
diff_right = np.abs(diff_right)
diff_right = s_right * np.log(diff_right + 1)
s_right = np.abs(diff_right)
s_right = 1.0 / (s_right + 1)

#s_down is the scaling we want to associate with each difference. Large differences
#in the original image are given small weight in the objective
s_down = np.diag(s_down)

# <codecell>

from qcml import QCML
import cvxopt

p = QCML()

rows = (m - 1) * n
cols = m * n

s = '''
    dimension cols
    dimension rows
    variable y(cols)
    parameter top(rows,cols)
    parameter bottom(rows,cols)
    parameter left(rows,cols)
    parameter right(rows,cols)

    parameter diff_down(rows)
    parameter diff_right(rows)