Package cc.mallet.types

Examples of cc.mallet.types.Instance


        double value = 0.0;
        Iterator<Instance> iter = trainingList.iterator();
        int ii=0;       
        while (iter.hasNext()) {
          ii++;
          Instance instance = iter.next();
          FeatureVectorSequence fvs = (FeatureVectorSequence) instance.getData();
          // scores stores Pr of subList[i] being positive instance
          double[] scores = new double[fvs.size()];
          double instanceWeight = trainingList.getInstanceWeight(instance);

          // labeling is a String representation of an int, indicating which FeatureVector from
          // the subList is the positive example         
         
          // If is String, proceed as usual. Else, if is String[], do
          // not penalize scores for duplicate entries. This improved accuracy in some expts.
          Object target = instance.getTarget();
          int li = -1;
          if (target instanceof Label) {
            li = Integer.valueOf(((Label)target).toString()).intValue();
            if (li == -1) // hack to avoid invalid instances
              continue;
            assert (li >=0 && li < fvs.size());
            this.theClassifier.getClassificationScores (instance, scores);
          } else if (target instanceof Labels){
            Labels labels = (Labels)target;
            int[] bestPositions = new int[labels.size()];
            for (int pi = 0; pi < labels.size(); pi++)
              bestPositions[pi] = Integer.valueOf(labels.get(pi).toString());
            li = bestPositions[0];
            this.theClassifier.getClassificationScoresForTies (instance, scores, bestPositions);             
          }
          value = - (instanceWeight * Math.log (scores[li]));
          if(Double.isNaN(value)) {
            logger.fine ("MaxEntTrainer: Instance " + instance.getName() +
                         "has NaN value. log(scores)= " + Math.log(scores[li]) +
                         " scores = " + scores[li] +
                         " has instance weight = " + instanceWeight);
           
          }
          if (Double.isInfinite(value)) {
            logger.warning ("Instance "+instance.getSource() + " has infinite value; skipping value and gradient");
            cachedValue -= value;
            cachedValueStale = false;
            return -value;
          }
          cachedValue += value;
View Full Code Here


            lprobs[si][fi] = Math.log(probs[si][fi]);
          }
        }

        while (iter.hasNext()) {
          Instance instance = iter.next();
          double instanceWeight = trainingList.getInstanceWeight(instance);
          Labeling labeling = instance.getLabeling ();
          //System.out.println("L Now "+inputAlphabet.size()+" regular features.");

          this.theClassifier.getClassificationScores (instance, scores);
          FeatureVector fv = (FeatureVector) instance.getData ();
          int li = labeling.getBestIndex();
          value = - (instanceWeight * Math.log (scores[li]));
          if(Double.isNaN(value)) {
            logger.fine ("MCMaxEntTrainer: Instance " + instance.getName() +
                         "has NaN value. log(scores)= " + Math.log(scores[li]) +
                         " scores = " + scores[li] +
                         " has instance weight = " + instanceWeight);

          }
          if (Double.isInfinite(value)) {
            logger.warning ("Instance "+instance.getSource() + " has infinite value; skipping value and gradient");
            cachedValue -= value;
            cachedValueStale = false;
            return -value;
//            continue;
          }
View Full Code Here

    lv.printByRank(pw);
    pw.println ();
  }

  public Instance toInstance() {
    Instance ret;
    FeatureVector fv;
    double[] values = new double[labeling.numLocations()];
    int[] indices = new int[labeling.numLocations()];
    for(int i = 0; i < labeling.numLocations(); i++){
      indices[i] = labeling.indexAtLocation(i);
      values[i] = labeling.valueAtLocation(i);
    }
    fv = new FeatureVector(labeling.getAlphabet(), indices, values);
    ret = new Instance(fv,null,null,instance.getSource());
    return ret;
  }
View Full Code Here

    //xxx Producing small numbers? int randomSize = r.nextPoisson (featureVectorSizePoissonLambda);
    int randomSize = (int)featureVectorSizePoissonLambda;
    FeatureVector fv = classCentroid[currentClassIndex].randomFeatureVector (r, randomSize);
    //logger.fine ("FeatureVector "+currentClassIndex+" "+currentInstanceIndex); fv.print();
    currentInstanceIndex--;
    return new Instance (fv, classNames[currentClassIndex], uri, null);
  }
View Full Code Here

  // The PipeInputIterator interface
  public Instance next ()
  {
    File nextFile = subIterator.next();
    fileCount++;
    return new Instance (nextFile, null, nextFile.toURI(), null);
  }
View Full Code Here

      if (m.find ()){
        targetName = m.group (1);
      }
    }
    fileCount++;
    return new Instance (nextFile, targetName, nextFile.toURI(), null);
  }
View Full Code Here

    return next != null;
  }

  public Instance next ()
  {
    Instance ret = (Instance)next;
    setNext();   
    return ret;
  }
View Full Code Here

    super (directory, null, targetPattern);
  }

  public Instance next ()
  {
    Instance carrier = super.next();
    carrier.setData(((File)carrier.getData()).toURI());
    return carrier;
  }
View Full Code Here

    InstanceList noMtLst = new InstanceList (noMtPipe);

    mtLst.addThruPipe (new ArrayIterator (doc1));
    noMtLst.addThruPipe (new ArrayIterator (doc1));

    Instance mtInst = mtLst.get (0);
    Instance noMtInst = noMtLst.get (0);

    TokenSequence mtTs = (TokenSequence) mtInst.getData ();
    TokenSequence noMtTs = (TokenSequence) noMtInst.getData ();

    assertEquals (6, mtTs.size ());
    assertEquals (6, noMtTs.size ());

    assertEquals (1.0, mtTs.get (3).getFeatureValue ("time"), 1e-15);
View Full Code Here

    });

    Pipe mtPipe = (Pipe) TestSerializable.cloneViaSerialization (origPipe);
    InstanceList mtLst = new InstanceList (mtPipe);
    mtLst.addThruPipe (new ArrayIterator (doc1));
    Instance mtInst = mtLst.get (0);
    TokenSequence mtTs = (TokenSequence) mtInst.getData ();
    assertEquals (6, mtTs.size ());
    assertEquals (1.0, mtTs.get (3).getFeatureValue ("time"), 1e-15);
    assertEquals (1.0, mtTs.get (4).getFeatureValue ("time"), 1e-15);
  }
View Full Code Here

TOP

Related Classes of cc.mallet.types.Instance

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.