Package cc.mallet.cluster.neighbor_evaluator

Examples of cc.mallet.cluster.neighbor_evaluator.AgglomerativeNeighbor


  public boolean hasNext () {
    return i < instances.size() - 1;
  }

  public Instance next () {
    AgglomerativeNeighbor neighbor =
      new AgglomerativeNeighbor(clustering,
                                ClusterUtils.copyAndMergeInstances(clustering,
                                                                   i, j),
                                i, j);
    // Increment.
    if (j + 1 == instances.size()) {
View Full Code Here


  public boolean hasNext () {
      return totalCount < numberSamples;
  }

  public Instance next () {
    AgglomerativeNeighbor neighbor = null;
   
    if (nonsingletonClusters.length>0 && positiveCount < positiveTarget || clustering.getNumClusters() == 1)) { //mmwick modified
      positiveCount++;
      int label = nonsingletonClusters[random.nextInt(nonsingletonClusters.length)];
      int[] instances = clustering.getIndicesWithLabel(label);
      int ii = instances[random.nextInt(instances.length)];
      int ij = instances[random.nextInt(instances.length)];
      while (ii == ij)
        ij = instances[random.nextInt(instances.length)];
      neighbor = new AgglomerativeNeighbor(clustering,
                                           clustering,
                                           ii, ij);     
    } else {
      int ii = random.nextInt(instances.size());
      int ij = random.nextInt(instances.size());
      while (clustering.getLabel(ii) == clustering.getLabel(ij))
        ij = random.nextInt(instances.size());
      neighbor =
        new AgglomerativeNeighbor(clustering,
                                  ClusterUtils.copyAndMergeInstances(clustering,
                                                                     ii, ij),
                                  ii, ij);       
    }
    totalCount++;
View Full Code Here

    this.positiveProportion=positiveProportion;
    this.numberSamples=numberSamples;
  }
 
  public Instance next () {
    AgglomerativeNeighbor neighbor = null;
   
    if (positiveCount < positiveTarget && nonsingletonClusters.length>0){ // Sample positive.
      positiveCount++;
      int label = nonsingletonClusters[random.nextInt(nonsingletonClusters.length)];
     
      int[] instances = clustering.getIndicesWithLabel(label);
      int[] subcluster = sampleFromArray(instances, random, 2);
      int[] cluster1 = new int[]{subcluster[random.nextInt(subcluster.length)]}; // Singleton.
      int[] cluster2 = new int[subcluster.length - 1];
      int nadded = 0;
      for (int i = 0; i < subcluster.length; i++)
        if (subcluster[i] != cluster1[0])
          cluster2[nadded++] = subcluster[i];
     
      neighbor = new AgglomerativeNeighbor(clustering,
                                           clustering,
                                           cluster1,
                                           cluster2);     
    } else { // Sample negative.
      int labeli = random.nextInt(clustering.getNumClusters());
      int labelj = random.nextInt(clustering.getNumClusters());
      while (labeli == labelj)
        labelj = random.nextInt(clustering.getNumClusters());

      int[] ii = sampleFromArray(clustering.getIndicesWithLabel(labeli), random, 1);
      int[] ij = sampleFromArray(clustering.getIndicesWithLabel(labelj), random, 1);

      neighbor =
        new AgglomerativeNeighbor(clustering,
                                  ClusterUtils.copyAndMergeClusters(clustering,
                                                                    labeli,
                                                                    labelj),
                                  ii,
                                  new int[]{ij[random.nextInt(ij.length)]});           
View Full Code Here

                                int numberSamples) {
    super(clustering, random, positiveProportion, numberSamples);
  }
 
  public Instance next () {
    AgglomerativeNeighbor neighbor = null;
   
    if ((positiveCount < positiveTarget  || clustering.getNumClusters() == 1) && nonsingletonClusters.length > 0) {
      positiveCount++;
      int label = nonsingletonClusters[random.nextInt(nonsingletonClusters.length)];

      int[] instances = clustering.getIndicesWithLabel(label);
      int[][] clusters = sampleSplitFromArray(instances, random, 2);
      neighbor = new AgglomerativeNeighbor(clustering,
                                           clustering,
                                           clusters);     
    } else {
      int labeli = random.nextInt(clustering.getNumClusters());
      int labelj = random.nextInt(clustering.getNumClusters());
      while (labeli == labelj)
        labelj = random.nextInt(clustering.getNumClusters());
      neighbor =
        new AgglomerativeNeighbor(clustering,
                                  ClusterUtils.copyAndMergeClusters(clustering,  labeli, labelj),
                                  sampleFromArray(clustering.getIndicesWithLabel(labeli), random, 1),
                                  sampleFromArray(clustering.getIndicesWithLabel(labelj), random, 1));           
    }
    totalCount++;
View Full Code Here

    int[] ci = clustering.getIndicesWithLabel(i);
    int[] cj = clustering.getIndicesWithLabel(j);
    if (scoreCache.get(ci[0], cj[0]) == 0.0) {
      double val = evaluator.evaluate(
        new AgglomerativeNeighbor(clustering,
                                  ClusterUtils.copyAndMergeClusters(clustering, i, j),
                                  ci, cj));
      for (int ni = 0; ni < ci.length; ni++)
        for (int nj = 0; nj < cj.length; nj++)
          scoreCache.set(ci[ni], cj[nj], val);
View Full Code Here

    double total = 0;
    int count = 0;
    for (AllPairsIterator iter = new AllPairsIterator(singletons); iter
        .hasNext(); count++) {
      Instance instance = (Instance) iter.next();
      AgglomerativeNeighbor neighbor = (AgglomerativeNeighbor) instance
          .getData();
      double score = evaluator.evaluate(neighbor);
      int[][] clusters = neighbor.getOldClusters();
      if (clustering.getLabel(clusters[0][0]) == clustering
          .getLabel(clusters[1][0]))
        total += score;
      else
        total += 1.0 - score;
View Full Code Here

    }
   
    public Instance pipe (Instance carrier) {
      boolean mergeFirst = false;
     
      AgglomerativeNeighbor neighbor = (AgglomerativeNeighbor)carrier.getData();
      Clustering original = neighbor.getOriginal();
      InstanceList list = original.getInstances();     
      int[] mergedIndices = neighbor.getNewCluster();
      boolean match = true;
      for (int i = 0; i < mergedIndices.length; i++) {
        for (int j = i + 1; j < mergedIndices.length; j++) {
          if ((original.getLabel(mergedIndices[i]) !=
               original.getLabel(mergedIndices[j])) || mergeFirst) {
View Full Code Here

        records.add((Record) list.get(a[i]).getData());
      return (Record[]) records.toArray(new Record[] {});
    }

    public Instance pipe(Instance carrier) {
      AgglomerativeNeighbor neighbor = (AgglomerativeNeighbor) carrier
          .getData();
      Clustering original = neighbor.getOriginal();
      int[] cluster1 = neighbor.getOldClusters()[0];
      int[] cluster2 = neighbor.getOldClusters()[1];
      InstanceList list = original.getInstances();
      int[] mergedIndices = neighbor.getNewCluster();
      Record[] records = array2Records(mergedIndices, list);
      Alphabet fieldAlph = records[0].fieldAlphabet();
      Alphabet valueAlph = records[0].valueAlphabet();

      PropertyList features = null;
View Full Code Here

TOP

Related Classes of cc.mallet.cluster.neighbor_evaluator.AgglomerativeNeighbor

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.