Package org.apache.mahout.clustering.kmeans

Examples of org.apache.mahout.clustering.kmeans.Cluster


  @Test
  public void testClusterClassification() {
    List<Model<VectorWritable>> models = new ArrayList<Model<VectorWritable>>();
    DistanceMeasure measure = new ManhattanDistanceMeasure();
    models.add(new Cluster(new DenseVector(2).assign(1), 0, measure));
    models.add(new Cluster(new DenseVector(2), 1, measure));
    models.add(new Cluster(new DenseVector(2).assign(-1), 2, measure));
    AbstractVectorClassifier classifier = new VectorModelClassifier(models);
    Vector pdf = classifier.classify(new DenseVector(2));
    assertEquals("[0,0]", "[0.107, 0.787, 0.107]", AbstractCluster.formatVector(pdf, null));
    pdf = classifier.classify(new DenseVector(2).assign(2));
    assertEquals("[2,2]", "[0.867, 0.117, 0.016]", AbstractCluster.formatVector(pdf, null));
View Full Code Here


          } catch (IllegalAccessException e) {
            log.error("Exception", e);
            throw new IllegalStateException(e);
          }
          if (valueClass.equals(Cluster.class)) {
            Cluster value = new Cluster();
            while (reader.next(key, value)) {
              // get the cluster info
              SoftCluster theCluster = new SoftCluster(value.getCenter(), value.getId(), value.getMeasure());
              clusters.add(theCluster);
              value = new Cluster();
            }
          } else if (valueClass.equals(SoftCluster.class)) {
            SoftCluster value = new SoftCluster();
            while (reader.next(key, value)) {
              // get the cluster info
              clusters.add(value);
              value = new SoftCluster();
            }
          } else if (valueClass.equals(Canopy.class)) {
            Canopy value = new Canopy();
            while (reader.next(key, value)) {
              // get the cluster info
              SoftCluster theCluster = new SoftCluster(value.getCenter(), value.getId(), value.getMeasure());
              clusters.add(theCluster);
              value = new Canopy();
            }
          }
        } finally {
View Full Code Here

                                                    PathFilters.partFilter(),
                                                    new Configuration())) {
      Class<? extends Writable> valueClass = value.getClass();
      if (valueClass.equals(Cluster.class)) {
        // get the cluster info
        Cluster cluster = (Cluster) value;
        clusters.add(new SoftCluster(cluster.getCenter(), cluster.getId(), cluster.getMeasure()));
      } else if (valueClass.equals(SoftCluster.class)) {
        // get the cluster info
        clusters.add((SoftCluster) value);
      } else if (valueClass.equals(Canopy.class)) {
        // get the cluster info
View Full Code Here

                                                    PathFilters.partFilter(),
                                                    conf)) {
      Class<? extends Writable> valueClass = value.getClass();
      if (valueClass.equals(Cluster.class)) {
        // get the cluster info
        Cluster cluster = (Cluster) value;
        Vector vector = cluster.getCenter();
        if (vector instanceof NamedVector) {
          seedVectors.add((NamedVector) vector);
        } else {
          seedVectors.add(new NamedVector(vector, cluster.getIdentifier()));
        }
      } else if (valueClass.equals(Canopy.class)) {
        // get the cluster info
        Canopy canopy = (Canopy) value;
        Vector vector = canopy.getCenter();
View Full Code Here

  @Override
  public void map(LongWritable key, Text values,
      OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
    String foo = values.toString();
    int ix = foo.indexOf(']');
    Cluster canopy = Cluster.decodeCluster(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

          } catch (IllegalAccessException e) {
            log.error("Exception", e);
            throw new IllegalStateException(e);
          }
          if (valueClass.equals(Cluster.class)) {
            Cluster value = new Cluster();
            while (reader.next(key, value)) {
              // get the cluster info
              SoftCluster theCluster = new SoftCluster(value.getCenter(), value.getId());
              clusters.add(theCluster);
              value = new Cluster();
            }
          } else if (valueClass.equals(SoftCluster.class)) {
            SoftCluster value = new SoftCluster();
            while (reader.next(key, value)) {
              // get the cluster info
View Full Code Here

    for (Path path : result) {
      for (Writable value : new SequenceFileValueIterable<Writable>(path, conf)) {
        Class<? extends Writable> valueClass = value.getClass();
        if (valueClass.equals(Cluster.class)) {
          // get the cluster info
          Cluster cluster = (Cluster) value;
          clusters.add(new SoftCluster(cluster.getCenter(), cluster.getId(), cluster.getMeasure()));
        } else if (valueClass.equals(SoftCluster.class)) {
          // get the cluster info
          clusters.add((SoftCluster) value);
        } else if (valueClass.equals(Canopy.class)) {
          // get the cluster info
View Full Code Here

    public List<Cluster> readClustersIteration(Path clusterIterationPath) {
        List<Cluster> clusters = new ArrayList<Cluster>();
        SequenceFileDirectoryReader iterationReader = null;
        try {
            Text k = new Text();
            Cluster c = new Cluster();
            iterationReader = new SequenceFileDirectoryReader(clusterIterationPath);
            while (iterationReader.next(k, c)) {
                clusters.add(c);
            }
        } catch (IOException e) {
View Full Code Here

        loadPoints();
    }

    private void loadCentroids() throws IOException {
        Text k = new Text();
        Cluster v = new Cluster();
        CoCluster c;
        SequenceFile.Reader currReader = null;
        try {
            fs = FileSystem.get(clustersPath.toUri(), conf);
            for (FileStatus status : fs.listStatus(clustersPath)) {
                Path p = status.getPath();
                if (!status.isDir() && !p.getName().startsWith("_")) {
                    try {
                        currReader = new SequenceFile.Reader(fs, p, conf);
                        while (currReader.next(k, v)) {
                            c = new CoCluster(v.getCenter(), v.getMeasure());
                            coclusters.put(v.getId(), c);
                        }
                    } finally {
                        IOUtils.closeStream(currReader);
                    }
                }
View Full Code Here

TOP

Related Classes of org.apache.mahout.clustering.kmeans.Cluster

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.