Exemplo n.º 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(DMatrixRMaj cov, DMatrixRMaj cov_inv)
        {
            if (cov.numCols <= 4)
            {
                if (cov.numCols != cov.numRows)
                {
                    throw new ArgumentException("Must be a square matrix.");
                }

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