Package org.apache.mahout.math

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


    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

    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

        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

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

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

  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

        + "] sd=" + sd);
    for (int i = 0; i < num; i++) {
      DenseVector v = new DenseVector(card);
      for (int j = 0; j < card; j++)
        v.set(j, UncommonDistributions.rNorm(mx, sd));
      sampleData.add(new VectorWritable(v));
    }
  }
View Full Code Here

    generateSamples(40, 1, 1, 3);
    generateSamples(30, 1, 0, 0.1);
    generateSamples(30, 0, 1, 0.1);

    DirichletClusterer<VectorWritable> dc = new DirichletClusterer<VectorWritable>(
        sampleData, new NormalModelDistribution(new VectorWritable(
            new DenseVector(2))), 1.0, 10, 1, 0);
    List<Model<VectorWritable>[]> result = dc.cluster(30);
    printResults(result, 2);
    assertNotNull(result);
  }
View Full Code Here

    generateSamples(40, 1, 1, 3);
    generateSamples(30, 1, 0, 0.1);
    generateSamples(30, 0, 1, 0.1);

    DirichletClusterer<VectorWritable> dc = new DirichletClusterer<VectorWritable>(
        sampleData, new SampledNormalDistribution(new VectorWritable(
            new DenseVector(2))), 1.0, 10, 1, 0);
    List<Model<VectorWritable>[]> result = dc.cluster(30);
    printResults(result, 2);
    assertNotNull(result);
  }
View Full Code Here

    generateSamples(40, 1, 1, 3);
    generateSamples(30, 1, 0, 0.1);
    generateSamples(30, 0, 1, 0.1);

    DirichletClusterer<VectorWritable> dc = new DirichletClusterer<VectorWritable>(
        sampleData, new AsymmetricSampledNormalDistribution(new VectorWritable(
            new DenseVector(2))), 1.0, 10, 1, 0);
    List<Model<VectorWritable>[]> result = dc.cluster(30);
    printResults(result, 2);
    assertNotNull(result);
  }
View Full Code Here

TOP

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

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.