Beispiel #1
0
        /**
         * <p>
         * Computes the householder vector "u" for the first column of submatrix j. The already computed
         * norm is used and checks to see if the matrix is singular at this point.
         * </p>
         * <p>
         * Q = I - &gamma;uu<sup>T</sup>
         * </p>
         * <p>
         * This function finds the values of 'u' and '&gamma;'.
         * </p>
         *
         * @param j Which submatrix to work off of.
         * @return false if it is degenerate
         */
        protected bool householderPivot(int j)
        {
            double[] u = dataQR[j];

            // find the largest value in this column
            // this is used to normalize the column and mitigate overflow/underflow
            double max = QrHelperFunctions_DDRM.findMax(u, j, numRows - j);

            if (max <= singularThreshold * maxValueAbs)
            {
                return(false);
            }
            else
            {
                // computes tau and normalizes u by max
                tau = QrHelperFunctions_DDRM.computeTauAndDivide(j, numRows, u, max);

                // divide u by u_0
                double u_0 = u[j] + tau;
                QrHelperFunctions_DDRM.divideElements(j + 1, numRows, u, u_0);

                gamma = u_0 / tau;
                tau  *= max;

                u[j] = -tau;
            }

            gammas[j] = gamma;

            return(true);
        }
        /**
         * <p>
         * Computes the householder vector "u" for the first column of submatrix j.  Note this is
         * a specialized householder for this problem.  There is some protection against
         * overfloaw and underflow.
         * </p>
         * <p>
         * Q = I - &gamma;uu<sup>T</sup>
         * </p>
         * <p>
         * This function finds the values of 'u' and '&gamma;'.
         * </p>
         *
         * @param j Which submatrix to work off of.
         */
        protected void householder(int j)
        {
            double[] u = dataQR[j];

            // find the largest value in this column
            // this is used to normalize the column and mitigate overflow/underflow
            double max = QrHelperFunctions_DDRM.findMax(u, j, numRows - j);

            if (max == 0.0)
            {
                gamma = 0;
                error = true;
            }
            else
            {
                // computes tau and normalizes u by max
                tau = QrHelperFunctions_DDRM.computeTauAndDivide(j, numRows, u, max);

                // divide u by u_0
                double u_0 = u[j] + tau;
                QrHelperFunctions_DDRM.divideElements(j + 1, numRows, u, u_0);

                gamma = u_0 / tau;
                tau  *= max;

                u[j] = -tau;
            }

            gammas[j] = gamma;
        }
Beispiel #3
0
        /**
         * <p>
         * Computes the householder vector "u" for the first column of submatrix j.  Note this is
         * a specialized householder for this problem.  There is some protection against
         * overflow and underflow.
         * </p>
         * <p>
         * Q = I - &gamma;uu<sup>T</sup>
         * </p>
         * <p>
         * This function finds the values of 'u' and '&gamma;'.
         * </p>
         *
         * @param j Which submatrix to work off of.
         */
        protected void householder(int j)
        {
            int startQR = j * numRows;
            int endQR   = startQR + numRows;

            startQR += j;

            double max = QrHelperFunctions_DDRM.findMax(QR.data, startQR, numRows - j);

            if (max == 0.0)
            {
                gamma = 0;
                error = true;
            }
            else
            {
                // computes tau and normalizes u by max
                tau = QrHelperFunctions_DDRM.computeTauAndDivide(startQR, endQR, QR.data, max);

                // divide u by u_0
                double u_0 = QR.data[startQR] + tau;
                QrHelperFunctions_DDRM.divideElements(startQR + 1, endQR, QR.data, u_0);

                gamma = u_0 / tau;
                tau  *= max;

                QR.data[startQR] = -tau;
            }

            gammas[j] = gamma;
        }
Beispiel #4
0
 /**
  * A = Q<sup>T</sup>*A
  *
  * @param A Matrix that is being multiplied by Q<sup>T</sup>.  Is modified.
  */
 public void applyTranQ(DMatrixRMaj A)
 {
     for (int j = 0; j < minLength; j++)
     {
         int    diagIndex = j * numRows + j;
         double before    = QR.data[diagIndex];
         QR.data[diagIndex] = 1;
         QrHelperFunctions_DDRM.rank1UpdateMultR(A, QR.data, j * numRows, gammas[j], 0, j, numRows, v);
         QR.data[diagIndex] = before;
     }
 }
Beispiel #5
0
        /**
         * A = Q*A
         *
         * @param A Matrix that is being multiplied by Q.  Is modified.
         */
        public void applyQ(DMatrixRMaj A)
        {
            if (A.numRows != numRows)
            {
                throw new ArgumentException("A must have at least " + numRows + " rows.");
            }

            for (int j = minLength - 1; j >= 0; j--)
            {
                int    diagIndex = j * numRows + j;
                double before    = QR.data[diagIndex];
                QR.data[diagIndex] = 1;
                QrHelperFunctions_DDRM.rank1UpdateMultR(A, QR.data, j * numRows, gammas[j], 0, j, numRows, v);
                QR.data[diagIndex] = before;
            }
        }
        virtual public DMatrixRMaj getQ(DMatrixRMaj Q, bool compact)
        {
            if (compact)
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, minLength);
            }
            else
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, numRows);
            }

            for (int j = minLength - 1; j >= 0; j--)
            {
                double[] u = dataQR[j];

                QrHelperFunctions_DDRM.rank1UpdateMultR_u0(Q, u, 1.0, gammas[j], j, j, numRows, v);
            }

            return(Q);
        }
Beispiel #7
0
        override public DMatrixRMaj getQ(DMatrixRMaj Q, bool compact)
        {
            if (compact)
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, minLength);
            }
            else
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, numRows);
            }

            for (int j = rank - 1; j >= 0; j--)
            {
                double[] u = dataQR[j];

                double vv = u[j];
                u[j] = 1;
                QrHelperFunctions_DDRM.rank1UpdateMultR(Q, u, gammas[j], j, j, numRows, v);
                u[j] = vv;
            }

            return(Q);
        }
Beispiel #8
0
        public DMatrixRMaj getQ(DMatrixRMaj Q, bool compact)
        {
            if (compact)
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, minLength);
            }
            else
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, numRows);
            }

            // Unlike applyQ() this takes advantage of zeros in the identity matrix
            // by not multiplying across all rows.
            for (int j = minLength - 1; j >= 0; j--)
            {
                int    diagIndex = j * numRows + j;
                double before    = QR.data[diagIndex];
                QR.data[diagIndex] = 1;
                QrHelperFunctions_DDRM.rank1UpdateMultR(Q, QR.data, j * numRows, gammas[j], j, j, numRows, v);
                QR.data[diagIndex] = before;
            }

            return(Q);
        }