/// <summary> /// Returns a counter for the log probability of each of the classes /// looking at the the sum of e^v for each count v, should be 1 /// Note: Uses SloppyMath.logSum which isn't exact but isn't as /// offensively slow as doing a series of exponentials /// </summary> public override ICounter <L> LogProbabilityOf(IDatum <L, F> example) { if (platt == null) { throw new NotSupportedException("If you want to ask for the probability, you must train a Platt model!"); } ICounter <L> scores = ScoresOf(example); scores.IncrementCount(null); ICounter <L> probs = platt.LogProbabilityOf(new RVFDatum <L, L>(scores)); //System.out.println(scores+" "+probs); return(probs); }
private void EnsureProbs(int word, bool subtractTagScore) { if (word == lastWord) { return; } lastWord = word; if (functionWordTags.Contains(wordIndex.Get(word))) { logProbs = new ClassicCounter <string>(); string trueTag = functionWordTags[wordIndex.Get(word)]; foreach (string tag in tagIndex.ObjectsList()) { if (ctlp.BasicCategory(tag).Equals(trueTag)) { logProbs.SetCount(tag, 0); } else { logProbs.SetCount(tag, double.NegativeInfinity); } } return; } IDatum datum = new BasicDatum(featExtractor.MakeFeatures(wordIndex.Get(word))); logProbs = scorer.LogProbabilityOf(datum); if (subtractTagScore) { ICollection <string> tagSet = logProbs.KeySet(); foreach (string tag in tagSet) { logProbs.IncrementCount(tag, -Math.Log(tagDist.ProbabilityOf(tag))); } } }