public void computeSelectionMatrix(GeometricJacobian jacobian, DenseMatrix64F selectionMatrix) { DenseMatrix64F jacobianMatrix = jacobian.getJacobianMatrix(); if (selectionMatrixSolver.modifiesA()) { throw new RuntimeException("Selection matrix solver changes A"); } if (!selectionMatrixSolver.setA(jacobianMatrix)) throw new IllegalArgumentException("Invert failed, maybe a bug?"); selectionMatrixSolver.invert(selectionMatrix); } }
private void solveSystem(int numRows, int numCols) { LinearSolver<DenseMatrix64F> qrSolver = LinearSolverFactory.qr(numRows, numCols); QRDecomposition<DenseMatrix64F> decomposition = qrSolver.getDecomposition(); qrSolver.setA(X); y.setData(response); qrSolver.solve(this.y, this.b); DenseMatrix64F R = decomposition.getR(null, true); LinearSolver<DenseMatrix64F> linearSolver = LinearSolverFactory.linear(numCols); linearSolver.setA(R); DenseMatrix64F Rinverse = new DenseMatrix64F(numCols, numCols); linearSolver.invert(Rinverse); // stores solver's solution inside of Rinverse. CommonOps.multOuter(Rinverse, this.XtXInv); }
@Override public boolean solve(DMatrixRMaj Y, DMatrixRMaj step) { solver.solve(Y,step); return true; }
@Override public boolean initializeSolver() { if( solver == null ) throw new RuntimeException("Solver not set"); if( !solver.setA(hessian) ) { return false; } return true; }
@Override public void invert(T A_inv) { alg.invert(A_inv); }
/** * Wraps a linear solver of any type with a safe solver the ensures inputs are not modified */ public static <S extends Matrix, D extends Matrix> LinearSolver<S,D> safe(LinearSolver<S,D> solver ) { if( solver.modifiesA() || solver.modifiesB() ) { if( solver instanceof LinearSolverDense ) { return new LinearSolverSafe((LinearSolverDense)solver); } else if( solver instanceof LinearSolverSparse ) { return new LinearSolverSparseSafe((LinearSolverSparse)solver); } else { throw new IllegalArgumentException("Unknown solver type"); } } else { return solver; } }
/** * Configures internal parameters. * * @param decomposition Used to solve the linear system. * @param norm2Solution If true then the optimal 2-norm solution will be computed for degenerate systems. */ protected BaseLinearSolverQrp(QRPDecomposition<DenseMatrix64F> decomposition, boolean norm2Solution) { this.decomposition = decomposition; this.norm2Solution = norm2Solution; if( internalSolver.modifiesA() ) internalSolver = new LinearSolverSafe<DenseMatrix64F>(internalSolver); }
@Override public boolean solve(DMatrixRMaj Y, DMatrixRMaj step) { solver.solve(Y,step); return true; } }
@Override public boolean initializeSolver() { if( solver == null ) throw new RuntimeException("Solver not set"); return solver.setA(hessian); }
@Override public void invert(T A_inv) { alg.invert(A_inv); }
/** * Configures internal parameters. * * @param decomposition Used to solve the linear system. * @param norm2Solution If true then the optimal 2-norm solution will be computed for degenerate systems. */ protected BaseLinearSolverQrp_D64(QRPDecomposition<DenseMatrix64F> decomposition, boolean norm2Solution) { this.decomposition = decomposition; this.norm2Solution = norm2Solution; if( internalSolver.modifiesA() ) internalSolver = new LinearSolverSafe<DenseMatrix64F>(internalSolver); }
/** * <p> * Computes the Moore-Penrose pseudo-inverse:<br> * <br> * pinv(A) = (A<sup>T</sup>A)<sup>-1</sup> A<sup>T</sup><br> * or<br> * pinv(A) = A<sup>T</sup>(AA<sup>T</sup>)<sup>-1</sup><br> * </p> * <p> * Internally it uses {@link org.ejml.alg.dense.linsol.svd.SolvePseudoInverseSvd} to compute the inverse. For performance reasons, this should only * be used when a matrix is singular or nearly singular. * </p> * @param A A m by n Matrix. Not modified. * @param invA Where the computed pseudo inverse is stored. n by m. Modified. * @return */ public static void pinv( DenseMatrix64F A , DenseMatrix64F invA ) { LinearSolver<DenseMatrix64F> solver = LinearSolverFactory.pseudoInverse(true); if( solver.modifiesA()) A = A.copy(); if( !solver.setA(A) ) throw new IllegalArgumentException("Invert failed, maybe a bug?"); solver.invert(invA); }