private void runSVD() { svd = gramMatrix.svd(); rightEigenvectors = svd.getV().getArray(); } }
public PCAModel buildModel(DataInfo dinfo, GramTask tsk) { logStart(); Matrix myGram = new Matrix(tsk._gram.getXX()); // X'X/n where n = num rows SingularValueDecomposition mySVD = myGram.svd(); // Extract eigenvalues and eigenvectors // Note: Singular values ordered in weakly descending order by algorithm double[] Sval = mySVD.getSingularValues(); double[][] eigVec = mySVD.getV().getArray(); // rows = features, cols = principal components assert Sval.length == eigVec.length; // DKV.put(EigenvectorMatrix.makeKey(input("source"), destination_key), new EigenvectorMatrix(eigVec)); // Compute standard deviation double[] sdev = new double[Sval.length]; double totVar = 0; double dfcorr = dinfo._adaptedFrame.numRows()/(dinfo._adaptedFrame.numRows() - 1.0); for(int i = 0; i < Sval.length; i++) { // if(standardize) Sval[i] = dfcorr*Sval[i]; // Correct since degrees of freedom = n-1 sdev[i] = Math.sqrt(Sval[i]); totVar += Sval[i]; } double[] propVar = new double[Sval.length]; // Proportion of total variance double[] cumVar = new double[Sval.length]; // Cumulative proportion of total variance for(int i = 0; i < Sval.length; i++) { propVar[i] = Sval[i]/totVar; cumVar[i] = i == 0 ? propVar[0] : cumVar[i-1] + propVar[i]; } Key dataKey = input("source") == null ? null : Key.make(input("source")); int ncomp = Math.min(getNumPC(sdev, tolerance), max_pc); return new PCAModel(this, destination_key, dataKey, dinfo, tsk, sdev, propVar, cumVar, eigVec, mySVD.rank(), ncomp); }
SingularValueDecomposition svd = Y.svd();
SingularValueDecomposition svd = Y.svd();
SingularValueDecomposition svdJ = gramJ.svd();
private ArrayList<Vector<Double>> getSingularVectors(Matrix an, int i){ ArrayList<Vector<Double>> list = new ArrayList<Vector<Double>>(i); SingularValueDecomposition svd = an.svd(); return list; }
private void runSVD() { svd = gramMatrix.svd(); rightEigenvectors = svd.getV().getArray(); } }
/** * Resize the image using a pyramid. * * @param image * the image * @param transform * the resize transform * @return the resized image */ public static FImage pyramidResize(FImage image, Matrix transform) { // estimate the scale change final SingularValueDecomposition svd = transform.getMatrix(0, 1, 0, 1).svd(); final double sv[] = svd.getSingularValues(); final double scale = ((sv[0] + sv[1]) / 2); // calculate the pyramid level final int lev = (int) (Math.max(Math.floor(Math.log(scale) / Math.log(1.5)), 0) + 1); final double pyramidScale = Math.pow(1.5, (lev - 1)); // setup the new transformed transform matrix final Matrix scaleMatrix = TransformUtilities.scaleMatrix(1 / pyramidScale, 1 / pyramidScale); final Matrix newTransform = scaleMatrix.times(transform); transform.setMatrix(0, 2, 0, 2, newTransform); return image.process(new SimplePyramid<FImage>(1.5f, lev)); }
private Eigendecomposition(int n, double[][] matrix) { final Jama.SingularValueDecomposition svd = new Jama.Matrix(matrix, n, n).svd(); eigenvalues = svd.getSingularValues(); v = svd.getV().getArrayCopy(); }
/** * Given an approximate rotation matrix Q (that doesn't necessarily conform * properly to a rotation matrix), return the best estimate of a rotation * matrix R such that the Frobenius norm is minimised: min||r-Q||^2_F. * <p> * Fundamentally, this works by performing an SVD of the matrix, setting all * the singular values to 1 and then reconstructing the input. * * @param approx * the initial guess * @return the rotation matrix */ public static Matrix approximateRotationMatrix(Matrix approx) { final SingularValueDecomposition svd = approx.svd(); return svd.getU().times(svd.getV().transpose()); }
@Override public EVDResult run(Matrix centeredData) { int m = centeredData.getRowDimension(); int n = centeredData.getColumnDimension(); SingularValueDecomposition svd = centeredData.svd(); double[] singularValues = svd.getSingularValues(); Matrix d = Matrix.identity(n, n); for(int i = 0; i < n; i++){ /** TODO: This is true according to SVD properties in my notes*/ double val; if(i < m) val = singularValues[i]; else val = 0; d.set(i, i, 1.0/(m-1) * Math.pow(val, 2)); } Matrix v = svd.getV(); return new EVDResult(d, v); } }
final SingularValueDecomposition Svd = Cov.svd(); // Cov = USV' final Matrix S = Svd.getS(); final Matrix U = Svd.getU();
svd = matrix.svd(); u = svd.getU(); v = svd.getV();
void metricUpgrade(Matrix R) { assert ((R.getRowDimension() == 3) && (R.getColumnDimension() == 3)); SingularValueDecomposition svd = R.svd(); Matrix X = svd.getU().times(svd.getV().transpose()); Matrix W = Matrix.identity(3, 3); W.set(2, 2, X.det()); R.setMatrix(0, 3 - 1, 0, 3 - 1, svd.getU().times(W).times(svd.getV().transpose())); }
void metricUpgrade(Matrix R) { assert ((R.getRowDimension() == 3) && (R.getColumnDimension() == 3)); SingularValueDecomposition svd = R.svd(); Matrix X = svd.getU().times(svd.getV().transpose()); Matrix W = Matrix.identity(3, 3); W.set(2, 2, X.det()); R.setMatrix(0, 3 - 1, 0, 3 - 1, svd.getU().times(W).times(svd.getV().transpose())); }
SingularValueDecomposition svd = MtM.svd(); Matrix svals = svd.getS(); svals.set(0, 0, 1.0 / Math.sqrt(svals.get(0, 0)));
SingularValueDecomposition svd = MtM.svd(); Matrix svals = svd.getS(); svals.set(0, 0, 1.0 / Math.sqrt(svals.get(0, 0)));