Skip to content

Instantly share code, notes, and snippets.

@smidm
Created February 28, 2019 14:43
Show Gist options
  • Save smidm/4099993e46e2802bb3bd78f5ffb1f33d to your computer and use it in GitHub Desktop.
Save smidm/4099993e46e2802bb3bd78f5ffb1f33d to your computer and use it in GitHub Desktop.
test returned flann distance
from pyflann import *
import numpy as np
dataset = np.array(
[[1., 1, 1, 2, 3],
[10, 10, 10, 3, 2],
[100, 100, 2, 30, 1]
])
testset = np.array(
[[1., 1, 1, 1, 1],
[90, 90, 10, 10, 1]
])
flann = FLANN()
result, dists = flann.nn(
dataset, testset, 1, algorithm="kmeans", branching=32, iterations=7, checks=16)
print('results: {}'.format(result))
print('dists: {}'.format(dists))
print('((testset[0] - dataset[0])**2).sum(): {}'.format(((testset[0] - dataset[0])**2).sum()))
print('((testset[1] - dataset[2])**2).sum(): {}'.format(((testset[1] - dataset[2])**2).sum()))
# output
# results: [0 2]
# dists: [ 5. 664.]
# ((testset[0] - dataset[0])**2).sum(): 5.0
# ((testset[1] - dataset[2])**2).sum(): 664.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment