Ejemplo n.º 1
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;

            float max = QrHelperFunctions_FDRM.findMax(QR.data, startQR, numRows - j);

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

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

                gamma = u_0 / tau;
                tau  *= max;

                QR.data[startQR] = -tau;
            }

            gammas[j] = gamma;
        }
        /**
         * <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)
        {
            float[] u = dataQR[j];

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

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

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

                gamma = u_0 / tau;
                tau  *= max;

                u[j] = -tau;
            }

            gammas[j] = gamma;
        }
Ejemplo n.º 3
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)
        {
            float[] u = dataQR[j];

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

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

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

                gamma = u_0 / tau;
                tau  *= max;

                u[j] = -tau;

                if (Math.Abs(tau) <= singularThreshold)
                {
                    return(false);
                }
            }

            gammas[j] = gamma;

            return(true);
        }