Package cc.mallet.cluster

Examples of cc.mallet.cluster.Clustering


  public double evaluate (Neighbor neighbor) {
     if (!(neighbor instanceof AgglomerativeNeighbor))
       throw new IllegalArgumentException("Expect AgglomerativeNeighbor not " + neighbor.getClass().getName());
     AgglomerativeNeighbor aneighbor = (AgglomerativeNeighbor) neighbor;

    Clustering original = neighbor.getOriginal();
//    int[] mergedIndices = ((AgglomerativeNeighbor)neighbor).getNewCluster();
    int[] cluster1 = aneighbor.getOldClusters()[0];
    int[] cluster2 = aneighbor.getOldClusters()[1];
    ArrayList<Double> scores = new ArrayList<Double>();
View Full Code Here


  if (!(neighbor instanceof AgglomerativeNeighbor))
      throw new IllegalArgumentException("Expect AgglomerativeNeighbor not " + neighbor.getClass().getName());
  int[][] oldIndices = ((AgglomerativeNeighbor)neighbor).getOldClusters();
  int[] mergedIndices=((AgglomerativeNeighbor)neighbor).getNewCluster();

  Clustering original = neighbor.getOriginal();

  result[0]=getCentroid(oldIndices[0],original);
  result[1]=getCentroid(oldIndices[1],original);
  if(singleLink) //scores a cluster based on link between medoid of each cluster
      {
View Full Code Here

 
  public void run () {
    Alphabet alphabet = dictOfSize(20);
   
    // TRAIN
    Clustering training = sampleClustering(alphabet);   
    Pipe clusterPipe = new OverlappingFeaturePipe();
    System.err.println("Training with " + training);
    InstanceList trainList = new InstanceList(clusterPipe);
    trainList.addThruPipe(new ClusterSampleIterator(training, random, 0.5, 100));
    System.err.println("Created " + trainList.size() + " instances.");
    Classifier me = new MaxEntTrainer().train(trainList);
    ClassifyingNeighborEvaluator eval =
      new ClassifyingNeighborEvaluator(me, "YES");
                                          
    Trial trial = new Trial(me, trainList);
    System.err.println(new ConfusionMatrix(trial));
    InfoGain ig = new InfoGain(trainList);
    ig.print();

//     Clusterer clusterer = new GreedyAgglomerative(training.getInstances().getPipe(),
//                                                   eval, 0.5);
    Clusterer clusterer = new GreedyAgglomerativeByDensity(training.getInstances().getPipe(),
                                                           eval, 0.5, false,
                                                           new java.util.Random(1));

    // TEST
    Clustering testing = sampleClustering(alphabet);   
    InstanceList testList = testing.getInstances();
    Clustering predictedClusters = clusterer.cluster(testList);     

    // EVALUATE
    System.err.println("\n\nEvaluating System: " + clusterer);
    ClusteringEvaluators evaluators = new ClusteringEvaluators(new ClusteringEvaluator[]{
        new BCubedEvaluator(),
View Full Code Here

    InstanceList instances =
      new InstanceList(random,
                       alph,
                       new String[]{"foo", "bar"},
                       30).subList(0, 20);
    Clustering singletons = ClusterUtils.createSingletonClustering(instances);
    // Merge instances that both have feature0
    for (int i = 0; i < instances.size(); i++) {
      FeatureVector fvi = (FeatureVector)instances.get(i).getData();
      for (int j = i + 1; j < instances.size(); j++) {
        FeatureVector fvj = (FeatureVector)instances.get(j).getData();
        if (fvi.contains("feature0") && fvj.contains("feature0")) {
          singletons = ClusterUtils.mergeClusters(singletons,
                                                  singletons.getLabel(i),
                                                  singletons.getLabel(j));
        } else if (!(fvi.contains("feature0") || fvj.contains("feature0"))
                   && random.nextUniform() < noise) {
          // Random noise.
          singletons = ClusterUtils.mergeClusters(singletons,
                                                  singletons.getLabel(i),
                                                  singletons.getLabel(j));         
        }
      }
    }
    return singletons;
  }
View Full Code Here

   */
  public static Clustering createSingletonClustering (InstanceList instances) {
    int[] labels = new int[instances.size()];
    for (int i = 0; i < labels.length; i++)
      labels[i] = i;
     return new Clustering(instances,
                          labels.length,
                          labels);
  }
View Full Code Here

                          labels);
  }

  public static Clustering createRandomClustering (InstanceList instances,
                                                   Randoms random) {
    Clustering clustering = createSingletonClustering(instances);
    int numMerges = 2 + random.nextInt(instances.size() - 2);
    for (int i = 0; i < numMerges; i++)
      clustering = mergeInstances(clustering,
                                  random.nextInt(instances.size()),
                                  random.nextInt(instances.size()));
View Full Code Here

   */
  public static Clustering copyWithNewLabels (Clustering clustering) {
    int[] oldLabels = clustering.getLabels();
    int[] newLabels = new int[oldLabels.length];
    System.arraycopy(oldLabels, 0, newLabels, 0, oldLabels.length);
    return new Clustering(clustering.getInstances(),
                          clustering.getNumClusters(),
                          newLabels);
  }
View Full Code Here

    super();
    this.evaluator = evaluator;
  }

  public double score(Clustering clustering) {
    Clustering singletons = ClusterUtils
        .createSingletonClustering(clustering.getInstances());
    double total = 0;
    int count = 0;
    for (AllPairsIterator iter = new AllPairsIterator(singletons); iter
        .hasNext(); count++) {
View Full Code Here

    super (name);
  }

  private Clustering generateTruth (InstanceList instances) {
    int[] labels = new int[]{0,0,0,0,0,1,1,2,2,2,2,2};
    return new Clustering(instances, 3, labels);
  }
View Full Code Here

    return new Clustering(instances, 3, labels);
  }
 
  private Clustering[] generatePredicted (InstanceList instances) {
    Clustering[] clusterings = new Clustering[4];
    clusterings[0] = new Clustering(instances, 2, new int[]{0,0,0,0,0,1,1,1,1,1,1,1});
    clusterings[1] = new Clustering(instances, 2, new int[]{0,0,0,0,0,1,1,0,0,0,0,0});
    clusterings[2] = new Clustering(instances, 1, new int[]{0,0,0,0,0,0,0,0,0,0,0,0});
    clusterings[3] = new Clustering(instances, 12, new int[]{0,1,2,3,4,5,6,7,8,9,10,11});
    return clusterings;
  }
View Full Code Here

TOP

Related Classes of cc.mallet.cluster.Clustering

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.