Package org.apache.mahout.clustering.fuzzykmeans

Examples of org.apache.mahout.clustering.fuzzykmeans.SoftCluster


    List<Vector> randomPoints = RandomPointsUtil.chooseRandomPoints(points, k);
    List<SoftCluster> clusters = new ArrayList<SoftCluster>();
    System.out.println(randomPoints.size());
    int clusterId = 0;
    for (Vector v : randomPoints) {
      clusters.add(new SoftCluster(v, clusterId++, new CosineDistanceMeasure()));
    }
   
    List<List<SoftCluster>> finalClusters = FuzzyKMeansClusterer.clusterPoints(points, clusters,
      new CosineDistanceMeasure(), 0.01, 3, 10);
    for (SoftCluster cluster : finalClusters.get(finalClusters.size() - 1)) {
View Full Code Here


    List<Vector> randomPoints = RandomPointsUtil.chooseRandomPoints(sampleData,  k);
    List<SoftCluster> clusters = new ArrayList<SoftCluster>();

    int clusterId = 0;
    for (Vector v : randomPoints) {
      clusters.add(new SoftCluster(v, clusterId++, new EuclideanDistanceMeasure()));
    }

    List<List<SoftCluster>> finalClusters = FuzzyKMeansClusterer
        .clusterPoints(sampleData, clusters,
            new EuclideanDistanceMeasure(), 0.01, 3, 10);
View Full Code Here

  @Test
  public void testSoftClusterClassification() {
    List<Model<VectorWritable>> models = new ArrayList<Model<VectorWritable>>();
    DistanceMeasure measure = new ManhattanDistanceMeasure();
    models.add(new SoftCluster(new DenseVector(2).assign(1), 0, measure));
    models.add(new SoftCluster(new DenseVector(2), 1, measure));
    models.add(new SoftCluster(new DenseVector(2).assign(-1), 2, measure));
    AbstractVectorClassifier classifier = new VectorModelClassifier(models);
    Vector pdf = classifier.classify(new DenseVector(2));
    assertEquals("[0,0]", "[0.000, 1.000, 0.000]", AbstractCluster.formatVector(pdf, null));
    pdf = classifier.classify(new DenseVector(2).assign(2));
    assertEquals("[2,2]", "[0.735, 0.184, 0.082]", AbstractCluster.formatVector(pdf, null));
View Full Code Here

    Vector pdfs = new DenseVector(models.size());
    if (models.get(0) instanceof SoftCluster) {
      List<SoftCluster> clusters = new ArrayList<SoftCluster>();
      List<Double> distances = new ArrayList<Double>();
      for (Model<VectorWritable> model : models) {
        SoftCluster sc = (SoftCluster) model;
        clusters.add(sc);
        distances.add(sc.getMeasure().distance(instance, sc.getCenter()));
      }
      return new FuzzyKMeansClusterer().computePi(clusters, distances);
    } else {
      int i = 0;
      for (Model<VectorWritable> model : models) {
View Full Code Here

  public Vector classify(Vector instance) {
    if (models.get(0) instanceof SoftCluster) {
      Collection<SoftCluster> clusters = Lists.newArrayList();
      List<Double> distances = Lists.newArrayList();
      for (Cluster model : models) {
        SoftCluster sc = (SoftCluster) model;
        clusters.add(sc);
        distances.add(sc.getMeasure().distance(instance, sc.getCenter()));
      }
      return new FuzzyKMeansClusterer().computePi(clusters, distances);
    } else {
      int i = 0;
      Vector pdfs = new DenseVector(models.size());
View Full Code Here

  }
 
  private static ClusterClassifier newSoftClusterClassifier() {
    List<Cluster> models = Lists.newArrayList();
    DistanceMeasure measure = new ManhattanDistanceMeasure();
    models.add(new SoftCluster(new DenseVector(2).assign(1), 0, measure));
    models.add(new SoftCluster(new DenseVector(2), 1, measure));
    models.add(new SoftCluster(new DenseVector(2).assign(-1), 2, measure));
    return new ClusterClassifier(models);
  }
View Full Code Here

      points.add(SAMPLE_DATA.get(i).get());
    }
    List<Cluster> initialClusters = Lists.newArrayList();
    int id = 0;
    for (Vector point : points) {
      initialClusters.add(new SoftCluster(point, id++, measure));
    }
    ClusterClassifier prior = new ClusterClassifier(initialClusters);
    Path priorClassifier = new Path(output, "classifier-0");
    writeClassifier(prior, conf, priorClassifier);
   
View Full Code Here

  @Override
  public Vector classify(Vector data, ClusterClassifier prior) {
    Collection<SoftCluster> clusters = Lists.newArrayList();
    List<Double> distances = Lists.newArrayList();
    for (Cluster model : prior.getModels()) {
      SoftCluster sc = (SoftCluster) model;
      clusters.add(sc);
      distances.add(sc.getMeasure().distance(data, sc.getCenter()));
    }
    FuzzyKMeansClusterer fuzzyKMeansClusterer = new FuzzyKMeansClusterer();
    fuzzyKMeansClusterer.setM(m);
    return fuzzyKMeansClusterer.computePi(clusters, distances);
  }
View Full Code Here

  }

  private static ClusterClassifier newSoftClusterClassifier() {
    List<Cluster> models = Lists.newArrayList();
    DistanceMeasure measure = new ManhattanDistanceMeasure();
    models.add(new SoftCluster(new DenseVector(2).assign(1), 0, measure));
    models.add(new SoftCluster(new DenseVector(2), 1, measure));
    models.add(new SoftCluster(new DenseVector(2).assign(-1), 2, measure));
    return new ClusterClassifier(models, new FuzzyKMeansClusteringPolicy());
  }
View Full Code Here

      points.add(SAMPLE_DATA.get(i).get());
    }
    List<Cluster> initialClusters = Lists.newArrayList();
    int id = 0;
    for (Vector point : points) {
      initialClusters.add(new SoftCluster(point, id++, measure));
    }
    ClusterClassifier prior = new ClusterClassifier(initialClusters, new FuzzyKMeansClusteringPolicy(m, threshold));
    Path priorPath = new Path(output, "classifier-0");
    prior.writeToSeqFiles(priorPath);
   
View Full Code Here

TOP

Related Classes of org.apache.mahout.clustering.fuzzykmeans.SoftCluster

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.