Package cc.mallet.types

Examples of cc.mallet.types.LabelVector


     *
     * @param trial Trial results to add to ROC data
     */
    public void add(Classification classification) {
        int correctIndex = classification.getInstance().getLabeling().getBestIndex();
        LabelVector lv = classification.getLabelVector();
        double[] values = lv.getValues();
       
        if (!Alphabet.alphabetsMatch(this, lv)) {
            throw new IllegalArgumentException ("Alphabets do not match");
        }
       
View Full Code Here


   * @param neighbors
   * @return An array containing a score for each of the elements of <code>neighbors</code>.
   */
  public double[] evaluate (Neighbor[] neighbors) {
    double[] scores = new double[neighbors.length];
    LabelVector ranks = classifier.classify(neighbors).getLabelVector();
    for (int i = 0; i < ranks.numLocations(); i++) {
      int idx = ((Integer)ranks.getLabelAtRank(i).getEntry()).intValue();
      scores[idx] = ranks.getValueAtRank(i);
    }
    return scores;
  }
View Full Code Here

    FeatureVector[] fva = new FeatureVector[fvs.size()];

    for (int i = 0; i < ilist.size(); i++) {
      Instance inst = ilist.get(i);
      Classification c = m_tokenClassifiers.classify(inst, ! m_inProduction);
      LabelVector lv = c.getLabelVector();
      AugmentableFeatureVector afv1 = (AugmentableFeatureVector) inst.getData();
      int[] indices = afv1.getIndices();
      AugmentableFeatureVector afv2 = new AugmentableFeatureVector(m_dataAlphabet,
          indices, afv1.getValues(), indices.length + m_predRanks2add.length);

      for (int j = 0; j < m_predRanks2add.length; j++) {
        Label label = lv.getLabelAtRank(m_predRanks2add[j]);
        int idx = m_dataAlphabet.lookupIndex("TOK_PRED=" + label.toString() + "_@_RANK_" + m_predRanks2add[j]);

        assert(idx >= 0);
        afv2.add(idx, 1);
      }
View Full Code Here

  private LabelVector lv;

  protected void setUp ()
  {
    ld = new LabelAlphabet ();
    lv = new LabelVector (ld,
                          new int[] {
                            ld.lookupIndex ("a"),
                            ld.lookupIndex ("b"),
                            ld.lookupIndex ("c"),
                            ld.lookupIndex ("d")},
View Full Code Here

      }
    if (outputAlphabet != null) {
      labelings = new LabelVector[latticeLength];
      for (int ip = latticeLength-2; ip >= 0; ip--) {
        assert (Math.abs(1.0-MatrixOps.sum (outputCounts[ip])) < 0.000001);;
        labelings[ip] = new LabelVector (outputAlphabet, outputCounts[ip]);
      }
    }
  }
View Full Code Here

  }
  public class ClassificationComparator implements Comparator
  {
    public final int compare (Object a, Object b)
    {
      LabelVector x = (LabelVector) (((Classification)a).getLabelVector());
      LabelVector y = (LabelVector) (((Classification)b).getLabelVector());
      double difference = x.getBestValue() - y.getBestValue();
      int toReturn = 0;
      if(difference > 0)
        toReturn = 1;
      else if (difference < 0)
        toReturn = -1;
View Full Code Here

      ((Classification)classifications.get(0)).getLabeling();
    this.numClasses = tempLabeling.getLabelAlphabet().size();
    values = new int[numClasses][numClasses];
    for(int i=0; i < classifications.size(); i++)
    {
      LabelVector lv =
        ((Classification)classifications.get(i)).getLabelVector();
      Instance inst = ((Classification)classifications.get(i)).getInstance();
      int bestIndex = lv.getBestIndex();
      int correctIndex = inst.getLabeling().getBestIndex();
      assert(correctIndex != -1);
      //System.out.println("Best index="+bestIndex+". Correct="+correctIndex);
      values[correctIndex][bestIndex]++;
    }     
View Full Code Here

    }
   
   
    // Create and return a Classification object
    return new Classification (instance, this,
                               new LabelVector (getLabelAlphabet(),
                                                scores));
  }   
View Full Code Here

  public Classification classify (Instance instance)
  {
    Classification c = underlyingClassifier.classify (instance);
    Classification cpc = confidencePredictingClassifier.classify (c);
    LabelVector lv = c.getLabelVector();
    int bestIndex = lv.getBestIndex();
    double [] values = new double[lv.numLocations()];
    //// Put score of "correct" into score of the winning class...
    // xxx Can't set lv - it's immutable.
    //     Must create copy and new classification object
    // lv.set (bestIndex, cpc.getLabelVector().value("correct"));
    //for (int i = 0; i < lv.numLocations(); i++)
    //  if (i != bestIndex)
    //    lv.set (i, 0.0);

    // Put score of "correct" in winning class and
    // set rest to 0
    for (int i = 0; i < lv.numLocations(); i++) {
      if (i != bestIndex)
        values[i] = 0.0;
      else values[i] = cpc.getLabelVector().value("correct");
    }
    //return c;
   
    if(c.bestLabelIsCorrect()){
      numCorrectInstances++;
      totalCorrect+=cpc.getLabelVector().value("correct");
      totalIncorrectCorrect+=cpc.getLabelVector().value("incorrect");
      String correct = new String("correct");
      if(correct.equals(cpc.getLabelVector().getBestLabel().toString()))
        numConfidenceCorrect++;
      else numFalseNegative++;
    }
   
    else{
      numIncorrectInstances++;
      totalIncorrect+=cpc.getLabelVector().value("correct");
      totalIncorrectIncorrect+=cpc.getLabelVector().value("incorrect");
      if((new String("incorrect")).equals(cpc.getLabelVector().getBestLabel().toString()))
        numConfidenceCorrect++;
      else numFalsePositive++;
    }
   
    return new Classification(instance, this, new LabelVector(lv.getLabelAlphabet(), values));
//    return cpc;
  }
View Full Code Here

      Classification c = ensemble[i].classify(instance);
      c.getLabelVector().addTo(scores, weights[i]);
    }
    // Exponentiate and normalize scores
    expNormalize (scores);
    return new Classification (instance, this, new LabelVector (ensemble[0].getLabelAlphabet(), scores));
  }
View Full Code Here

TOP

Related Classes of cc.mallet.types.LabelVector

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.