/** * @param matrix The matrix to return as a String * @param format The format to use for each value in the matrix, eg "%f" */ public static String toString(SimpleMatrix matrix, String format) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); MatrixIO.print(new PrintStream(stream), matrix.getMatrix(), format); return stream.toString(); }
@Override public DenseMatrix64F apply(SimpleMatrix matrix) { return matrix.getMatrix(); } };
/** * If a single calibration matrix was requested then this returns it. * * @return Calibration matrix for both cameras */ public DenseMatrix64F getCalibrationMatrix() { return K.getMatrix(); }
public DenseMatrix64F getCovariance() { return P.getMatrix(); } }
public DenseMatrix64F getCovariance() { return P.getMatrix(); } }
public DenseMatrix64F getState() { return x.getMatrix(); }
/** * Checks to see if every element in A is countable. A doesn't have any element with * a value of NaN or infinite. * * @param A Matrix */ public static void assertCountable( SimpleMatrix A ) { EjmlUnitTests.assertCountable(A.getMatrix()); }
/** * @param matrix The matrix to return as a String * @param format The format to use for each value in the matrix, eg "%f" */ public static String toString(SimpleMatrix matrix, String format) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); MatrixIO.print(new PrintStream(stream), matrix.getMatrix(), format); return stream.toString(); }
private ReshapeMatrix64F createMatrix(List<double[]> rows) { SimpleMatrix matrix = new SimpleMatrix(rows.toArray(new double[][] {})); return matrix.getMatrix(); }
/** * @param matrix The matrix to return as a String * @param format The format to use for each value in the matrix, eg "%f" */ public static String toString(SimpleMatrix matrix, String format) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); MatrixIO.print(new PrintStream(stream), matrix.getMatrix(), format); return stream.toString(); }
SimpleMatrix A = new SimpleMatrix(10,5); LUDecomposition<DenseMatrix64F> lu = DecompositionFactory.lu(A.numCols()); if( !lu.decompose(A.getMatrix()) ) { throw new RuntimeException("LU Decomposition failed!"); } SimpleMatrix L = SimpleMatrix.wrap(lu.getLower(null)); SimpleMatrix U = SimpleMatrix.wrap(lu.getUpper(null));
public SimpleSVD( DenseMatrix64F mat , boolean compact ) { this.mat = mat; svd = DecompositionFactory.svd(mat.numRows,mat.numCols,true,true,compact); if( !svd.decompose(mat) ) throw new RuntimeException("Decomposition failed"); U = (T)SimpleMatrix.wrap(svd.getU(null,false)); W = (T)SimpleMatrix.wrap(svd.getW(null)); V = (T)SimpleMatrix.wrap(svd.getV(null,false)); // order singular values from largest to smallest SingularOps.descendingOrder(U.getMatrix(),false,W.getMatrix(),V.getMatrix(),false); }
public SimpleSVD( DenseMatrix64F mat , boolean compact ) { this.mat = mat; svd = DecompositionFactory.svd(mat.numRows,mat.numCols,true,true,compact); if( !svd.decompose(mat) ) throw new RuntimeException("Decomposition failed"); U = (T)SimpleMatrix.wrap(svd.getU(null,false)); W = (T)SimpleMatrix.wrap(svd.getW(null)); V = (T)SimpleMatrix.wrap(svd.getV(null,false)); // order singular values from largest to smallest SingularOps.descendingOrder(U.getMatrix(),false,W.getMatrix(),V.getMatrix(),false); }
public SimpleSVD( DenseMatrix64F mat , boolean compact ) { this.mat = mat; svd = DecompositionFactory.svd(mat.numRows,mat.numCols,true,true,compact); if( !svd.decompose(mat) ) throw new RuntimeException("Decomposition failed"); U = (T)SimpleMatrix.wrap(svd.getU(null,false)); W = (T)SimpleMatrix.wrap(svd.getW(null)); V = (T)SimpleMatrix.wrap(svd.getV(null,false)); // order singular values from largest to smallest SingularOps.descendingOrder(U.getMatrix(),false,W.getMatrix(),V.getMatrix(),false); tol = SingularOps.singularThreshold(svd); }
double[] x = { 2.5, 0.5, 2.2, 1.9, 3.1, 2.3, 2.0, 1.0, 1.5, 1.1 }; double[] y = { 2.4, 0.7, 2.9, 2.2, 3.0, 2.7, 1.6, 1.1, 1.6, 0.9 }; SimpleMatrix a = new SimpleMatrix(x.length,1,true,x); SimpleMatrix b = new SimpleMatrix(x.length,1,true,x); double meanA = a.elementSum()/x.length; double meanB = a.elementSum()/y.length; // X = X - mean(A) CommonOps.add(a.getMatrix(),-meanA); CommonOps.add(b.getMatrix(),-meanB); // compute the covariance double c11 = a.transpose().mult(a).get(0,0)/x.length; double c12 = a.transpose().mult(b).get(0,0)/x.length; double c22 = b.transpose().mult(b).get(0,0)/x.length; SimpleMatrix covariance = new SimpleMatrix(2,2,true,c11,c12,c12,c22);
private static void addTask(DenseMatrix64F taskJacobian, DenseMatrix64F taskObjective, DenseMatrix64F taskWeight, DenseMatrix64F hToModify, DenseMatrix64F fToModify) { SimpleMatrix J = new SimpleMatrix(taskJacobian); SimpleMatrix W = new SimpleMatrix(taskWeight); SimpleMatrix b = new SimpleMatrix(taskObjective); SimpleMatrix H = J.transpose().mult(W).mult(J); SimpleMatrix f = J.transpose().mult(W).mult(b); CommonOps.add(hToModify, H.getMatrix(), hToModify); CommonOps.add(fToModify, f.getMatrix(), fToModify); } }
public static double quality( DenseMatrix64F orig , DenseMatrix64F U , DenseMatrix64F W , DenseMatrix64F Vt ) { SimpleMatrix _U = SimpleMatrix.wrap(U); SimpleMatrix _W = SimpleMatrix.wrap(W); SimpleMatrix _Vt = SimpleMatrix.wrap(Vt); SimpleMatrix foundA = _U.mult(_W).mult(_Vt); return SpecializedOps.diffNormF(orig,foundA.getMatrix())/foundA.normF(); }
/** * Undoes normalization for a homography matrix. */ protected void undoNormalizationH(DenseMatrix64F M, DenseMatrix64F N1, DenseMatrix64F N2) { SimpleMatrix a = SimpleMatrix.wrap(M); SimpleMatrix b = SimpleMatrix.wrap(N1); SimpleMatrix c = SimpleMatrix.wrap(N2); SimpleMatrix result = c.invert().mult(a).mult(b); M.set(result.getMatrix()); }
public static double quality( DenseMatrix64F orig , DenseMatrix64F U , DenseMatrix64F W , DenseMatrix64F Vt ) { SimpleMatrix _U = SimpleMatrix.wrap(U); SimpleMatrix _W = SimpleMatrix.wrap(W); SimpleMatrix _Vt = SimpleMatrix.wrap(Vt); SimpleMatrix foundA = _U.mult(_W).mult(_Vt); return SpecializedOps.diffNormF(orig,foundA.getMatrix())/foundA.normF(); }