Package org.apache.mahout.math

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


    sampleMean = sum.divide(sampleN);

    Vector sampleVar = new DenseVector(2);
    for (VectorWritable v : sampleData) {
      Vector delta = v.get().minus(sampleMean);
      sampleVar.assign(delta.times(delta), Functions.PLUS);
    }
    sampleVar = sampleVar.divide(sampleN - 1);
    sampleStd = sampleVar.clone();
    sampleStd.assign(new SquareRootFunction());
    log.info("Observing {} samples m=[{}, {}] sd=[{}, {}]",
View Full Code Here


    Matrix projection = new DenseMatrix(64, 10);
    projection.assign(gen);

    Vector query = new DenseVector(10);
    query.assign(gen);
    long qhash = HashedVector.computeHash64(query, projection);

    int count[] = new int[65];
    Vector v = new DenseVector(10);
    for (int i = 0; i <500000; i++) {
View Full Code Here

    long qhash = HashedVector.computeHash64(query, projection);

    int count[] = new int[65];
    Vector v = new DenseVector(10);
    for (int i = 0; i <500000; i++) {
      v.assign(gen);
      long hash = HashedVector.computeHash64(v, projection);
      final int bitDot = Long.bitCount(qhash ^ hash);
      count[bitDot]++;
      if (count[bitDot] < 200) {
        System.out.printf("%d, %.3f\n", bitDot, v.dot(query) / Math.sqrt(v.getLengthSquared() * query.getLengthSquared()));
 
View Full Code Here

    v.set(v.maxValueIndex(), 0);
    assertEquals(8.0, v.norm(0), 0);
    assertEquals(8.0, v.norm(1), 0);
    assertEquals(1.0, v.maxValue(), 0);

    v.assign(0);
    t = csv.processLine("ignore,5.3,no,line, \"and more text and more\",ignore", v);
    assertEquals(1, t);

    // should have 9 values set
    assertEquals(9.0, v.norm(0), 0);
View Full Code Here

    v.set(v.maxValueIndex(), 0);
    assertEquals(8.0, v.norm(0), 0);
    assertEquals(10.339850002884626, v.norm(1), 1.0e-6);
    assertEquals(1.5849625007211563, v.maxValue(), 1.0e-6);

    v.assign(0);
    t = csv.processLine("ignore,5.3,invalid,line, \"and more text and more\",ignore", v);
    assertEquals(1, t);

    // should have 9 values set
    assertEquals(9.0, v.norm(0), 0);
View Full Code Here

  @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

   * For the distributed case, the best guess at a useful initialization state for Lanczos we'll chose to be
   * uniform over all input dimensions, L_2 normalized.
   */
  public Vector getInitialVector(VectorIterable corpus) {
    Vector initialVector = new DenseVector(corpus.numCols());
    initialVector.assign(1.0 / Math.sqrt(corpus.numCols()));
    return initialVector;
  }

  public LanczosState runJob(Configuration originalConfig,
                             LanczosState state,
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

    } else if ("--fast".equals(args[0])) {
      FastLineReader in = new FastLineReader(new FileInputStream(args[1]));
      try {
        FastLine line = in.read();
        while (line != null) {
          v.assign(0);
          for (int i = 0; i < FIELDS; i++) {
            double z = line.getDouble(i);
            s[i].add(z);
            encoder[i].addToVector((byte[]) null, z, 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.