Package cc.mallet.types

Examples of cc.mallet.types.InstanceList$NotYetSetPipe


                          clustering.getNumClusters(),
                          newLabels);
  }
 
  public static Clustering mergeInstancesWithSameLabel (Clustering clustering) {
    InstanceList list = clustering.getInstances();
    for (int i = 0; i < list.size(); i++) {
      Instance ii = list.get(i);
      int li = clustering.getLabel(i);
      for (int j = i + 1; j < list.size(); j++) {
        Instance ij = list.get(j);
        int lj = clustering.getLabel(j);
        if (li != lj && ii.getLabeling().equals(ij.getLabeling()))
          clustering = ClusterUtils.mergeClusters(clustering, li, lj);
      }
    } 
View Full Code Here


   
    // 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[]{
View Full Code Here

   * Sample a InstanceList and its true clustering.
   * @param alph
   * @return
   */
  private Clustering sampleClustering (Alphabet alph) {
    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"))
View Full Code Here

    return clusterings;
  }
 
  public void testEvaluators ()
  {
    InstanceList instances = new InstanceList(new Randoms(1), 100, 2).subList(0,12);
    System.err.println(instances.size() + " instances");
    Clustering truth = generateTruth(instances);
    System.err.println("truth=" + truth);

    Clustering[] predicted = generatePredicted(instances);
    ClusteringEvaluator pweval = new PairF1Evaluator();
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) {
            FeatureVector fvi = (FeatureVector)list.get(mergedIndices[i]).getData();
            FeatureVector fvj = (FeatureVector)list.get(mergedIndices[j]).getData();
            if (!(fvi.contains("feature0") && fvj.contains("feature0"))) {
              match = false;
              break;             
            }
          }
View Full Code Here

    /** Returns the <code>Instance</code> at the specified index. If
     * this Instance is not in memory, swap a block of instances back
     * into memory. */
    public Instance get (int index) {
        InstanceList page = getPageForIndex (index, false);
        return page.get (index % this.instancesPerPage);
    }
View Full Code Here

    /** Replaces the <code>Instance</code> at position
     * <code>index</code> with a new one. Note that this is the only
     * sanctioned way of changing an Instance. */
    public Instance set (int index, Instance instance) {
        InstanceList page = getPageForIndex (index, true);
        return page.set (index % this.instancesPerPage, instance);
    }
View Full Code Here

        this.collectGarbage = b;
   
    }

    public InstanceList shallowClone () {
        InstanceList ret = this.cloneEmpty ();
        for (int i = 0; i < this.size (); i++) {
            ret.add (get (i));
        }
        return ret;
    }
View Full Code Here

     * @throws IOException
     * @throws ClassNotFoundException
     */
    private InstanceList deserializePage(ObjectInputStream in)
    throws IOException, ClassNotFoundException {
        InstanceList page = new InstanceList(noopPipe);
        int size = in.readInt();
       
        for (int i = 0; i < size; i++) {
            Object data = deserializeObject (in);
            Object target = deserializeObject (in);
            Object name = in.readObject ();
            Object source = in.readObject ();
            double weight = in.readDouble ();
            page.add (new Instance (data, target, name, source), weight);
        }
       
        return page;
    }
View Full Code Here

   {
     Pipe pipe = TestMEMM.makeSpacePredictionPipe ();
     String[] data0 = { TestCRF.data[0] };
     String[] data1 = { TestCRF.data[1] };

     InstanceList training = new InstanceList (pipe);
     training.addThruPipe (new ArrayIterator (data0));
     InstanceList testing = new InstanceList (pipe);
     testing.addThruPipe (new ArrayIterator (data1));

     CRF crf = new CRF (pipe, null);
     crf.addFullyConnectedStatesForLabels ();
     CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf);
     crft.trainIncremental (training);
View Full Code Here

TOP

Related Classes of cc.mallet.types.InstanceList$NotYetSetPipe

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.