Package cc.mallet.types

Examples of cc.mallet.types.FeatureSequence


    double unlabeledWeight, labeledWeight, weight;
    for (int ii = batchAssignments[0]; ii < batchAssignments[1]; ii++) {
      Instance instance = trainingSet.get(ii);
      double instanceWeight = trainingSet.getInstanceWeight(instance);
      FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();

      labeledWeight = new SumLatticeDefault (this.crf, input, output, null).getTotalWeight();
      if (Double.isInfinite (labeledWeight)) {
        ++numInfLabeledWeight;
      }
View Full Code Here


    assert (constraints.structureMatches(crf.parameters));
    constraints.zero();

    for (Instance instance : ilist) {
      FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      double instanceWeight = ilist.getInstanceWeight(instance);
      //System.out.println ("Constraint-gathering on instance "+i+" of "+ilist.size());
      Transducer.Incrementor incrementor = instanceWeight == 1.0 ? constraints.new Incrementor() : constraints.new WeightedIncrementor(instanceWeight);
      new SumLatticeDefault (this.crf, input, output, incrementor);
    }
View Full Code Here

    double unlabeledWeight, labeledWeight, weight;
    for (int ii = 0; ii < trainingSet.size(); ii++) {
      Instance instance = trainingSet.get(ii);
      double instanceWeight = trainingSet.getInstanceWeight(instance);
      FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      labeledWeight = new SumLatticeDefault (this.crf, input, output, (Transducer.Incrementor)null).getTotalWeight();
      String instanceName = instance.getName() == null ? "instance#"+ii : instance.getName().toString();
      //System.out.println ("labeledWeight = "+labeledWeight);
      if (Double.isInfinite (labeledWeight)) {
        ++numInfLabeledWeight;
View Full Code Here

  }
 
  public Instance pipe (Instance carrier)
  {
    TokenSequence ts = (TokenSequence) carrier.getData();
    FeatureSequence ret =
      new FeatureSequence ((Alphabet)getDataAlphabet(), ts.size());
    for (int i = 0; i < ts.size(); i++) {
      ret.add (ts.get(i).getText());
    }
    carrier.setData(ret);
    return carrier;
  }
View Full Code Here

 
  public void testEstimating ()
  {
    Alphabet dict = new Alphabet ();
    Multinomial.Estimator e = new Multinomial.LaplaceEstimator (dict);
    FeatureSequence fs = new FeatureSequence (dict);
    fs.add (dict.lookupIndex ("a"));
    fs.add (dict.lookupIndex ("n"));
    fs.add (dict.lookupIndex ("d"));
    fs.add (dict.lookupIndex ("r"));
    fs.add (dict.lookupIndex ("e"));
    fs.add (dict.lookupIndex ("w"));
    fs.add (dict.lookupIndex ("m"));
    fs.add (dict.lookupIndex ("c"));
    fs.add (dict.lookupIndex ("c"));
    fs.add (dict.lookupIndex ("a"));
    fs.add (dict.lookupIndex ("l"));
    fs.add (dict.lookupIndex ("l"));
    fs.add (dict.lookupIndex ("u"));
    fs.add (dict.lookupIndex ("m"));
    //System.out.println (fs.toString());
    e.increment (fs);
    assertTrue (e.size() == 10);

    Multinomial m = e.estimate ();
View Full Code Here

    }

    public Instance pipe(Instance carrier) {
      TokenSequence ts = (TokenSequence) carrier.getData();
      TokenSequence newTs = new TokenSequence();
      FeatureSequence labelSeq = new FeatureSequence(getTargetAlphabet());
      boolean lastWasSpace = true;
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < ts.size(); i++) {
        Token t = ts.get(i);
        if (t.getText().equals(" "))
          lastWasSpace = true;
        else {
          sb.append(t.getText());
          newTs.add(t);
          labelSeq.add(lastWasSpace ? "start" : "notstart");
          lastWasSpace = false;
        }
      }
      if (isTargetProcessing())
        carrier.setTarget(labelSeq);
View Full Code Here

    
     this.instances=instances;
     numDocuments=instances.size();
     numTypes=instances.getDataAlphabet().size();
    
     FeatureSequence fs;
     for(int i=0;i<numDocuments ; i++){
       fs =(FeatureSequence) instances.get(i).getData();
       totalWord+=fs.getLength();
     }
    
     /*initialize algorithm parameter*/
     init();
    
View Full Code Here

     nmk = new ArrayList[numDocuments];
     nkt = new ArrayList<int[]>();
     nk = new ArrayList<Integer>();
     z = new int[numDocuments][];
    
     FeatureSequence fs;
     for(int m=0; m < numDocuments; m++){
       nmk[m] = new ArrayList<Integer>();
      
       for(int k=0; k<K ; k++){
         nmk[m].add(0);
       }
       fs =(FeatureSequence) instances.get(m).getData();
       z[m]= new int[fs.getLength()];
     }
    
     /*topic index*/
     kgaps = new ArrayList<Integer>();
     kactive = new ArrayList<Integer>();
View Full Code Here

       pp[kk] = 1.0/K;
     }
    
     for(int m=0 ; m < numDocuments ; m++){    
      
       FeatureSequence fs = (FeatureSequence) instances.get(m).getData();
       int seqLen = fs.getLength();
       int type, token, k;
       double sum;
      
       for(token=0 ; token < seqLen ; token++){
        
         type = fs.getIndexAtPosition(token);
        
         int u = rand.nextInt(K);
         //assign topics
         k = kactive.get(u);
         z[m][token]=k;
View Full Code Here

     }
   }
  
   private void updateDocs(int m) {
    
     FeatureSequence fs = (FeatureSequence) instances.get(m).getData();
     int seqLen = fs.getLength();
     int type, token;
     double sum;
    
     for(token=0 ; token < seqLen ; token++){
      
       type = fs.getIndexAtPosition(token);
       int k, kold = -1;
      
       if(initialized){
         //get old topic
         k=z[m][token];
View Full Code Here

TOP

Related Classes of cc.mallet.types.FeatureSequence

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.