Package org.apache.mahout.math

Examples of org.apache.mahout.math.DenseVector.assign()


  @Override
  public Vector classify(Vector instance) {
    Vector r = new DenseVector(numCategories() - 1);
    DoubleDoubleFunction scale = Functions.plusMult(1.0 / models.size());
    for (OnlineLogisticRegression model : models) {
      r.assign(model.classify(instance), scale);
    }
    return r;
  }

  @Override
View Full Code Here


  @Override
  public Vector classifyNoLink(Vector instance) {
    Vector r = new DenseVector(numCategories() - 1);
    DoubleDoubleFunction scale = Functions.plusMult(1.0 / models.size());
    for (OnlineLogisticRegression model : models) {
      r.assign(model.classifyNoLink(instance), scale);
    }
    return r;
  }

  @Override
View Full Code Here

    int i = 0;
    Vector pdfs = new DenseVector(models.size());
    for (Cluster model : models) {
      pdfs.set(i++, model.pdf(new VectorWritable(data)));
    }
    return pdfs.assign(new TimesFunction(), 1.0 / pdfs.zSum());
  }
 
  @Override
  public void close(ClusterClassifier posterior) {
    for (Cluster cluster : posterior.getModels()) {
View Full Code Here

    // target variable of 0, the last 30 a target of 1.  The remaining columns are are random noise.
    input = readCsv("sgd.csv");

    // regenerate the target variable
    Vector target = new DenseVector(60);
    target.assign(0);
    target.viewPart(30, 30).assign(1);
    return target;
  }

  static void train(Matrix input, Vector target, OnlineLearner lr) {
View Full Code Here

        int count = 0;
        Vector center = new DenseVector(2);
        for (int vix : canopy.getBoundPoints().toList()) {
          Vector v = SAMPLE_DATA.get(vix).get();
          count++;
          center.assign(v, Functions.PLUS);
          DisplayClustering.plotRectangle(g2, v, dv);
        }
        center = center.divide(count);
        DisplayClustering.plotEllipse(g2, center, dv1);
        DisplayClustering.plotEllipse(g2, center, dv2);
View Full Code Here

      Vector v = new DenseVector(numCols);
      for (int col = 0; col < numCols; col++) {
        double val = r.nextGaussian();
        v.set(col, val);
      }
      v.assign(Functions.MULT, 1/((row + 1) * v.norm(2)));
      matrix.assignRow(row, v);
    }
    if (symmetric) {
      return matrix.times(matrix.transpose());
    }
View Full Code Here

  }

  @Override
  public Vector classifyNoLink(Vector instance) {
    Vector result = new DenseVector(weights.numRows());
    result.assign(0);
    for (int i = 0; i < weights.numRows(); i++) {
      result.setQuick(i, weights.viewRow(i).dot(instance));
    }
    return result;
  }
View Full Code Here

    sealed = false;
  }

  private void regularizeAll() {
    Vector all = new DenseVector(beta.numCols());
    all.assign(1);
    regularize(all);
  }

  @Override
  public void close() {
View Full Code Here

      }
      // converged!
      double eigenValue = state.getStatusProgress().get(state.getStatusProgress().size() - 1).getEigenValue();
      // it's actually more efficient to do this to normalize than to call currentEigen = currentEigen.normalize(),
      // because the latter does a clone, which isn't necessary here.
      currentEigen.assign(new TimesFunction(), 1 / currentEigen.norm(2));
      eigens.assignRow(i, currentEigen);
      eigenValues.add(eigenValue);
      state.setCurrentEigenValues(eigenValues);
      log.info("Found eigenvector {}, eigenvalue: {}", i, eigenValue);
View Full Code Here

    } else if ("--parse".equals(args[0])) {
      BufferedReader in = Files.newReader(new File(args[1]), Charsets.UTF_8);
      try {
        String line = in.readLine();
        while (line != null) {
          v.assign(0);
          Line x = new Line(line);
          for (int i = 0; i < FIELDS; i++) {
            s[i].add(x.getDouble(i));
            encoder[i].addToVector(x.get(i), v);
          }
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.