Package org.apache.mahout.math

Examples of org.apache.mahout.math.NamedVector


public class ApplesToVectors {
  public static void main(String args[]) throws Exception {
    List<NamedVector> apples = new ArrayList<NamedVector>();
   
    NamedVector apple;
    apple = new NamedVector(                   
        new DenseVector(new double[] {0.11, 510, 1}),
        "Small round green apple");
    apples.add(apple);
    apple = new NamedVector(
      new DenseVector(new double[] {0.23, 650, 3}),
        "Large oval red apple");
    apples.add(apple);
    apple = new NamedVector(
      new DenseVector(new double[] {0.09, 630, 1}),
        "Small elongated red apple");
    apples.add(apple);
    apple = new NamedVector(
      new DenseVector(new double[] {0.25, 590, 3}),
        "Large round yellow apple");
    apples.add(apple);
    apple = new NamedVector(
      new DenseVector(new double[] {0.18, 520, 2}),
        "Medium oval green apple");

   
    Configuration conf = new Configuration();
View Full Code Here


      return;
    }
    String artist = fields[1];
    String tag = fields[2];
    double weight = Double.parseDouble(fields[3]);
    NamedVector vector = new NamedVector(
        new SequentialAccessSparseVector(dictionary.size()), tag);
    vector.set(dictionary.get(artist), weight);
    writer.set(vector);
    context.write(new Text(tag), writer);
  }
View Full Code Here

      if (vector == null) {
        vector = partialVector.get().like();
      }
      partialVector.get().addTo(vector);
    }
    NamedVector namedVector = new NamedVector(vector, tag.toString());
    writer.set(namedVector);
    context.write(tag, writer);
  }
View Full Code Here

    Iterable<Vector> iterable = new LuceneIterable(reader, "id", "content", mapper);

    i = 0;
    for (Vector vector : iterable) {
      assertNotNull(vector);
      NamedVector namedVector;
      if (vector instanceof NamedVector) {
        //rename it for testing purposes
        namedVector = new NamedVector(((NamedVector) vector).getDelegate(), "P(" + i + ')');

      } else {
        namedVector = new NamedVector(vector, "P(" + i + ')');
      }
      System.out.println(AbstractCluster.formatVector(namedVector, termDictionary));
      sampleData.add(new VectorWritable(namedVector));
      i++;
    }
View Full Code Here

  }

  @Test
  public void testDirichlet() throws Exception {
    Path output = getTestTempDirPath("output");
    NamedVector prototype = (NamedVector) sampleData.get(0).get();
    AbstractVectorModelDistribution modelDistribution = new SampledNormalDistribution(new VectorWritable(prototype));
    Configuration conf = new Configuration();
    DirichletDriver.run(conf, getTestTempDirPath("testdata"), output, modelDistribution, 15, 10, 1.0, true, true, 0, false);
    // run ClusterDumper
    ClusterDumper clusterDumper = new ClusterDumper(finalClusterPath(conf, output, 10), new Path(output, "clusteredPoints"));
View Full Code Here

  }

  @Test
  public void testDirichlet2() throws Exception {
    Path output = getTestTempDirPath("output");
    NamedVector prototype = (NamedVector) sampleData.get(0).get();
    AbstractVectorModelDistribution modelDistribution = new GaussianClusterDistribution(new VectorWritable(prototype));
    Configuration conf = new Configuration();
    DirichletDriver.run(conf, getTestTempDirPath("testdata"), output, modelDistribution, 15, 10, 1.0, true, true, 0, true);
    // run ClusterDumper
    ClusterDumper clusterDumper = new ClusterDumper(finalClusterPath(conf, output, 10), new Path(output, "clusteredPoints"));
View Full Code Here

  }

  @Test
  public void testDirichlet3() throws Exception {
    Path output = getTestTempDirPath("output");
    NamedVector prototype = (NamedVector) sampleData.get(0).get();
    AbstractVectorModelDistribution modelDistribution = new DistanceMeasureClusterDistribution(new VectorWritable(prototype));
    Configuration conf = new Configuration();
    DirichletDriver.run(conf, getTestTempDirPath("testdata"), output, modelDistribution, 15, 10, 1.0, true, true, 0, true);
    // run ClusterDumper
    ClusterDumper clusterDumper = new ClusterDumper(finalClusterPath(conf, output, 10), new Path(output, "clusteredPoints"));
View Full Code Here

    if (sequentialAccess) {
      vector = new SequentialAccessSparseVector(vector);
    }
   
    if (namedVector) {
      vector = new NamedVector(vector, key.toString());
    }
   
    VectorWritable vectorWritable = new VectorWritable(vector);
    context.write(key, vectorWritable);
  }
View Full Code Here

    if (sequentialAccess) {
      vector = new SequentialAccessSparseVector(vector);
    }
   
    if (namedVector) {
      vector = new NamedVector(vector, key.toString());
    }
   
    // if the vector has no nonZero entries (nothing in the dictionary), let's not waste space sending it to disk.
    if (vector.getNumNondefaultElements() > 0) {
      VectorWritable vectorWritable = new VectorWritable(vector);
View Full Code Here

      vector = new SequentialAccessSparseVector(cardinality);
    } else {
      vector = new RandomAccessSparseVector(cardinality);
    }
    if (namedVectors){
      vector = new NamedVector(vector, key.toString());
    }
    encoder.addToVector(value.toString(), vector);
    context.write(new Text(key.toString()), new VectorWritable(vector));
  }
View Full Code Here

TOP

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

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.