Package org.apache.mahout.math

Examples of org.apache.mahout.math.DenseMatrix


    int sampleDimension = sampleData.get(0).get().size();
    solver.run(testData, output, tmp, sampleData.size(), sampleDimension, false, desiredRank, 0.5, 0.0, true);
    Path cleanEigenvectors = new Path(output, EigenVerificationJob.CLEAN_EIGENVECTORS);

    // build in-memory data matrix A
    Matrix a = new DenseMatrix(sampleData.size(), sampleDimension);
    int i = 0;
    for (VectorWritable vw : sampleData) {
      a.assignRow(i++, vw.get());
    }
    // extract the eigenvectors into P
    Matrix p = new DenseMatrix(39, desiredRank - 1);
    FileSystem fs = FileSystem.get(cleanEigenvectors.toUri(), conf);
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, cleanEigenvectors, conf);
    try {
      Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
      Writable value = reader.getValueClass().asSubclass(Writable.class).newInstance();
      i = 0;
      while (reader.next(key, value)) {
        Vector v = ((VectorWritable) value).get();
        p.assignColumn(i, v);
        System.out.println("k=" + key.toString() + " V=" + AbstractCluster.formatVector(v, termDictionary));
        value = reader.getValueClass().asSubclass(Writable.class).newInstance();
        i++;
      }
    } finally {
View Full Code Here


    this.corpus = corpus;
    this.desiredRank = desiredRank;
    intitializeBasisAndSingularVectors();
    setBasisVector(0, initialVector);
    scaleFactor = 0;
    diagonalMatrix = new DenseMatrix(desiredRank, desiredRank);
    singularValues = Maps.newHashMap();
    iterationNumber = 1;
  }
View Full Code Here

    return digammaGamma;
  }
 
  private void createPhiMatrix(int docLength) {
    if (phi == null || phi.rowSize() != docLength) {
      phi = new DenseMatrix(state.getNumTopics(), docLength);
    } else {
      phi.assign(0);
    }
  }
View Full Code Here

    }

  }

  static Matrix generateDenseOrthonormalRandom(int m, int n, Random rnd) {
    Matrix result = new DenseMatrix(m, n);
    for (int j = 0; j < n; j++) {
      for (int i = 0; i < m; i++) {
        result.setQuick(i, j, rnd.nextDouble() - 0.5);
      }
    }
    GramSchmidt.orthonormalizeColumns(result);
    SSVDPrototypeTest.assertOrthonormality(result, false, 1.0e-10);
    return result;
View Full Code Here

    double[][] a = SSVDSolver.loadDistributedRowMatrix(fs, aPath, conf);

    // SingularValueDecompositionImpl svd=new SingularValueDecompositionImpl(new
    // Array2DRowRealMatrix(a));
    SingularValueDecomposition svd2 =
      new SingularValueDecomposition(new DenseMatrix(a));

    double[] svalues2 = svd2.getSingularValues();
    dumpSv(svalues2);

    for (int i = 0; i < k + p; i++) {
      assertTrue(Math.abs(svalues2[i] - stochasticSValues[i]) <= s_epsilon);
    }

    double[][] mQ =
      SSVDSolver.loadDistributedRowMatrix(fs, new Path(svdOutPath, "Bt-job/"
          + BtJob.OUTPUT_Q + "-*"), conf);

    SSVDPrototypeTest
      .assertOrthonormality(new DenseMatrix(mQ), false, s_epsilon);

    /*
     * removing tests on U and V to keep this test leaner. I will keep U,V
     * computation and assertions in the dense tests though.
     */
 
View Full Code Here

        "56,34",
        "56,56",
        "56,78",
        "78,34");

    Matrix expectedAdjacencyMatrix = new DenseMatrix(new double[][] {
        { 0, 1, 1, 0 },
        { 0, 1, 0, 1 },
        { 1, 1, 1, 1 },
        { 0, 1, 0, 0 } });
View Full Code Here

        "34,78",
        "56,34",
        "56,56",
        "56,78");

    Matrix expectedAdjacencyMatrix = new DenseMatrix(new double[][] {
        { 0, 1, 1, 0 },
        { 1, 1, 1, 1 },
        { 1, 1, 1, 1 },
        { 0, 1, 1, 0 } });
View Full Code Here

    randomWalkWithRestart.run(new String[]{"--vertices", verticesFile.getAbsolutePath(),
        "--edges", edgesFile.getAbsolutePath(), "--sourceVertexIndex", String.valueOf(2),
        "--output", outputDir.getAbsolutePath(), "--numIterations", String.valueOf(2),
        "--stayingProbability", String.valueOf(0.75), "--tempDir", tempDir.getAbsolutePath()});

    Matrix expectedAdjacencyMatrix = new DenseMatrix(new double[][] {
        { 0, 1, 1, 0 },
        { 0, 1, 0, 1 },
        { 1, 1, 1, 1 },
        { 0, 1, 0, 0 } });

    int numVertices = HadoopUtil.readInt(new Path(tempDir.getAbsolutePath(), AdjacencyMatrixJob.NUM_VERTICES), conf);
    assertEquals(4, numVertices);
    Matrix actualAdjacencyMatrix = MathHelper.readMatrix(conf, new Path(tempDir.getAbsolutePath(),
        AdjacencyMatrixJob.ADJACENCY_MATRIX + "/part-r-00000"), numVertices, numVertices);

    StringBuilder info = new StringBuilder();
    info.append("\nexpected adjacency matrix\n\n");
    info.append(MathHelper.nice(expectedAdjacencyMatrix));
    info.append("\nactual adjacency matrix \n\n");
    info.append(MathHelper.nice(actualAdjacencyMatrix));
    info.append('\n');
    log.info(info.toString());

    Matrix expectedTransitionMatrix = new DenseMatrix(new double[][] {
        { 0,     0,     0.1875, 0    },
        { 0.375, 0.375, 0.1875, 0.75 },
        { 0.375, 0,     0.1875, 0    },
        { 0,     0.375, 0.1875, 0    } });
View Full Code Here

      FileSystem fs = FileSystem.get(context.getConfiguration());
      Path uHatPath = new Path(context.getConfiguration().get(PROP_UHAT_PATH));

      Path sigmaPath = new Path(context.getConfiguration().get(PROP_SIGMA_PATH));

      uHat = new DenseMatrix(SSVDSolver.loadDistributedRowMatrix(fs,
          uHatPath, context.getConfiguration()));
      // since uHat is (k+p) x (k+p)
      kp = uHat.columnSize();
      k = context.getConfiguration().getInt(PROP_K, kp);
      vRow = new DenseVector(k);
View Full Code Here

    double[][] mQ =
      SSVDSolver.loadDistributedRowMatrix(fs, new Path(svdOutPath, "Bt-job/"
          + BtJob.OUTPUT_Q + "-*"), conf);

    SSVDPrototypeTest.assertOrthonormality(new DenseMatrix(mQ),
                                           false,
                                           s_epsilon);

    double[][] u =
      SSVDSolver.loadDistributedRowMatrix(fs,
                                          new Path(svdOutPath, "U/[^_]*"),
                                          conf);

    SSVDPrototypeTest.assertOrthonormality(new DenseMatrix(u), false, s_epsilon);
    double[][] v =
      SSVDSolver.loadDistributedRowMatrix(fs,
                                          new Path(svdOutPath, "V/[^_]*"),
                                          conf);

    SSVDPrototypeTest.assertOrthonormality(new DenseMatrix(v), false, s_epsilon);
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.DenseMatrix

Copyright © 2018 www.massapicom. 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.