Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.Vector


  private List<Canopy> canopies;

  @Override
  public void map(WritableComparable<?> key, Text values,
                  OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
    Vector point = AbstractVector.decodeVector(values.toString());
    Canopy.emitPointToExistingCanopies(point, canopies, values, output);
  }
View Full Code Here


  @Override
  public void reduce(Text key, Iterator<Text> values,
      OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
    Writable value = values.next();
    Vector center = AbstractVector.decodeVector(value.toString());
    Canopy canopy = new Canopy(center);
    while (values.hasNext()) {
      value = values.next();
      Vector point = AbstractVector.decodeVector(value.toString());
      canopy.addPoint(point);
    }
    output.collect(new Text("centroid"), new Text(canopy.computeCentroid()
        .asFormatString()));
  }
View Full Code Here

        .getModels());

    // iterate over the samples, assigning each to a model
    for (Observation x : sampleData) {
      // compute normalized vector of probabilities that x is described by each model
      Vector pi = normalizedProbabilities(state, x);
      // then pick one cluster by sampling a Multinomial distribution based upon them
      // see: http://en.wikipedia.org/wiki/Multinomial_distribution
      int k = UncommonDistributions.rMultinom(pi);
      // ask the selected model to observe the datum
      newModels[k].observe(x);
View Full Code Here

   * @param x an Observation
   * @return the Vector of probabilities
   */
  private Vector normalizedProbabilities(DirichletState<Observation> state,
      Observation x) {
    Vector pi = new DenseVector(numClusters);
    double max = 0;
    for (int k = 0; k < numClusters; k++) {
      double p = state.adjustedProbability(x, k);
      pi.set(k, p);
      if (max < p)
        max = p;
    }
    // normalize the probabilities by largest observed value
    pi.assign(new TimesFunction(), 1.0 / max);
    return pi;
  }
View Full Code Here

  public void reduce(Text key, Iterator<Text> values,
      OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
    Integer k = new Integer(key.toString());
    Model<Vector> model = newModels[k];
    while (values.hasNext()) {
      Vector v = DenseVector.decodeFormat(values.next().toString());
      model.observe(v);
    }
    model.computeParameters();
    DirichletCluster<Vector> cluster = state.clusters.get(k);
    cluster.setModel(model);
View Full Code Here

      if (valueStr.startsWith("new"))
        canopy.init(MeanShiftCanopy.decodeCanopy(valueStr.substring(4)));
      else if (valueStr.startsWith("merge"))
        canopy.merge(MeanShiftCanopy.decodeCanopy(valueStr.substring(6)));
      else {
        Vector formatString = DenseVector.decodeFormat(new Text(valueStr));
        int number = Integer.parseInt(valueStr.substring(valueStr.indexOf(']') + 2));
        canopy.addPoints(formatString, number);
      }
    }
    // Combiner may see situations where a canopy touched others in the mapper
View Full Code Here

    String boundPoints = formattedString.substring(endIndex + 1).trim();
    char firstChar = id.charAt(0);
    boolean startsWithV = firstChar == 'V';
    if (firstChar == 'C' || startsWithV) {
      int canopyId = Integer.parseInt(formattedString.substring(1, beginIndex - 3));
      Vector canopyCentroid = DenseVector.decodeFormat(new Text(centroid));
      List<Vector> canopyBoundPoints = new ArrayList<Vector>();
      while (boundPoints.length() > 0) {
        int ix = boundPoints.indexOf(']');
        Vector v = DenseVector.decodeFormat(new Text(boundPoints.substring(0,
            ix + 1)));
        canopyBoundPoints.add(v);
        boundPoints = boundPoints.substring(ix + 1);
      }
      return new MeanShiftCanopy(canopyCentroid, canopyId, canopyBoundPoints,
View Full Code Here

    List<Double> doubles = new ArrayList<Double>();
    for (String value : numbers) {
      if (value.length() > 0)
        doubles.add(Double.valueOf(value));
    }
    Vector result = new DenseVector(doubles.size());
    int index = 0;
    for (Double d : doubles)
      result.set(index++, d);
    output.collect(null, new Text(result.asFormatString()));
  }
View Full Code Here

  public void map(LongWritable key, Text values,
      OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
    String foo = values.toString();
    int ix = foo.indexOf(']');
    Canopy canopy = Canopy.decodeCanopy(foo.substring(0, ix + 1));
    Vector point = AbstractVector.decodeVector(foo.substring(ix + 3));
    output.collect(new Text(canopy.getIdentifier()), new Text(point
        .asFormatString()));
  }
View Full Code Here

    List<Double> doubles = new ArrayList<Double>();
    for (String value : numbers) {
      if (value.length() > 0)
        doubles.add(Double.valueOf(value));
    }
    Vector point = new DenseVector(doubles.size());
    int index = 0;
    for (Double d : doubles)
      point.set(index++, d);
    MeanShiftCanopy canopy = new MeanShiftCanopy(point);
    output.collect(null, new Text(canopy.toString()));
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.matrix.Vector

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.