Last active
April 27, 2016 13:12
-
-
Save Develer/834ef67dea2410970a5cf2f579169c0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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