Examples of DenseMatrix


Examples of org.apache.mahout.math.DenseMatrix

    double topicSmoothing = Double.parseDouble(job.get(TOPIC_SMOOTHING_KEY));
   
    Path dir = new Path(statePath);
    FileSystem fs = dir.getFileSystem(job);
   
    DenseMatrix pWgT = new DenseMatrix(numTopics, numWords);
    double[] logTotals = new double[numTopics];
    double ll = 0.0;
   
    IntPairWritable key = new IntPairWritable();
    DoubleWritable value = new DoubleWritable();
    for (FileStatus status : fs.globStatus(new Path(dir, "part-*"))) {
      Path path = status.getPath();
      SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, job);
      while (reader.next(key, value)) {
        int topic = key.getFirst();
        int word = key.getSecond();
        if (word == TOPIC_SUM_KEY) {
          logTotals[topic] = value.get();
          if (Double.isInfinite(value.get())) {
            throw new IllegalArgumentException();
          }
        } else if (topic == LOG_LIKELIHOOD_KEY) {
          ll = value.get();
        } else {
          if (!((topic >= 0) && (word >= 0))) {
            throw new IllegalArgumentException(topic + " " + word);
          }
          if (pWgT.getQuick(topic, word) != 0.0) {
            throw new IllegalArgumentException();
          }
          pWgT.setQuick(topic, word, value.get());
          if (Double.isInfinite(pWgT.getQuick(topic, word))) {
            throw new IllegalArgumentException();
          }
        }
      }
      reader.close();
View Full Code Here

Examples of org.apache.mahout.math.DenseMatrix

    return v;
  }
 
  private LDAState generateRandomState(int numWords, int numTopics) {
    double topicSmoothing = 50.0 / numTopics; // whatever
    Matrix m = new DenseMatrix(numTopics, numWords);
    double[] logTotals = new double[numTopics];
   
    for (int k = 0; k < numTopics; ++k) {
      double total = 0.0; // total number of pseudo counts we made
      for (int w = 0; w < numWords; ++w) {
        // A small amount of random noise, minimized by having a floor.
        double pseudocount = random.nextDouble() + 1.0E-10;
        total += pseudocount;
        m.setQuick(k, w, Math.log(pseudocount));
      }
     
      logTotals[k] = Math.log(total);
    }
   
View Full Code Here

Examples of org.apache.mahout.math.DenseMatrix

    // since some of the eigen-output is spurious and will be eliminated
    // upon verification, we have to aim to overshoot and then discard
    // unnecessary vectors later
    int overshoot = (int) ((double) clusters * OVERSHOOT_MULTIPLIER);
    List<Double> eigenValues = new ArrayList<Double>(overshoot);
    Matrix eigenVectors = new DenseMatrix(overshoot, numDims);
    DistributedLanczosSolver solver = new DistributedLanczosSolver();
    Path lanczosSeqFiles = new Path(outputCalc, "eigenvectors-" + (System.nanoTime() & 0xFF));
    solver.runJob(conf,
                  L.getRowPath(),
                  new Path(outputTmp, "lanczos-" + (System.nanoTime() & 0xFF)),
View Full Code Here

Examples of org.apache.mahout.math.DenseMatrix

      L.configure(new JobConf(conf));

      // eigendecomposition (step 3)
      int overshoot = (int) ((double) dimensions * OVERSHOOT_MULTIPLIER);
      List<Double> eigenValues = new ArrayList<Double>(overshoot);
      Matrix eigenVectors = new DenseMatrix(overshoot, dimensions);
      DistributedRowMatrix U = performEigenDecomposition(conf, L, dimensions, overshoot, eigenValues, eigenVectors, outputCalc);
      U.configure(new JobConf(conf));
      eigenValues = eigenValues.subList(0, dimensions);

      // here's where things get interesting: steps 4, 5, and 6 are unique
View Full Code Here

Examples of org.apache.mahout.math.DenseMatrix

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

Examples of org.apache.mahout.math.DenseMatrix

    double topicSmoothing = Double.parseDouble(job.get(TOPIC_SMOOTHING_KEY));

    Path dir = new Path(statePath);
    FileSystem fs = dir.getFileSystem(job);

    DenseMatrix pWgT = new DenseMatrix(numTopics, numWords);
    double[] logTotals = new double[numTopics];
    double ll = 0.0;

    IntPairWritable key = new IntPairWritable();
    DoubleWritable value = new DoubleWritable();
    for (FileStatus status : fs.globStatus(new Path(dir, "part-*"))) {
      Path path = status.getPath();
      SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, job);
      while (reader.next(key, value)) {
        int topic = key.getFirst();
        int word = key.getSecond();
        if (word == TOPIC_SUM_KEY) {
          logTotals[topic] = value.get();
          Preconditions.checkArgument(!Double.isInfinite(value.get()));
        } else if (topic == LOG_LIKELIHOOD_KEY) {
          ll = value.get();
        } else {
          Preconditions.checkArgument(topic >= 0, "topic should be non-negative, not %d", topic);
          Preconditions.checkArgument(word >= 0, "word should be non-negative not %d", word);
          Preconditions.checkArgument(pWgT.getQuick(topic, word) == 0.0);

          pWgT.setQuick(topic, word, value.get());
          Preconditions.checkArgument(!Double.isInfinite(pWgT.getQuick(topic, word)));
        }
      }
      reader.close();
    }

View Full Code Here

Examples of org.apache.mahout.math.DenseMatrix

    return v;
  }

  private LDAState generateRandomState(int numWords, int numTopics) {
    double topicSmoothing = 50.0 / numTopics; // whatever
    Matrix m = new DenseMatrix(numTopics,numWords);
    double[] logTotals = new double[numTopics];
    for(int k = 0; k < numTopics; ++k) {
      double total = 0.0; // total number of pseudo counts we made
      for(int w = 0; w < numWords; ++w) {
        // A small amount of random noise, minimized by having a floor.
        double pseudocount = random.nextDouble() + 1.0E-10;
        total += pseudocount;
        m.setQuick(k,w,Math.log(pseudocount));
      }

      logTotals[k] = Math.log(total);
    }
View Full Code Here

Examples of org.apache.mahout.math.DenseMatrix

  private final Vector averages;
  private final Vector samples;

  public GlobalOnlineAuc() {
    int numCategories = 2;
    scores = new DenseMatrix(numCategories, HISTORY);
    scores.assign(Double.NaN);
    averages = new DenseVector(numCategories);
    averages.assign(0.5);
    samples = new DenseVector(numCategories);
  }
View Full Code Here

Examples of org.apache.mahout.math.DenseMatrix

  @Test
  public void testMeasure() {
    double[][] invCovValues = { { 2.2, 0.4 }, { 0.4, 2.8 } };
    double[] meanValues = { -2.3, -0.9 };
    DenseMatrix invCov = new DenseMatrix(invCovValues);
    DenseVector meanVector = new DenseVector(meanValues);
    MahalanobisDistanceMeasure distanceMeasure = new MahalanobisDistanceMeasure();
    distanceMeasure.setInverseCovarianceMatrix(invCov);
    distanceMeasure.setMeanVector(meanVector);
    double[] v1 = { -1.9, -2.3 };
View Full Code Here

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
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.