Various improvements
This commit is contained in:
parent
c2997ff3a1
commit
474d02ebcb
16
util.go
16
util.go
@ -58,9 +58,9 @@ func innerProduct(features1 featureMap, features2 featureMap) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func walkMatches(entries records, features featureMap, minScore float64, callback func(record, float64)) {
|
func walkMatches(entries records, features featureMap, minScore float64, callback func(record, float64)) {
|
||||||
for _, record := range entries {
|
for _, entry := range entries {
|
||||||
if score := innerProduct(features, record.features); score >= minScore {
|
if score := innerProduct(features, entry.features); score >= minScore {
|
||||||
callback(record, score)
|
callback(entry, score)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,8 +69,8 @@ func statRecords(entries records, features featureMap, minScore float64) (float6
|
|||||||
var compatibility float64
|
var compatibility float64
|
||||||
var count int
|
var count int
|
||||||
|
|
||||||
walkMatches(entries, features, minScore, func(record record, score float64) {
|
walkMatches(entries, features, minScore, func(entry record, score float64) {
|
||||||
compatibility += record.compatibility
|
compatibility += entry.compatibility
|
||||||
count++
|
count++
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -92,9 +92,9 @@ func stepRange(min, max float64, steps int, callback func(float64)) {
|
|||||||
func findRecords(entries records, features featureMap, minScore float64) records {
|
func findRecords(entries records, features featureMap, minScore float64) records {
|
||||||
var foundEntries records
|
var foundEntries records
|
||||||
|
|
||||||
walkMatches(entries, features, minScore, func(record record, score float64) {
|
walkMatches(entries, features, minScore, func(entry record, score float64) {
|
||||||
record.score = score
|
entry.score = score
|
||||||
foundEntries = append(foundEntries, record)
|
foundEntries = append(foundEntries, entry)
|
||||||
})
|
})
|
||||||
|
|
||||||
sort.Sort(foundEntries)
|
sort.Sort(foundEntries)
|
||||||
|
Loading…
Reference in New Issue
Block a user