/** * 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); }
/** * 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); }
/** * 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); }
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); } }
/** * 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; } }
/** * <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); }
/** * <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); }
/** * <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); }
@Override public boolean setA(T A) { if( alg.modifiesA() ) { if( this.A == null ) { this.A = (T)A.copy(); } else { if( this.A.numRows != A.numRows || this.A.numCols != A.numCols ) { this.A.reshape(A.numRows,A.numCols,false); } this.A.set(A); } return alg.setA(this.A); } return alg.setA(A); }
@Override public boolean setA(T A) { if( alg.modifiesA() ) { if( this.A == null ) { this.A = (T)A.copy(); } else { if( this.A.numRows != A.numRows || this.A.numCols != A.numCols ) { this.A.reshape(A.numRows,A.numCols,false); } this.A.set(A); } return alg.setA(this.A); } return alg.setA(A); }
if( solver.modifiesA() ) input = input.copy();