Package org.apache.mahout.math

Examples of org.apache.mahout.math.DenseVector$AllIterator


  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();
    FileSystem fs = FileSystem.get(conf);
View Full Code Here


    FeatureVectorEncoder[] encoder = new FeatureVectorEncoder[FIELDS];
    for (int i = 0; i < FIELDS; i++) {
      encoder[i] = new ConstantValueEncoder("v" + i);
    }
    long t0 = System.currentTimeMillis();
    Vector v = new DenseVector(1000);
    ByteBuffer buf = ByteBuffer.wrap(FileUtils
        .readFileToByteArray(new File(args[1])));
    FastLine line = FastLine.read(buf);
    while (line != null) {
      v.assign(0);
      for (int i = 0; i < FIELDS; i++) {
        encoder[i].addToVector((byte[]) null, line.getDouble(i), v);
      }
      line = FastLine.read(buf);
    }
View Full Code Here

      points.add(new VectorWritable(sd));
    }

    DirichletClusterer dc = new DirichletClusterer(points,
        new GaussianClusterDistribution(new VectorWritable(
            new DenseVector(2))), 1.0, 10, 2, 2);
    List<Cluster[]> result = dc.cluster(20);
    for (Cluster cluster : result.get(result.size() - 1)) {
      System.out.println("Cluster id: " + cluster.getId() + " center: "
          + cluster.getCenter().asFormatString());
    }
View Full Code Here

public class RandomPointsUtil {
  public static void generateSamples(List<Vector> vectors, int num,
      double mx, double my, double sd) {
    for (int i = 0; i < num; i++) {
      vectors.add(new DenseVector(new double[] {
          UncommonDistributions.rNorm(mx, sd),
          UncommonDistributions.rNorm(my, sd) }));
    }
  } 
View Full Code Here

    FeatureVectorEncoder[] encoder = new FeatureVectorEncoder[FIELDS];
    for (int i = 0; i < FIELDS; i++) {
      encoder[i] = new ConstantValueEncoder("v" + i);
    }
    long t0 = System.currentTimeMillis();
    Vector v = new DenseVector(1000);
    BufferedReader in = new BufferedReader(new FileReader(args[1]));
    String line = in.readLine();
    while (line != null) {
      v.assign(0);
      Line x = new Line(line);
      for (int i = 0; i < FIELDS; i++) {
        encoder[i].addToVector((byte[]) null, x.getDouble(i), v);
      }
      line = in.readLine();
View Full Code Here

public class VectorExamplesTest extends TamingTextTestJ4 {
  @Test
  public void testProgrammatic() throws Exception {
    //<start id="vec.examples.programmatic"/>
    double[] vals = new double[]{0.3, 1.8, 200.228};
    Vector dense = new DenseVector(vals);//<co id="vec.exam.dense"/>
    assertTrue(dense.size() == 3);
    Vector sparseSame = new SequentialAccessSparseVector(3);//<co id="vec.exam.sparse.same"/>
    Vector sparse = new SequentialAccessSparseVector(3000);//<co id="vec.exam.sparse"/>
    for (int i = 0; i < vals.length; i++) {//<co id="vec.exam.assign.sparse"/>
      sparseSame.set(i, vals[i]);
      sparse.set(i, vals[i]);
    }
    assertFalse(dense.equals(sparse));//<co id="vec.exam.notequals.d.s"/>
    assertEquals(dense, sparseSame);//<co id="vec.exam.equals.d.s"/>
    assertFalse(sparse.equals(sparseSame));
    /*
<calloutlist>
    <callout arearefs="vec.exam.dense"><para>Create a <classname>DenseVector</classname> with a label of "my-dense" and 3 values.  The cardinality of this vector is 3 </para></callout>
View Full Code Here

    @Override
    public Vector next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      Vector result = type == VectorType.SPARSE ? new RandomAccessSparseVector(numItems) : new DenseVector(numItems);
      result.assign(new UnaryFunction(){
        @Override
        public double apply(double arg1) {
          return random.nextDouble();
        }
View Full Code Here

 
  public void test() throws Exception {
    StringWriter strWriter = new StringWriter();
    VectorWriter writer = new JWriterVectorWriter(strWriter);
    List<Vector> vectors = new ArrayList<Vector>();
    vectors.add(new DenseVector(new double[]{0.3, 1.5, 4.5}));
    vectors.add(new DenseVector(new double[]{1.3, 1.5, 3.5}));
    writer.write(vectors);
    writer.close();
    StringBuffer buffer = strWriter.getBuffer();
    Assert.assertNotNull(buffer);
    Assert.assertTrue(buffer.length() > 0);
View Full Code Here

    if (tokenizer.countTokens() != nball) {
      throw new IllegalArgumentException("Wrong number of attributes in the string");
    }
   
    int nbattrs = dataset.nbAttributes();
    DenseVector vector = new DenseVector(nbattrs);
   
    int aId = 0;
    int label = -1;
    for (int attr = 0; attr < nball; attr++) {
      String token = tokenizer.nextToken().trim();
     
      if (ArrayUtils.contains(dataset.getIgnored(), attr)) {
        continue; // IGNORED
      }
     
      if ("?".equals(token)) {
        // missing value
        return null;
      }
     
      if (attr == dataset.getLabelId()) {
        label = dataset.labelCode(token);
        if (label == -1) {
          log.error(String.format("label token: %s\ndataset.labels: %s", token, Arrays
              .toString(dataset.labels())));
          throw new IllegalStateException("Label value (" + token + ") not known");
        }
      } else if (dataset.isNumerical(aId)) {
        vector.set(aId++, Double.parseDouble(token));
      } else {
        vector.set(aId, dataset.valueOf(aId, token));
        aId++;
      }
    }
   
    if (label == -1) {
View Full Code Here

      tokens[attr] = token;
    }
   
    int nbattrs = Dataset.countAttributes(attrs);
   
    DenseVector vector = new DenseVector(nbattrs);
   
    int aId = 0;
    int label = -1;
    for (int attr = 0; attr < attrs.length; attr++) {
      if (attrs[attr].isIgnored()) {
        continue;
      }
     
      String token = tokens[attr];
     
      if (attrs[attr].isNumerical()) {
        vector.set(aId++, Double.parseDouble(token));
      } else { // CATEGORICAL or LABEL
        // update values
        if (values[attr] == null) {
          values[attr] = new ArrayList<String>();
        }
        if (!values[attr].contains(token)) {
          values[attr].add(token);
        }
       
        if (attrs[attr].isCategorical()) {
          vector.set(aId++, values[attr].indexOf(token));
        } else { // LABEL
          label = values[attr].indexOf(token);
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.DenseVector$AllIterator

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.