qtyr.src

来自「没有说明」· SRC 代码 · 共 631 行 · 第 1/2 页

SRC
631
字号
**             If N < P the factorization assumes the form:
**
**                   Q'* X[.,E] = [ R1  R2 ]                   (60a)
**
**             where R1 is a PxP upper triangular matrix and R2 is Px(N-P).
**             Thus Q is a PxP matrix and R is a PxN matrix containing R1 and
**             R2.  This type of factorization is useful for the solution of
**             underdetermined systems.  For the solution of
**
**                   X[.,E] b = Y
**
**             it can be shown that
**
**                  b = qrsol(QTY,R1) | zeros(N-P,1);
**
**  Globals:    _qrdc, _qrsl
**
**  See Also:   qqr, qre, qtyr
*/

proc (3) = qtyre(y,x);
    local flag,n,p,qraux,work,pvt,job,dum,info,r,v,q,i,k,dif,qty,ty,l,yi;

    /* check for complex input */
    if iscplx(y);
        if hasimag(y);
            errorlog "ERROR: Not implemented for complex matrices.";
            end;
        else;
            y = real(y);
        endif;
    endif;

    if iscplx(x);
        if hasimag(x);
            errorlog "ERROR: Not implemented for complex matrices.";
            end;
        else;
            x = real(x);
        endif;
    endif;

    n = rows(x);
    p = cols(x);
    l = cols(y);
    qraux = zeros(p,1);
    work = qraux;
    pvt = qraux;

    dum = 0;
    info = 0;
    job = 01000;
    x = x';

    flag = 1;

#ifDLLCALL
#else

    if rows(_qrdc) /= 647 or _qrdc[1] $== 0;
        _qrdc = zeros(647,1);
        loadexe _qrdc = qrdc.rex;
    endif;
    callexe _qrdc(x,n,n,p,qraux,pvt,work,flag);

#endif

#ifDLLCALL

    dllcall qrdc(x,n,n,p,qraux,pvt,work,flag);

#endif

    k = minc(n|p);
    dif = abs(n-p);
    qty = zeros(n,l);
    ty = zeros(n,1);

    if n > p;
        r = trimr(x',0,dif);
        v = seqa(1,1,p);    /* use to create mask */
        r = r .*( v .<= v' );       /* R */
        clear v;
    elseif p > n;
        v = seqa(1,1,p);    /* use to create mask */
        v = v .<= v';
        v = trimr(v,0,dif);
        r = x' .* v ;        /* R */
        clear v;
    else;
        v = seqa(1,1,p);    /* use to create mask */
        v = v .<= v';
        r = x' .* v ;        /* R */
        clear v;
    endif;

#ifDLLCALL
#else

    if rows(_qrsl) /= 455 or _qrsl[1] $== 0;
        _qrsl = zeros(455,1);
        loadexe _qrsl = qrsl.rex;
    endif;

#endif

    i = 1;
    do until i > l;         /* Compute the QTY */
        yi = y[.,i];

#ifDLLCALL
#else

        callexe _qrsl(x,n,n,k,qraux,yi,dum,ty,dum,dum,dum,job,info);

#endif

#ifDLLCALL

        dllcall qrsl(x,n,n,k,qraux,yi,dum,ty,dum,dum,dum,job,info);

#endif

        qty[.,i] = ty;
        i = i + 1;
    endo;
    retp(qty,r,pvt);
endp;

/*
**> qtyrep
**
**
**  Purpose:    Computes the orthogonal-triangular (QR)
**              decomposition of a matrix X using pivot vector
**              and returns Q'Y and R.
**
**  Format:     { QTY,R,E } = qtyrep(Y,X,PVT);
**
**  Input:      Y      NxL matrix.
**
**              X      NxP matrix.
**
**  Output:     QTY    KxL unitary matrix, K = min(N,P)
**
**              R      LxP upper triangular matrix, L = min(N,P)
**
**              E      Px1 permutation vector
**
**              PVT    Px1 vector, controls the selection of the pivot
**                     columns:
**
**                          if PVT[Q] gt 0 then X[Q] is an initial column
**                          if PVT[Q] eq 0 then X[Q] is a free column
**                          if PVT[Q] lt 0 then X[Q] is a final column
**
**                     The initial columns are placed at the beginning
**                     of the matrix and the final columns are placed
**                     at the end.  Only the free columns will be moved
**                     during the decomposition.
**
**  Output:     QTY    KxL unitary matrix, K = min(N,P).
**
**              R      LxP upper triangular matrix, L = min(N,P).
**
**              E      Px1 permutation vector.
**
**
**  Remarks:   Given X[.,E], where E is a permutation vector that permutes
**             the columns of X, there is an orthogonal matrix Q such that
**             Q' * X[.,E] is zero below its diagonal, i.e.,
**
**                   Q'* X[.,E] = [ R ]                         (63)
**                                [ 0 ]
**
**             where R is upper triangular.
**             If we partition
**
**                   Q = [ Q1 Q2 ]                         (64)
**
**             where Q1 has P columns then
**
**                    X[.,E] = Q1 * R                     (65)
**
**             is the QR decomposition of X[.,E].
**
**             qtyrep allows you to control the pivoting.  For example,
**             suppose that X is a data set with a column of ones in the
**             first column.  If there are linear dependencies among the
**             columns of X, the column of ones for the constant may get
**             pivoted away.  This column can be forced to be included
**             among the linearly independent columns using pvt.

**  Globals:    _qrdc, _qrsl
**
**  See Also:  qrep, qtyre
*/

proc (3) = qtyrep(y,x,pvt);
    local flag,n,p,l,qraux,work,dum,info,job,r,v,q,i,k,dif,qty,ty,yi;

    /* check for complex input */
    if iscplx(y);
        if hasimag(y);
            errorlog "ERROR: Not implemented for complex matrices.";
            end;
        else;
            y = real(y);
        endif;
    endif;

    if iscplx(x);
        if hasimag(x);
            errorlog "ERROR: Not implemented for complex matrices.";
            end;
        else;
            x = real(x);
        endif;
    endif;

    if iscplx(pvt);
        if hasimag(pvt);
            errorlog "ERROR: Not implemented for complex matrices.";
            end;
        else;
            pvt = real(pvt);
        endif;
    endif;

    n = rows(x);
    p = cols(x);
    l = cols(y);
    qraux = zeros(p,1);
    work = qraux;

    dum = 0;
    info = 0;
    job = 01000;    /* compute qty */
    x = x';

    flag = 1;

#ifDLLCALL
#else

    if rows(_qrdc) /= 647 or _qrdc[1] $== 0;
        _qrdc = zeros(647,1);
        loadexe _qrdc = qrdc.rex;
    endif;
    callexe _qrdc(x,n,n,p,qraux,pvt,work,flag);

#endif

#ifDLLCALL

    dllcall qrdc(x,n,n,p,qraux,pvt,work,flag);

#endif

    k = minc(n|p);
    dif = abs(n-p);
    qty = zeros(n,l);
    ty = zeros(n,1);

    if n > p;
        r = trimr(x',0,dif);
        v = seqa(1,1,p);    /* use to create mask */
        r = r .*( v .<= v' );       /* R */
        clear v;
    elseif p > n;
        v = seqa(1,1,p);    /* use to create mask */
        v = v .<= v';
        v = trimr(v,0,dif);
        r = x' .* v ;        /* R */
        clear v;
    else;
        v = seqa(1,1,p);    /* use to create mask */
        v = v .<= v';
        r = x' .* v ;        /* R */
        clear v;
    endif;

#ifDLLCALL
#else

    if rows(_qrsl) /= 455 or _qrsl[1] $== 0;
        _qrsl = zeros(455,1);
        loadexe _qrsl = qrsl.rex;
    endif;

#endif

    i = 1;
    do until i > l;         /* Compute Q'Y */
        yi = y[.,i];

#ifDLLCALL
#else

        callexe _qrsl(x,n,n,k,qraux,yi,dum,ty,dum,dum,dum,job,info);

#endif

#ifDLLCALL

        dllcall qrsl(x,n,n,k,qraux,yi,dum,ty,dum,dum,dum,job,info);

#endif

        qty[.,i] = ty;
        i = i + 1;
    endo;
    retp(qty,r,pvt);
endp;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?