Skip to content

Instantly share code, notes, and snippets.

@Develer
Last active April 27, 2016 13:12
Show Gist options
  • Save Develer/834ef67dea2410970a5cf2f579169c0e to your computer and use it in GitHub Desktop.
Save Develer/834ef67dea2410970a5cf2f579169c0e to your computer and use it in GitHub Desktop.
// current
func (ap *AveragedPerceptron) maxScore(m map[string]float64) string {
var maxKey string
var maxVal float64 = math.SmallestNonzeroFloat64
for k, _ := range ap.Classes {
v, ok := m[k]
if !ok {
v = 0.0
}
if v > maxVal || (v == maxVal && strings.Compare(k, maxKey) > 0) {
maxKey = k
maxVal = v
}
}
return maxKey
}
// previous
func (ap *AveragedPerceptron) maxScore(m map[string]float64) string {
var maxKey string
var maxVal float64
for k, v := range m {
switch {
case v > maxVal:
maxKey = k
maxVal = v
case v == maxVal:
if k < maxKey {
maxKey = k
maxVal = v
}
}
}
return maxKey
}
// _perceptron.py
self.classes = set()
...
scores = defaultdict(float)
...
return max(self.classes, key=lambda label: (scores[label], label))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment