Classification cpc = confidencePredictingClassifier.classify (c); LabelVector lv = c.getLabelVector(); int bestIndex = lv.getBestIndex(); double [] values = new double[lv.numLocations()]; for (int i = 0; i < lv.numLocations(); i++) { if (i != bestIndex) values[i] = 0.0; else values[i] = cpc.getLabelVector().value("correct"); 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++; 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));
public final Label labelAtLocation (int loc) { return ((LabelAlphabet)dictionary).lookupLabel(indexAtLocation (loc)); }
public Classification classify (Instance instance) { int numLabels = ensemble[0].getLabelAlphabet().size(); double[] scores = new double[numLabels]; // Run each classifier on the instance, summing each one's per-class score, with a weight for (int i = 0; i < ensemble.length; i++) { 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)); }
private double getScoreMean(LabelVector lv) { double sum = 0.0; for(int i=0; i<lv.numLocations(); i++) { sum += lv.getValueAtRank(i); } return sum / lv.numLocations(); }
/** * * @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; }
public List<RerankerResult> probabilities(List<RerankExample> ex) { Classification classify = model.classify(ex); LabelVector labeling = (LabelVector) classify.getLabeling(); List<RerankerResult> result = Lists.newArrayListWithCapacity(ex.size()); for (int i = 0; i < ex.size(); i++) { Label rankLabel = labeling.getLabelAlphabet().lookupLabel(Integer.toString(i)); result.add(new RerankerResult(ex.get(i), labeling.value(rankLabel))); } Collections.sort(result, Ordering.<RerankerResult>natural().reverse()); return result; }
PropertyList features = null; LabelVector lv = classification.getLabelVector(); Label bestLabel = lv.getBestLabel(); Instance inst = (Instance)classification.getInstance(); FeatureVector fv = (FeatureVector)inst.getData(); double secondThreshold = .03; double winningScore = lv.getValueAtRank(0); double marginOfVictory = winningScore - lv.getValueAtRank(1); features = PropertyList.add ("secondScore", lv.getValueAtRank(1), features); for(int i=0; i<lv.numLocations(); i++) { features = PropertyList.add (lv.getLabelAtRank(i).toString() +"HasValue", lv.valueAtLocation (i), features); features = PropertyList.add (bestLabel.toString() + "IsFirst-" + lv.getLabelAtRank(1).toString()+"IsSecond", 1.0, features); features = PropertyList.add ("Range", winningScore - lv.getValueAtRank(lv.numLocations()-1), features); features = PropertyList.add (bestLabel.toString()+"IsFirst", 1.0, features); features = PropertyList.add (lv.getLabelAtRank(1).toString() + "IsSecond", 1.0, features);
public void print(String prefix) int bestLabelIndex = getGainRatio().getBaseLabelDistribution().getBestIndex(); int numMajorityLabel = (int) (getGainRatio().getBaseLabelDistribution().value(bestLabelIndex) * getSize()); System.out.println("root:" + getGainRatio().getBaseLabelDistribution().getBestLabel() + " " + numMajorityLabel + "/" + getSize()); System.out.print(prefix + "\"" + featName + "\" <= " + threshold + ":"); if (m_leftChild.isLeaf()) { int bestLabelIndex = m_leftChild.getGainRatio().getBaseLabelDistribution().getBestIndex(); int numMajorityLabel = (int) (m_leftChild.getGainRatio().getBaseLabelDistribution().value(bestLabelIndex) * m_leftChild.getSize()); System.out.println(m_leftChild.getGainRatio().getBaseLabelDistribution().getBestLabel() + " " + numMajorityLabel + "/" + m_leftChild.getSize()); int bestLabelIndex = m_rightChild.getGainRatio().getBaseLabelDistribution().getBestIndex(); int numMajorityLabel = (int) (m_rightChild.getGainRatio().getBaseLabelDistribution().value(bestLabelIndex) * m_rightChild.getSize()); System.out.println(m_rightChild.getGainRatio().getBaseLabelDistribution().getBestLabel() + " " + numMajorityLabel + "/" + m_rightChild.getSize());
Label expected = targetSeq.getLabelAtPosition(j); FeatureVector fv = fvs.get(j); for (int ll = 0; ll < predicated.numLocations(); ll++) { int li = predicated.indexAtLocation(ll); double[] toUpdate = (expected.getBestIndex() == li ? pos : neg); double expectedWeight = (expected.getBestIndex() == li ? 1.0 : 0.0); double predWeight = predicated.value(li); double labelWeightDiff = Math.abs(expectedWeight - predWeight); synchronized (count) {
public void testValue () { assertEquals (4.0, lv.value (ld.lookupLabel ("b")), 1e-5); }
public LabelVector toLabelVector () { return new LabelVector ((LabelAlphabet)dictionary, new int[] {index}, new double[] {weightOfLabel}); }
public Label getBestLabel () { return ((LabelAlphabet)dictionary).lookupLabel (getBestIndex()); }
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; return(toReturn); }
public RankedFeatureVector newRankedFeatureVector (InstanceList ilist) { assert (ilist.getTargetAlphabet() == classifications[0].getAlphabet()); return new ExpGain (ilist, classifications, gaussianPriorVariance); }
private double[][] optimizeQ(InstanceList data, Classifier p, boolean firstIter) { int numLabels = data.getTargetAlphabet().size(); double[][] base; if (firstIter) { base = null; } else { base = new double[data.size()][numLabels]; for (int ii = 0; ii < data.size(); ii++) { p.classify(data.get(ii)).getLabelVector().addTo(base[ii]); } } PRAuxClassifierOptimizable optimizable = new PRAuxClassifierOptimizable(data,base,q); LimitedMemoryBFGS bfgs = new LimitedMemoryBFGS(optimizable); try { bfgs.optimize(); } catch (Exception e) { e.printStackTrace(); } bfgs.reset(); try { bfgs.optimize(); } catch (Exception e) { e.printStackTrace(); } return base; } }
public void testGetBestLabel () { assertTrue (lv.getBestLabel() == ld.lookupLabel ("b")); }
PropertyList features = null; LabelVector lv = classification.getLabelVector(); Label bestLabel = lv.getBestLabel(); Instance inst = (Instance)classification.getInstance(); FeatureVector fv = (FeatureVector)inst.getData(); double secondThreshold = .03; double winningScore = lv.getValueAtRank(0); double marginOfVictory = winningScore - lv.getValueAtRank(1); features = PropertyList.add ("secondScore", lv.getValueAtRank(1), features); for(int i=0; i<lv.numLocations(); i++) { features = PropertyList.add (lv.getLabelAtRank(i).toString() +"HasValue", lv.valueAtLocation (i), features); features = PropertyList.add (bestLabel.toString() + "IsFirst-" + lv.getLabelAtRank(1).toString()+"IsSecond", 1.0, features); features = PropertyList.add ("Range", winningScore - lv.getValueAtRank(lv.numLocations()-1), features); features = PropertyList.add (bestLabel.toString()+"IsFirst", 1.0, features); features = PropertyList.add (lv.getLabelAtRank(1).toString() + "IsSecond", 1.0, features);
assert (classifications[i].getLabelAlphabet() == ilist.getTargetAlphabet()); Instance inst = ilist.get(i); Labeling labeling = inst.getLabeling (); for (int li = 0; li < numClasses; li++) { double trueLabelWeight = labeling.value (li); double modelLabelWeight = classifications[i].value(li); trueLabelWeightSum += trueLabelWeight; modelLabelWeightSum += modelLabelWeight; assert (classifications[i].getLabelAlphabet() == ilist.getTargetAlphabet()); Instance inst = ilist.get(i); Labeling labeling = inst.getLabeling (); fli = fv.indexAtLocation(fl); for (int li = 0; li < numClasses; li++) { double modelLabelWeight = classifications[i].value(li); double expalpha = Math.exp (alphas[li][fli]); double numerator = modelLabelWeight * expalpha; assert (classifications[i].getLabelAlphabet() == ilist.getTargetAlphabet()); Instance inst = ilist.get(i); Labeling labeling = inst.getLabeling (); int fvMaxLocation = fv.numLocations()-1; for (int li = 0; li < numClasses; li++) { double modelLabelWeight = classifications[i].value(li);
public void print(String prefix) int bestLabelIndex = getGainRatio().getBaseLabelDistribution().getBestIndex(); int numMajorityLabel = (int) (getGainRatio().getBaseLabelDistribution().value(bestLabelIndex) * getSize()); System.out.println("root:" + getGainRatio().getBaseLabelDistribution().getBestLabel() + " " + numMajorityLabel + "/" + getSize()); System.out.print(prefix + "\"" + featName + "\" <= " + threshold + ":"); if (m_leftChild.isLeaf()) { int bestLabelIndex = m_leftChild.getGainRatio().getBaseLabelDistribution().getBestIndex(); int numMajorityLabel = (int) (m_leftChild.getGainRatio().getBaseLabelDistribution().value(bestLabelIndex) * m_leftChild.getSize()); System.out.println(m_leftChild.getGainRatio().getBaseLabelDistribution().getBestLabel() + " " + numMajorityLabel + "/" + m_leftChild.getSize()); int bestLabelIndex = m_rightChild.getGainRatio().getBaseLabelDistribution().getBestIndex(); int numMajorityLabel = (int) (m_rightChild.getGainRatio().getBaseLabelDistribution().value(bestLabelIndex) * m_rightChild.getSize()); System.out.println(m_rightChild.getGainRatio().getBaseLabelDistribution().getBestLabel() + " " + numMajorityLabel + "/" + m_rightChild.getSize());
/** * * @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; }