/** * Computes the decomposition from an essential matrix. * * @param E essential matrix */ public void decompose( DenseMatrix64F E ) { if( svd.inputModified() ) { E_copy.set(E); E = E_copy; } if( !svd.decompose(E)) throw new RuntimeException("Svd some how failed"); U = svd.getU(U,false); V = svd.getV(V,false); S = svd.getW(S); SingularOps.descendingOrder(U,false,S,V,false); decompose(U, S, V); }
DenseMatrix64F V = svd.getV(null,false); SingularOps.descendingOrder(null,false,singularValues,3,V,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); }
SingularOps.descendingOrder(null, false, W, V_t, true);
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); }
SingularOps.descendingOrder(null,false,W,V_t,true);
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); }
/** * Projects the found estimate of F onto Fundamental space. * * @return true if svd returned true. */ protected boolean projectOntoFundamentalSpace( DenseMatrix64F F ) { if( !svdConstraints.decompose(F) ) { return false; } svdV = svdConstraints.getV(svdV,false); svdU = svdConstraints.getU(svdU,false); svdS = svdConstraints.getW(svdS); SingularOps.descendingOrder(svdU, false, svdS, svdV, false); // the smallest singular value needs to be set to zero, unlike svdS.set(2, 2, 0); // recompute F CommonOps.mult(svdU, svdS, temp0); CommonOps.multTransB(temp0,svdV, F); return true; }
DenseMatrix64F S = svd.getW(null); SingularOps.descendingOrder(null,false,S, V,false);
SingularOps.descendingOrder(null, false, W, V_t, true);
DenseMatrix64F V = svd.getV(null,false); SingularOps.descendingOrder(null,false,singularValues,3,V,false);
/** * Projects the found estimate of E onto essential space. * * @return true if svd returned true. */ protected boolean projectOntoEssential( DenseMatrix64F E ) { if( !svdConstraints.decompose(E) ) { return false; } svdV = svdConstraints.getV(svdV,false); svdU = svdConstraints.getU(svdU,false); svdS = svdConstraints.getW(svdS); SingularOps.descendingOrder(svdU, false, svdS, svdV, false); // project it into essential space // the scale factor is arbitrary, but the first two singular values need // to be the same. so just set them to one svdS.unsafe_set(0, 0, 1); svdS.unsafe_set(1, 1, 1); svdS.unsafe_set(2, 2, 0); // recompute F CommonOps.mult(svdU, svdS, temp0); CommonOps.multTransB(temp0,svdV, E); return true; }
private ImmutablePair<DenseMatrix64F[], double[]> computeSVD(DenseMatrix64F matrix) { SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd(matrix.getNumRows(), matrix.getNumCols(), true, true, false); svd.decompose(matrix); DenseMatrix64F matrixU = new DenseMatrix64F(matrix.getNumRows(), matrix.getNumRows()); DenseMatrix64F matrixW = new DenseMatrix64F(matrix.getNumRows(), matrix.getNumCols()); DenseMatrix64F matrixVTranspose = new DenseMatrix64F(matrix.getNumCols(), matrix.getNumCols()); svd.getU(matrixU, false); svd.getW(matrixW); svd.getV(matrixVTranspose, true); double[] singularValues = svd.getSingularValues(); SingularOps.descendingOrder(matrixU, false, matrixW, matrixVTranspose, true); return new ImmutablePair<DenseMatrix64F[], double[]>(new DenseMatrix64F[] {matrixU, matrixW, matrixVTranspose}, singularValues); } }
private void computeNullspace(DenseMatrix64F nullspace, DenseMatrix64F A, int nullity) { nullspace.reshape(nullspace.getNumRows(), nullity); svd.decompose(A); sigma.reshape(A.getNumCols(), A.getNumRows()); svd.getW(sigma); v.reshape(A.getNumRows(), A.getNumRows()); boolean transposed = false; svd.getV(v, transposed); SingularOps.descendingOrder(null, false, sigma, v, transposed); CommonOps.extract(v, 0, v.getNumRows(), v.getNumCols() - nullity, v.getNumCols(), nullspace, 0, 0); if (makeLargestComponentPositive) { makeLargestComponentInEachRowPositive(nullspace); } }
SingularOps.descendingOrder(U,false,svdU.getSingularValues(),svdU.numberOfSingularValues(),null,false); int rank = SingularOps.rank(svdU, 1e-13); Up.reshape(U.numRows,rank);
private static Vector3D refineNormalWithLeastSquares(Point3DReadOnly pointOnPlane, Vector3DReadOnly ransacNormal, double maxDistanceFromPlane, List<NormalOcTreeNode> neighbors) { IncrementalCovariance3D covarianceCalulator = new IncrementalCovariance3D(); Vector3D toNeighborHitLocation = new Vector3D(); for (NormalOcTreeNode neighbor : neighbors) { toNeighborHitLocation.set(neighbor.getHitLocationX(), neighbor.getHitLocationY(), neighbor.getHitLocationZ()); toNeighborHitLocation.sub(pointOnPlane); double distanceFromPlane = Math.abs(ransacNormal.dot(toNeighborHitLocation)); if (distanceFromPlane <= maxDistanceFromPlane) covarianceCalulator.addDataPoint(neighbor.getHitLocationX(), neighbor.getHitLocationY(), neighbor.getHitLocationZ()); } if (covarianceCalulator.getSampleSize() <= 2) return null; SingularValueDecomposition<DenseMatrix64F> svd = new SvdImplicitQrDecompose_D64(true, false, true, false); svd.decompose(covarianceCalulator.getCovariance()); DenseMatrix64F v = svd.getV(null, false); if (MatrixFeatures.hasNaN(v)) return null; SingularOps.descendingOrder(null, false, svd.getW(null), v, false); Vector3D refinedNormal = new Vector3D(v.get(0, 2), v.get(1, 2), v.get(2, 2)); refinedNormal.normalize(); return refinedNormal; }
/** * Performs the singular value decomposition to get the principal axes and the variance of the given dataset. * The point cloud needs to be provided before being able to call {@link #compute()}. */ public void compute() { if (covarianceCalculator.getSampleSize() < 3) { principalAxis.set(Double.NaN, Double.NaN, Double.NaN); secondaryAxis.set(Double.NaN, Double.NaN, Double.NaN); thirdAxis.set(Double.NaN, Double.NaN, Double.NaN); variance.set(0.0, 0.0, 0.0); return; } covarianceCalculator.getCovariance(covariance); svd.decompose(covariance); svd.getW(W); svd.getV(V, false); SingularOps.descendingOrder(null, false, W, V, false); if (DEBUG) System.out.println("V: \n" + V); principalAxis.set(V.get(0, 0), V.get(1, 0), V.get(2, 0)); secondaryAxis.set(V.get(0, 1), V.get(1, 1), V.get(2, 1)); thirdAxis.cross(principalAxis, secondaryAxis); if (DEBUG) System.out.println("W: \n" + W); variance.setX(W.get(0, 0)); variance.setY(W.get(1, 1)); variance.setZ(W.get(2, 2)); }
SingularOps.descendingOrder(null, false, W, V, false);