Package org.apache.mahout.math

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


    Vector v = new DenseVector(1000);
    ByteBuffer buf = ByteBuffer.wrap(FileUtils
        .readFileToByteArray(new File(args[1])));
    FastLine line = FastLine.read(buf);
    while (line != null) {
      v.assign(0);
      for (int i = 0; i < FIELDS; i++) {
        encoder[i].addToVector((byte[]) null, line.getDouble(i), v);
      }
      line = FastLine.read(buf);
    }
View Full Code Here


    long t0 = System.currentTimeMillis();
    Vector v = new DenseVector(1000);
    BufferedReader in = new BufferedReader(new FileReader(args[1]));
    String line = in.readLine();
    while (line != null) {
      v.assign(0);
      Line x = new Line(line);
      for (int i = 0; i < FIELDS; i++) {
        encoder[i].addToVector((byte[]) null, x.getDouble(i), v);
      }
      line = in.readLine();
View Full Code Here

   *          initial classification bias.
   * */
  protected LinearTrainer(int dimension, double threshold,
                          double init, double initBias) throws CardinalityException {
    DenseVector initialWeights = new DenseVector(dimension);
    initialWeights.assign(init);
    this.model = new LinearModel(initialWeights, initBias, threshold);
  }
 
  /**
   * Initializes training. Runs through all data points in the training set and
View Full Code Here

   * @return
   */
  @Override
  protected Vector getInitialVector(VectorIterable corpus) {
    Vector initialVector = new DenseVector(corpus.numCols());
    initialVector.assign(1/Math.sqrt(corpus.numCols()));
    return initialVector;
  }

  @Override
  public int run(String[] strings) throws Exception {
View Full Code Here

      if (max < p) {
        max = p;
      }
    }
    // normalize the probabilities by largest observed value
    pi.assign(new TimesFunction(), 1.0 / max);
    return pi;
  }
 
  /**
   * Create a new instance on the sample data with the given additional parameters
View Full Code Here

    for (List<SoftCluster> cls : clusters) {
      g2.setStroke(new BasicStroke(i == 0 ? 3 : 1));
      g2.setColor(colors[Math.min(DisplayDirichlet.colors.length - 1, i--)]);
      for (SoftCluster cluster : cls) {
        // if (true || cluster.getWeightedPointTotal().zSum() > sampleData.size() * 0.05) {
        dv.assign(Math.max(cluster.std(), 0.3) * 3);
        DisplayDirichlet.plotEllipse(g2, cluster.getCenter(), dv);
        // }
      }
    }
  }
View Full Code Here

    for (Model<VectorWritable>[] models : result) {
      g2.setStroke(new BasicStroke(i == 0 ? 3 : 1));
      g2.setColor(colors[Math.min(DisplayDirichlet.colors.length - 1, i--)]);
      for (Model<VectorWritable> m : models) {
        AsymmetricSampledNormalModel mm = (AsymmetricSampledNormalModel) m;
        dv.assign(mm.getStdDev().times(3));
        if (DisplayDirichlet.isSignificant(mm)) {
          DisplayDirichlet.plotEllipse(g2, mm.getMean(), dv);
        }
      }
    }
View Full Code Here

    Vector dv = new DenseVector(2);
    for (Canopy canopy : canopies) {
      if (canopy.getNumPoints() > DisplayDirichlet.sampleData.size() * 0.05) {
        g2.setStroke(new BasicStroke(2));
        g2.setColor(colors[1]);
        dv.assign(t1);
        Vector center = canopy.computeCentroid();
        DisplayDirichlet.plotEllipse(g2, center, dv);
        g2.setStroke(new BasicStroke(3));
        g2.setColor(colors[0]);
        dv.assign(t2);
View Full Code Here

        dv.assign(t1);
        Vector center = canopy.computeCentroid();
        DisplayDirichlet.plotEllipse(g2, center, dv);
        g2.setStroke(new BasicStroke(3));
        g2.setColor(colors[0]);
        dv.assign(t2);
        DisplayDirichlet.plotEllipse(g2, center, dv);
      }
    }
  }
 
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

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.