コード例 #1
0
        /**
         * <p>
         * x<sup>T</sup>A<sup>T</sup>y
         * </p>
         *
         * @param x  A vector with n elements. Not modified.
         * @param A  A matrix with n by n elements.  Not modified.
         * @param y  A vector with n elements. Not modified.
         * @return  The results.
         */
        // TODO better name for this
        public static float innerProdTranA(FMatrixD1 x, FMatrixD1 A, FMatrixD1 y)
        {
            int n = A.numRows;

            if (n != A.numCols)
            {
                throw new ArgumentException("A must be square");
            }

            if (x.getNumElements() != n)
            {
                throw new ArgumentException("Unexpected number of elements in x");
            }
            if (y.getNumElements() != n)
            {
                throw new ArgumentException("Unexpected number of elements in y");
            }

            float result = 0;

            for (int i = 0; i < n; i++)
            {
                float total = 0;

                for (int j = 0; j < n; j++)
                {
                    total += x.get(j) * A.unsafe_get(i, j);
                }

                result += total * y.get(i);
            }

            return(result);
        }
コード例 #2
0
        /**
         * Computes the quality of a triangular matrix, where the quality of a matrix
         * is defined in {@link LinearSolverDense#quality()}.  In
         * this situation the quality os the absolute value of the product of
         * each diagonal element divided by the magnitude of the largest diagonal element.
         * If all diagonal elements are zero then zero is returned.
         *
         * @param T A matrix.
         * @return the quality of the system.
         */
        public static float qualityTriangular(FMatrixD1 T)
        {
            int N = Math.Min(T.numRows, T.numCols);

            // TODO make faster by just checking the upper triangular portion
            float max = elementDiagonalMaxAbs(T);

            if (max == 0.0f)
            {
                return(0.0f);
            }

            float quality = 1.0f;

            for (int i = 0; i < N; i++)
            {
                quality *= T.unsafe_get(i, i) / max;
            }

            return(Math.Abs(quality));
        }