Package org.apache.mahout.math

Examples of org.apache.mahout.math.SparseMatrix


    return new DiagonalMatrix(confidenceMatrix);
  }

  private Matrix buildConfidenceMatrixForUser(long userId) throws TasteException {
    PreferenceArray prefs = dataModel.getPreferencesFromUser(userId);
    Matrix confidenceMatrix = new SparseMatrix(dataModel.getNumItems(), dataModel.getNumItems());
    for (Preference pref : prefs) {
      long itemId = pref.getItemID();
      int itemIdx = itemIndex(itemId);
      confidenceMatrix.setQuick(itemIdx, itemIdx, 1);
    }
    return new DiagonalMatrix(confidenceMatrix);
  }
View Full Code Here


    }
    return new DiagonalMatrix(confidenceMatrix);
  }

  private Matrix buildPreferenceVectorForItem(long realId) throws TasteException {
    Matrix ids = new SparseMatrix(1, dataModel.getNumUsers());
    for (Preference pref : dataModel.getPreferencesForItem(realId)) {
      int useridx = userIndex(pref.getUserID());
      ids.setQuick(0, useridx, pref.getValue());
    }
    return ids;
  }
View Full Code Here

    }

    Preconditions.checkNotNull(scoresPerFeature);
    Preconditions.checkNotNull(scoresPerLabel);

    Matrix scoresPerLabelAndFeature = new SparseMatrix(scoresPerLabel.size(), scoresPerFeature.size());
    for (Pair<IntWritable,VectorWritable> entry : new SequenceFileDirIterable<IntWritable,VectorWritable>(
        new Path(base, TrainNaiveBayesJob.SUMMED_OBSERVATIONS), PathType.LIST, PathFilters.partFilter(), conf)) {
      scoresPerLabelAndFeature.assignRow(entry.getFirst().get(), entry.getSecond().get());
    }

    Vector perlabelThetaNormalizer = scoresPerLabel.like();
    /* for (Pair<Text,VectorWritable> entry : new SequenceFileDirIterable<Text,VectorWritable>(
        new Path(base, TrainNaiveBayesJob.THETAS), PathType.LIST, PathFilters.partFilter(), conf)) {
View Full Code Here

    Matrix em = model.getEmissionMatrix();
    Matrix tr = model.getTransitionMatrix();
    // allocate the sparse data structures
    RandomAccessSparseVector sparseIp = new RandomAccessSparseVector(model
        .getNrOfHiddenStates());
    SparseMatrix sparseEm = new SparseMatrix(model.getNrOfHiddenStates(), model.getNrOfOutputStates());
    SparseMatrix sparseTr = new SparseMatrix(model.getNrOfHiddenStates(), model.getNrOfHiddenStates());
    // now transfer the values
    for (int i = 0; i < model.getNrOfHiddenStates(); ++i) {
      double value = ip.getQuick(i);
      if (value > threshold) {
        sparseIp.setQuick(i, value);
      }
      for (int j = 0; j < model.getNrOfHiddenStates(); ++j) {
        value = tr.getQuick(i, j);
        if (value > threshold) {
          sparseTr.setQuick(i, j, value);
        }
      }

      for (int j = 0; j < model.getNrOfOutputStates(); ++j) {
        value = em.getQuick(i, j);
View Full Code Here

  @Test
  public void addLambdaTimesNuiTimesE() {
    int nui = 5;
    double lambda = 0.2;
    Matrix matrix = new SparseMatrix(5, 5);

    solver.addLambdaTimesNuiTimesE(matrix, lambda, nui);

    for (int n = 0; n < 5; n++) {
      assertEquals(1.0, matrix.getQuick(n, n), EPSILON);
    }
  }
View Full Code Here

      randomVectorValues.add(values);
      randomVectors.add(v);
    }
    vectors = new Vector[3][numVectors];
    clusters = new Vector[numClusters];
    clusterDistances = new SparseMatrix(numClusters, numClusters);
  }
View Full Code Here

 
  @Test
  public void addLambdaTimesNuiTimesE() {
    int nui = 5;
    double lambda = 0.2;
    Matrix matrix = new SparseMatrix(5, 5);

    AlternatingLeastSquaresSolver.addLambdaTimesNuiTimesE(matrix, lambda, nui);

    for (int n = 0; n < 5; n++) {
      assertEquals(1.0, matrix.getQuick(n, n), EPSILON);
    }
  }
View Full Code Here

    Frame frame = drm.frame;
    Vec labels = drm.keys;
    Matrix m;

    if (isSparse(frame)) {
      m = new SparseMatrix((int)frame.numRows(), frame.numCols());
    } else {
      m = new DenseMatrix((int)frame.numRows(), frame.numCols());
    }

    int c = 0;
View Full Code Here

    if (cow != null) {
      return;
    }

    if (chks[0].isSparse()) {
      cow = new SparseMatrix(chks[0].len(), chks.length);
    } else {
      cow = new DenseMatrix(chks[0].len(), chks.length);
    }

    for (int c = 0; c < chks.length; c++) {
View Full Code Here

  }

  @Override
  public Matrix like(int nrow, int ncol) {
    if (chks[0].isSparse()) {
      return new SparseMatrix(nrow, ncol);
    } else {
      return new DenseMatrix(nrow, ncol);
    }
  }
View Full Code Here

TOP

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

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.