Beispiel #1
0
    def lsq(self, A, b, reg=0.0, radius=None, **kwargs):
        """
        Solve the linear least-squares problem in the variable x

            minimize |Ax - b| + reg * |x|

        in the Euclidian norm with LSQR. Optionally, x may be
        subject to a Euclidian-norm trust-region constraint
        |x| <= radius. This function returns (x, xNorm, status).
        """
        LSQR = LSQRFramework(A)
        LSQR.solve(b, radius=radius, damp=reg, show=False)
        return (LSQR.x, LSQR.xnorm, LSQR.status)
Beispiel #2
0
    def lsq(self, A, b, reg=0.0, radius=None, **kwargs):
        """
        Solve the linear least-squares problem in the variable x

            minimize |Ax - b| + reg * |x|

        in the Euclidian norm with LSQR. Optionally, x may be
        subject to a Euclidian-norm trust-region constraint
        |x| <= radius. This function returns (x, xNorm, status).
        """
        LSQR = LSQRFramework(A)
        LSQR.solve(b, radius=radius, damp=reg, show=False)
        return (LSQR.x, LSQR.xnorm, LSQR.status)
Beispiel #3
0
    print 'op.T(e1) = ', op.T(e1)
    print 'op.T.T is op : ', (op.T.T is op)
    print
    print 'Testing SimpleLinearOperator:'
    op = SimpleLinearOperator(J.shape[1],
                              J.shape[0],
                              lambda v: J * v,
                              matvec_transp=lambda u: u * J)
    print 'op.shape = ', op.shape
    print 'op.T.shape = ', op.T.shape
    print 'op * e2 = ', op * e2
    print 'e1.shape = ', e1.shape
    print 'op.T * e1 = ', op.T * e1
    print 'op.T.T * e2 = ', op.T.T * e2
    print 'op(e2) = ', op(e2)
    print 'op.T(e1) = ', op.T(e1)
    print 'op.T.T is op : ', (op.T.T is op)
    print
    print 'Solving a constrained least-squares problem with LSQR:'
    lsqr = LSQRFramework(op)
    lsqr.solve(np.random.random(nlp.m), show=True)
    print
    print 'Building a SquaredLinearOperator:'
    op2 = SquaredLinearOperator(J, log=True)
    print 'op2 * e2 = ', op2 * e2
    print 'op.T * (op * e2) = ', op.T * (op * e2)
    op3 = SquaredLinearOperator(J, transposed=True, log=True)
    print 'op3 * e1 = ', op3 * e1
    print 'op * (op.T * e1) = ', op * (op.T * e1)
    print 'op3 is symmetric: ', op3.check_symmetric()
Beispiel #4
0
    print 'op(e2) = ', op(e2)
    print 'op.T(e1) = ', op.T(e1)
    print 'op.T.T is op : ', (op.T.T is op)
    print
    print 'Testing SimpleLinearOperator:'
    op = SimpleLinearOperator(J.shape[1], J.shape[0],
                              lambda v: J*v,
                              matvec_transp=lambda u: u*J)
    print 'op.shape = ', op.shape
    print 'op.T.shape = ', op.T.shape
    print 'op * e2 = ', op * e2
    print 'e1.shape = ', e1.shape
    print 'op.T * e1 = ', op.T * e1
    print 'op.T.T * e2 = ', op.T.T * e2
    print 'op(e2) = ', op(e2)
    print 'op.T(e1) = ', op.T(e1)
    print 'op.T.T is op : ', (op.T.T is op)
    print
    print 'Solving a constrained least-squares problem with LSQR:'
    lsqr = LSQRFramework(op)
    lsqr.solve(np.random.random(nlp.m), show=True)
    print
    print 'Building a SquaredLinearOperator:'
    op2 = SquaredLinearOperator(J, log=True)
    print 'op2 * e2 = ', op2 * e2
    print 'op.T * (op * e2) = ', op.T * (op * e2)
    op3 = SquaredLinearOperator(J, transposed=True, log=True)
    print 'op3 * e1 = ', op3 * e1
    print 'op * (op.T * e1) = ', op * (op.T * e1)
    print 'op3 is symmetric: ', op3.check_symmetric()