예제 #1
0
        /**
         * Performs a matrix inversion operations that takes advantage of the special
         * properties of a covariance matrix.
         *
         * @param cov A covariance matrix. Not modified.
         * @param cov_inv The inverse of cov.  Modified.
         * @return true if it could invert the matrix false if it could not.
         */
        public static bool invert(FMatrixRMaj cov, FMatrixRMaj cov_inv)
        {
            if (cov.numCols <= 4)
            {
                if (cov.numCols != cov.numRows)
                {
                    throw new ArgumentException("Must be a square matrix.");
                }

                if (cov.numCols >= 2)
                {
                    UnrolledInverseFromMinor_FDRM.inv(cov, cov_inv);
                }
                else
                {
                    cov_inv.data[0] = 1.0f / cov_inv.data[0];
                }
            }
            else
            {
                LinearSolverDense <FMatrixRMaj> solver = LinearSolverFactory_FDRM.symmPosDef(cov.numRows);
                // wrap it to make sure the covariance is not modified.
                solver = new LinearSolverSafe <FMatrixRMaj>(solver);
                if (!solver.setA(cov))
                {
                    return(false);
                }
                solver.invert(cov_inv);
            }
            return(true);
        }
 //@Override
 public void invert(FMatrixRMaj A_inv)
 {
     if (A.numRows == 1)
     {
         A_inv.set(0, 1.0f / A.get(0));
     }
     UnrolledInverseFromMinor_FDRM.inv(A, A_inv);
 }