Package cc.mallet.types

Examples of cc.mallet.types.FeatureVector


      double instanceWeight = trainingList.getInstanceWeight(inst);
      Labeling labeling = inst.getLabeling ();
      if (labeling == null)
        continue;
      //logger.fine ("Instance "+ii+" labeling="+labeling);
      FeatureVector fv = (FeatureVector) inst.getData ();
      Alphabet fdict = fv.getAlphabet();
      assert (fv.getAlphabet() == fd);
      int li = labeling.getBestIndex();
      MatrixOps.rowPlusEquals (constraints, numFeatures, li, fv, instanceWeight);
      // For the default feature, whose weight is 1.0
      assert(!Double.isNaN(instanceWeight)) : "instanceWeight is NaN";
      assert(!Double.isNaN(li)) : "bestIndex is NaN";
      boolean hasNaN = false;
      for (int i = 0; i < fv.numLocations(); i++) {
        if(Double.isNaN(fv.valueAtLocation(i))) {
          logger.info("NaN for feature " + fdict.lookupObject(fv.indexAtLocation(i)).toString());
          hasNaN = true;
        }
      }
      if (hasNaN)
        logger.info("NaN in instance: " + inst.getName());
View Full Code Here


        if (labeling == null)
          continue;
        //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 ("MaxEntTrainer: Instance " + instance.getName() +
              "has NaN value. log(scores)= " + Math.log(scores[li]) +
View Full Code Here

  public BitSet preProcess(InstanceList data) {
    // count
    int ii = 0;
    int fi;
    FeatureVector fv;
    BitSet bitSet = new BitSet(data.size());
    for (Instance instance : data) {
      double weight = data.getInstanceWeight(instance);
      fv = (FeatureVector)instance.getData();
      for (int loc = 0; loc < fv.numLocations(); loc++) {
        fi = fv.indexAtLocation(loc);
        if (constraints.containsKey(fi)) {
          if (useValues) {
            constraints.get(fi).count += weight * fv.valueAtLocation(loc);
          }
          else {
            constraints.get(fi).count += weight;
          }
          bitSet.set(ii);
View Full Code Here

  private void incorporateOneInstance (Instance instance, double instanceWeight)
  {
    Labeling labeling = instance.getLabeling ();
    if (labeling == null) return; // Handle unlabeled instances by skipping them
    FeatureVector fv = (FeatureVector) instance.getData ();
    double oneNorm = fv.oneNorm();
    if (oneNorm <= 0) return; // Skip instances that have no features present
    if (docLengthNormalization > 0)
      // Make the document have counts that sum to docLengthNormalization
      // I.e., if 20, it would be as if the document had 20 words.
      instanceWeight *= docLengthNormalization / oneNorm;
View Full Code Here

   * @return an object containing the classifier's guess
     */
  public Classification classify (Instance instance){
    int numClasses = getLabelAlphabet().size();
    double[] scores = new double[numClasses];
    FeatureVector fv = (FeatureVector) instance.getData ();
    // Make sure the feature vector's feature dictionary matches
    // what we are expecting from our data pipe (and thus our notion
    // of feature probabilities.
    assert (instancePipe == null || fv.getAlphabet () == this.instancePipe.getDataAlphabet ());
    int fvisize = fv.numLocations();
   
    // Set the scores by summing wi*xi
    for (int fvi = 0; fvi < fvisize; fvi++) {
      int fi = fv.indexAtLocation (fvi);
      for (int ci = 0; ci < numClasses; ci++)
        scores[ci] += this.weights[ci][fi];
    }
   
   
View Full Code Here

    FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
    assert (scores.length == fvs.size());
    int numFeatures = instance.getDataAlphabet().size()+1;

    for (int instanceNumber=0; instanceNumber < fvs.size(); instanceNumber++) {
      FeatureVector fv = (FeatureVector)fvs.get(instanceNumber);
      // Make sure the feature vector's feature dictionary matches
      // what we are expecting from our data pipe (and thus our notion
      // of feature probabilities.
      assert (fv.getAlphabet ()
              == this.instancePipe.getDataAlphabet ());
     
      // Include the feature weights according to each label xxx is
      // this correct ? we only calculate the dot prod of the feature
      // vector with the "positiveLabel" weights
View Full Code Here

    int numFeatures = instance.getDataAlphabet().size()+1;
    int numLabels = fvs.size();
    assert (scores.length == fvs.size());

    for (int instanceNumber=0; instanceNumber < fvs.size(); instanceNumber++) {
      FeatureVector fv = (FeatureVector)fvs.get(instanceNumber);
      // Make sure the feature vector's feature dictionary matches
      // what we are expecting from our data pipe (and thus our notion
      // of feature probabilities.
      assert (fv.getAlphabet ()
              == this.instancePipe.getDataAlphabet ());
     
      // Include the feature weights according to each label
      scores[instanceNumber] = parameters[0*numFeatures + defaultFeatureIndex]
                                 + MatrixOps.rowDotProduct (parameters, numFeatures,
View Full Code Here

  public BitSet preProcess(InstanceList data) {
    // count
    int ii = 0;
    int fi;
    FeatureVector fv;
    BitSet bitSet = new BitSet(data.size());
    for (Instance instance : data) {
      double weight = data.getInstanceWeight(instance);
      fv = (FeatureVector)instance.getData();
      for (int loc = 0; loc < fv.numLocations(); loc++) {
        fi = fv.indexAtLocation(loc);
        if (constraints.containsKey(fi)) {
          if (useValues) {
            constraints.get(fi).count += weight * fv.valueAtLocation(loc);
          }
          else {
            constraints.get(fi).count += weight;
          }
          bitSet.set(ii);
View Full Code Here

        //        int numFeatures = getAlphabet().size() + 1;
        int numFeatures = this.defaultFeatureIndex + 1;

        int numLabels = getLabelAlphabet().size();
        assert (scores.length == numLabels);
        FeatureVector fv = (FeatureVector) instance.getData ();
        // Make sure the feature vector's feature dictionary matches
        // what we are expecting from our data pipe (and thus our notion
        // of feature probabilities.
        assert (fv.getAlphabet ()
                == this.instancePipe.getDataAlphabet ());

        // Include the feature weights according to each label
        for (int li = 0; li < numLabels; li++) {
            scores[li] = parameters[li*numFeatures + defaultFeatureIndex]
View Full Code Here

    public void getClassificationScores (Instance instance, double[] scores)
    {
        int numLabels = getLabelAlphabet().size();
        assert (scores.length == numLabels);
        FeatureVector fv = (FeatureVector) instance.getData ();
        // Make sure the feature vector's feature dictionary matches
        // what we are expecting from our data pipe (and thus our notion
        // of feature probabilities.
        assert (instancePipe == null || fv.getAlphabet () == this.instancePipe.getDataAlphabet ());
        //  arrayOutOfBounds if pipe has grown since training
        //        int numFeatures = getAlphabet().size() + 1;
        int numFeatures = this.defaultFeatureIndex + 1;

        // Include the feature weights according to each label
View Full Code Here

TOP

Related Classes of cc.mallet.types.FeatureVector

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.