Examples of VectorWritable


Examples of org.apache.mahout.math.VectorWritable

      System.out.println("Model[" + m + "] had " + count + " hits (!) and " + (samples.size() - count)
                         + " misses (? in pdf order) during the last iteration:");
      MapElement[] map = new MapElement[samples.size()];
      // sort the samples by pdf
      for (int i = 0; i < samples.size(); i++) {
        VectorWritable sample = samples.get(i);
        map[i] = new MapElement(model.pdf(sample), docs[i]);
      }
      Arrays.sort(map);
      // now find the n=model.count() most likely docs and output them
      for (int i = 0; i < map.length; i++) {
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

      while(it.hasNext()) {
        DistributedRowMatrix.MatrixEntryWritable e = it.next();
        tmp.setQuick(e.getCol(), e.getVal());
      }
      SequentialAccessSparseVector outVector = new SequentialAccessSparseVector(tmp);
      out.collect(outRow, new VectorWritable(outVector));
    }
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

      testData.mkdir();
    }
    FileSystem fs = FileSystem.get(new Path("testdata").toUri(), conf);
    List<VectorWritable> points = new ArrayList<VectorWritable>();
    for (Vector v : raw)
      points.add(new VectorWritable(v));
    ClusteringTestUtils.writePointsToFile(points, "testdata/file1", fs, conf);
    ClusteringTestUtils.writePointsToFile(points, "testdata/file2", fs, conf);
    // now run the Job
    MeanShiftCanopyJob.runJob("testdata", "output", EuclideanDistanceMeasure.class.getName(), 4, 1, 0.5, 10);
    JobConf conf = new JobConf(MeanShiftCanopyDriver.class);
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

      }
      while(it.hasNext()) {
        Vector row = it.next().get();
        row.addTo(accumulator);
      }
      out.collect(rowNum, new VectorWritable(new SequentialAccessSparseVector(accumulator)));
    }
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

      ParameteredGeneralizations.configureParameters(this, jobConf);
    }
    try {
      if (weightsFile.get() != null) {
        FileSystem fs = FileSystem.get(weightsFile.get().toUri(), jobConf);
        VectorWritable weights = (VectorWritable) vectorClass.get().newInstance();
        if (!fs.exists(weightsFile.get())) {
          throw new FileNotFoundException(weightsFile.get().toString());
        }
        DataInputStream in = fs.open(weightsFile.get());
        try {
          weights.readFields(in);
        } finally {
          in.close();
        }
        this.weights = weights.get();
      }
    } catch (IOException e) {
      throw new IllegalStateException(e);
    } catch (IllegalAccessException e) {
      throw new IllegalStateException(e);
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

    long now = System.nanoTime();
    Path inputVectorPath = new Path(outputVectorPathBase, INPUT_VECTOR + '/' + now);
    SequenceFile.Writer inputVectorPathWriter = new SequenceFile.Writer(fs,
            conf, inputVectorPath, NullWritable.class, VectorWritable.class);
    VectorWritable inputVW = new VectorWritable(v);
    inputVectorPathWriter.append(NullWritable.get(), inputVW);
    inputVectorPathWriter.close();
    URI ivpURI = inputVectorPath.toUri();
    DistributedCache.setCacheFiles(new URI[] {ivpURI}, conf);
    fs.deleteOnExit(inputVectorPath);
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

    Path outputPath = FileOutputFormat.getOutputPath(conf);
    FileSystem fs = FileSystem.get(conf);
    Path outputFile = new Path(outputPath, "part-00000");
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, outputFile, conf);
    NullWritable n = NullWritable.get();
    VectorWritable v = new VectorWritable();
    reader.next(n,v);
    Vector vector = v.get();
    reader.close();
    fs.deleteOnExit(outputFile);
    return vector;
  }
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

        FileSystem fs = inputVectorPath.getFileSystem(conf);

        SequenceFile.Reader reader = new SequenceFile.Reader(fs,
          inputVectorPath,
          conf);
        VectorWritable val = new VectorWritable();
        NullWritable nw = NullWritable.get();
        reader.next(nw, val);
        reader.close();
        inputVector = val.get();
        if(!(inputVector instanceof SequentialAccessSparseVector || inputVector instanceof DenseVector)) {
          inputVector = new SequentialAccessSparseVector(inputVector);
        }
        int outDim = conf.getInt(OUTPUT_VECTOR_DIMENSION, Integer.MAX_VALUE);
        outputVector = conf.getBoolean(IS_SPARSE_OUTPUT, false)
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

      return v.get().dot(inputVector);
    }

    @Override
    public void close() throws IOException {
      out.collect(NullWritable.get(), new VectorWritable(outputVector));
    }
View Full Code Here

Examples of org.apache.mahout.math.VectorWritable

  public void saveCleanEigens(List<Map.Entry<MatrixSlice,EigenStatus>> prunedEigenMeta) throws IOException {
    Path path = new Path(outPath, "largestCleanEigens");
    Configuration conf = getConf();
    FileSystem fs = FileSystem.get(conf);
    SequenceFile.Writer seqWriter = new SequenceFile.Writer(fs, conf, path, IntWritable.class, VectorWritable.class);
    VectorWritable vw = new VectorWritable();
    IntWritable iw = new IntWritable();
    for(Map.Entry<MatrixSlice,EigenStatus> pruneSlice : prunedEigenMeta) {
      MatrixSlice s = pruneSlice.getKey();
      EigenStatus meta = pruneSlice.getValue();
      EigenVector ev = new EigenVector((DenseVector)s.vector(),
                                       meta.getEigenValue(),
                                       Math.abs(1-meta.getCosAngle()),
                                       s.index());
      log.info("appending " + ev.getName() + " to " + path.toString());
      vw.set(ev);
      iw.set(s.index());
      seqWriter.append(iw, vw);
    }
    seqWriter.close();
  }
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.