Skip to content

Commit

Permalink
return num of neighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Oct 10, 2024
1 parent 4b9460d commit d1f33b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lsh/model_wide.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (me *WideModel) Predict1Alloc(k int, x []uint64, votes bitknn.Votes) int {
// Predict1Into predicts the label for a single input using the given slices (of length [k]+1 each) for the neighbor heaps.
func (me *WideModel) Predict1Into(k int, x []uint64, votes bitknn.Votes, bucketDistances []int, bucketIDs []uint64, distances []int, indices []int) int {
xp := me.Hash.Hash1Wide(x)
k, n := NearestWide(me.WideData, me.BucketIDs, me.Buckets, k, xp, x, bucketDistances, bucketIDs, distances, indices)
me.WideModel.Narrow.Vote(k, distances, indices, votes)
return n
k0, _ := NearestWide(me.WideData, me.BucketIDs, me.Buckets, k, xp, x, bucketDistances, bucketIDs, distances, indices)
me.WideModel.Narrow.Vote(k0, distances, indices, votes)
return k0
}
9 changes: 6 additions & 3 deletions model_wide.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ func (me *WideModel) PreallocateHeap(k int) {
}

// Predicts the label of a single input point. Reuses two slices of length K+1 for the neighbor heap.
func (me *WideModel) Predict1(k int, x []uint64, votes Votes) {
// Returns the number of neighbors found.
func (me *WideModel) Predict1(k int, x []uint64, votes Votes) int {
me.Narrow.PreallocateHeap(k)
me.Predict1Into(k, x, me.Narrow.HeapDistances, me.Narrow.HeapIndices, votes)
return me.Predict1Into(k, x, me.Narrow.HeapDistances, me.Narrow.HeapIndices, votes)
}

// Predicts the label of a single input point, using the given slices for the neighbor heap.
func (me *WideModel) Predict1Into(k int, x []uint64, distances []int, indices []int, votes Votes) {
// Returns the number of neighbors found.
func (me *WideModel) Predict1Into(k int, x []uint64, distances []int, indices []int, votes Votes) int {
k = NearestWide(me.WideData, k, x, distances, indices)
me.Narrow.Vote(k, distances, indices, votes)
return k
}

0 comments on commit d1f33b3

Please sign in to comment.