Examples of SingularValueDecomposition


Examples of Jama.SingularValueDecomposition

    if ((y.length < ndata) || (x.length < ndata) || ((sd != null) && (sd.length < ndata))) {
      throw new IllegalArgumentException("data paramenters incorrect too short vector");
    }
    Matrix A = new Matrix(ndata, order + 1);
    double[] b = new double[ndata];
    SingularValueDecomposition SVD;
    double[] a = new double[order + 1];
    double xVal;
    double yVal;
    double small = 0.0000000001 * ndata;
    double[] coeff = new double[order + 1];
    double[][] U;
    double[][] V;
    double[] w;

    if (sd == null) {
      sd = new double[ndata];
      for (int i = 0; i < ndata; i++) {
        sd[i] = 1;
      }
    }

    for (int i = 0; i < ndata; i++) {
      A.set(i, 0, 1 / sd[i]);
    }
    for (int i = 0; i < ndata; i++) {
      xVal = 1;
      yVal = 1;
      for (int j = 1; j <= order; j++) {
        xVal *= x[i];
        yVal += xVal;
        A.set(i, j, xVal / sd[i]);
      }
      b[i] = yVal / sd[i];
    }
    SVD = A.svd();
    U = (SVD.getU()).getArray();
    V = (SVD.getV()).getArray();
    w = SVD.getSingularValues();

    for (int j = 0; j <= order; j++) {
      coeff[j] = 0;
      if (w[j] > small) {
        for (int i = 0; i < ndata; i++) {
View Full Code Here

Examples of Jama.SingularValueDecomposition

            try_success("QRDecomposition...", "");
        } catch (java.lang.RuntimeException e) {
            errorCount = try_failure(errorCount, "QRDecomposition...",
                    "incorrect QR decomposition calculation");
        }
        SingularValueDecomposition SVD = A.svd();

        try {
            check(A, SVD.getU().times(SVD.getS().times(SVD.getV().transpose())));
            try_success("SingularValueDecomposition...", "");
        } catch (java.lang.RuntimeException e) {
            errorCount = try_failure(errorCount, "SingularValueDecomposition...",
                    "incorrect singular value decomposition calculation");
        }
        DEF = new Matrix(rankdef);
        try {
            check(DEF.rank(),
                    Math.min(DEF.getRowDimension(), DEF.getColumnDimension())
                    - 1);
            try_success("rank()...", "");
        } catch (java.lang.RuntimeException e) {
            errorCount = try_failure(errorCount, "rank()...",
                    "incorrect rank calculation");
        }
        B = new Matrix(condmat);
        SVD = B.svd();
        double[] singularvalues = SVD.getSingularValues();

        try {
            check(B.cond(),
                    singularvalues[0]
                    / singularvalues[Math.min(B.getRowDimension(), B.getColumnDimension()) - 1]);
View Full Code Here

Examples of cern.colt.matrix.linalg.SingularValueDecomposition

*/
public class MultinormalPCAGen extends MultinormalGen {
   private double[] lambda;

   private static SingularValueDecomposition getSvd (DoubleMatrix2D sigma) {
      return (new SingularValueDecomposition (sigma));
   }
View Full Code Here

Examples of cern.colt.matrix.linalg.SingularValueDecomposition

   public static DoubleMatrix2D decompPCA (DoubleMatrix2D sigma)   {
      // L'objet SingularValueDecomposition permet de recuperer la matrice
      // des valeurs propres en ordre decroissant et celle des vecteurs propres de
      // sigma (pour une matrice symetrique et definie-positive seulement).

      SingularValueDecomposition sv = getSvd (sigma);
      // D contient les valeurs propres sur la diagonale
      DoubleMatrix2D D = sv.getS ();
      // Calculer la racine carree des valeurs propres
      for (int i = 0; i < D.rows(); ++i)
         D.setQuick (i, i, Math.sqrt (D.getQuick (i, i)));
      DoubleMatrix2D P = sv.getV();
      // Multiplier par la matrice orthogonale (ici P)
      return P.zMult (D, null);
   }
View Full Code Here

Examples of cern.colt.matrix.linalg.SingularValueDecomposition

    * Computes and returns the eigenvalues of <TT>sigma</TT> in
    *  decreasing order.
    *
    */
   public static double[] getLambda (DoubleMatrix2D sigma) {
      SingularValueDecomposition sv = getSvd (sigma);
      DoubleMatrix2D D = sv.getS ();
      double[] lambd = new double[D.rows()];
      for (int i = 0; i < D.rows(); ++i)
         lambd[i] = D.getQuick (i, i);
      return lambd;
   }
View Full Code Here

Examples of edu.ucla.sspace.matrix.factorization.SingularValueDecomposition

            Transform transform = new LogEntropyTransform();
            if (argOptions.hasOption("preprocess"))
                transform = ReflectionUtil.getObjectInstance(
                        argOptions.getStringOption("preprocess"));
            String algName = argOptions.getStringOption("svdAlgorithm", "ANY");
            SingularValueDecomposition factorization = SVD.getFactorization(
                    Algorithm.valueOf(algName.toUpperCase()));
            basis = new StringBasisMapping();

            return new LatentSemanticAnalysis(
                false, dimensions, transform, factorization, false, basis);
View Full Code Here

Examples of org.apache.commons.math.linear.SingularValueDecomposition

    public void testMoreRows() {
        final double[] singularValues = { 123.456, 2.3, 1.001, 0.999 };
        final int rows    = singularValues.length + 2;
        final int columns = singularValues.length;
        Random r = new Random(15338437322523l);
        SingularValueDecomposition svd =
            new SingularValueDecompositionImpl(createTestMatrix(r, rows, columns, singularValues));
        double[] computedSV = svd.getSingularValues();
        assertEquals(singularValues.length, computedSV.length);
        for (int i = 0; i < singularValues.length; ++i) {
            assertEquals(singularValues[i], computedSV[i], 1.0e-10);
        }
    }
View Full Code Here

Examples of org.apache.commons.math.linear.SingularValueDecomposition

    public void testMoreColumns() {
        final double[] singularValues = { 123.456, 2.3, 1.001, 0.999 };
        final int rows    = singularValues.length;
        final int columns = singularValues.length + 2;
        Random r = new Random(732763225836210l);
        SingularValueDecomposition svd =
            new SingularValueDecompositionImpl(createTestMatrix(r, rows, columns, singularValues));
        double[] computedSV = svd.getSingularValues();
        assertEquals(singularValues.length, computedSV.length);
        for (int i = 0; i < singularValues.length; ++i) {
            assertEquals(singularValues[i], computedSV[i], 1.0e-10);
        }
    }
View Full Code Here

Examples of org.apache.commons.math.linear.SingularValueDecomposition

    /** test dimensions */
    public void testDimensions() {
        RealMatrix matrix = MatrixUtils.createRealMatrix(testSquare);
        final int m = matrix.getRowDimension();
        final int n = matrix.getColumnDimension();
        SingularValueDecomposition svd = new SingularValueDecompositionImpl(matrix);
        assertEquals(m, svd.getU().getRowDimension());
        assertEquals(m, svd.getU().getColumnDimension());
        assertEquals(m, svd.getS().getColumnDimension());
        assertEquals(n, svd.getS().getColumnDimension());
        assertEquals(n, svd.getV().getRowDimension());
        assertEquals(n, svd.getV().getColumnDimension());

    }
View Full Code Here

Examples of org.apache.commons.math.linear.SingularValueDecomposition

                {15.0 / 2.05.0 / 2.09.0 / 2.03.0 / 2.0 },
                { 5.0 / 2.0, 15.0 / 2.03.0 / 2.09.0 / 2.0 },
                { 9.0 / 2.03.0 / 2.0, 15.0 / 2.05.0 / 2.0 },
                { 3.0 / 2.09.0 / 2.05.0 / 2.0, 15.0 / 2.0 }
        }, false);
        SingularValueDecomposition svd = new SingularValueDecompositionImpl(matrix);
        assertEquals(16.0, svd.getSingularValues()[0], 1.0e-14);
        assertEquals( 8.0, svd.getSingularValues()[1], 1.0e-14);
        assertEquals( 4.0, svd.getSingularValues()[2], 1.0e-14);
        assertEquals( 2.0, svd.getSingularValues()[3], 1.0e-14);

        RealMatrix fullCovariance = new Array2DRowRealMatrix(new double[][] {
                {  85.0 / 1024, -51.0 / 1024, -75.0 / 102445.0 / 1024 },
                { -51.0 / 102485.0 / 102445.0 / 1024, -75.0 / 1024 },
                { -75.0 / 102445.0 / 102485.0 / 1024, -51.0 / 1024 },
                45.0 / 1024, -75.0 / 1024, -51.0 / 102485.0 / 1024 }
        }, false);
        assertEquals(0.0,
                     fullCovariance.subtract(svd.getCovariance(0.0)).getNorm(),
                     1.0e-14);

        RealMatrix halfCovariance = new Array2DRowRealMatrix(new double[][] {
                {   5.0 / 1024,  -3.0 / 1024,   5.0 / 1024,  -3.0 / 1024 },
                -3.0 / 1024,   5.0 / 1024,  -3.0 / 1024,   5.0 / 1024 },
                {   5.0 / 1024,  -3.0 / 1024,   5.0 / 1024,  -3.0 / 1024 },
                -3.0 / 1024,   5.0 / 1024,  -3.0 / 1024,   5.0 / 1024 }
        }, false);
        assertEquals(0.0,
                     halfCovariance.subtract(svd.getCovariance(6.0)).getNorm(),
                     1.0e-14);

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.