Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kth nearest neighbor needs a fivebox #6

Open
timm opened this issue Nov 4, 2015 · 0 comments
Open

kth nearest neighbor needs a fivebox #6

timm opened this issue Nov 4, 2015 · 0 comments

Comments

@timm
Copy link
Contributor

timm commented Nov 4, 2015

could do better than this with a bin search that ignores top items

class nlist:
  def __init__(i,n=5,inits=[]):
     i.n, i.all,ordered = n,[],False
     map(i.add, inits)
  def add(i,x):
     if len(i.all) < i.n: 
         i.all += [x]
         if len(i.all) == n:
            i.all = sorted(i.all)
     elif x < i.all[-1]:  
         i.all += [x]
         i.all = sorted(i.all)[:n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant