def run_algorithm(algorithm="buffer_kd_tree", tree_depth=None, leaf_size=None): nbrs = NearestNeighbors(n_neighbors=n_neighbors, \ algorithm=algorithm, \ tree_depth=tree_depth, \ leaf_size=leaf_size, \ float_type=float_type, \ n_jobs=n_jobs, \ plat_dev_ids=plat_dev_ids, \ verbose=verbose) start_time = time.time() nbrs.fit(Xtrain) end_time = time.time() print("Fitting time: %f" % (end_time - start_time)) start_time = time.time() dists, inds = nbrs.kneighbors(Xtest) end_time = time.time() print("Testing time: %f" % (end_time - start_time))
def run_algorithm(algorithm="buffer_kd_tree", tree_depth=None, leaf_size=None): nbrs = NearestNeighbors(n_neighbors=n_neighbors, algorithm=algorithm, tree_depth=tree_depth, leaf_size=leaf_size, float_type=float_type, n_jobs=n_jobs, plat_dev_ids=plat_dev_ids, verbose=verbose) start_time = time.time() nbrs.fit(Xtrain) end_time = time.time() print("Fitting time: %f" % (end_time - start_time)) start_time = time.time() _, _ = nbrs.kneighbors(Xtest) end_time = time.time() print("Testing time: %f" % (end_time - start_time))
# Authors: Fabian Gieseke # Licence: GNU GPL (v2) import numpy from bufferkdtree import NearestNeighbors n_neighbors = 10 plat_dev_ids = {0: [0]} n_jobs = 1 verbose = 1 X = numpy.random.uniform(low=-1, high=1, size=(10000, 10)) # (1) apply buffer k-d tree implementation nbrs_buffer_kd_tree = NearestNeighbors(algorithm="buffer_kd_tree", \ tree_depth=9, \ plat_dev_ids=plat_dev_ids, \ verbose=verbose) nbrs_buffer_kd_tree.fit(X) dists, inds = nbrs_buffer_kd_tree.kneighbors(X, n_neighbors=n_neighbors) print("\nbuffer_kd_tree output\n" + str(dists[0])) # (2) apply brute-force implementation nbrs_brute = NearestNeighbors(algorithm="brute", \ plat_dev_ids=plat_dev_ids, \ verbose=verbose) nbrs_brute.fit(X) dists, inds = nbrs_brute.kneighbors(X, n_neighbors=n_neighbors) print("\nbrute output\n" + str(dists[0])) # (3) apply k-d tree mplementation nbrs_kd_tree = NearestNeighbors(algorithm="kd_tree", \
# https://github.com/gieseke/bufferkdtree/tree/master/examples import time from bufferkdtree import NearestNeighbors import generate Xtrain, Ytrain, Xtest = generate.get_data_set(data_set="psf_model_mag", NUM_TRAIN=1000000, NUM_TEST=1000000) n_jobs = 1 print("Using n_jobs=%i" % n_jobs) nbrs = NearestNeighbors(n_neighbors=10, algorithm="kd_tree", leaf_size=32, n_jobs=n_jobs) nbrs.fit(Xtrain) start_time = time.time() _, _ = nbrs.kneighbors(Xtest) end_time = time.time() print("Testing time: %f" % (end_time - start_time))
""" print(__doc__) import numpy from bufferkdtree import NearestNeighbors n_neighbors = 10 plat_dev_ids = {0:[0]} n_jobs = 1 verbose = 1 X = numpy.random.uniform(low=-1, high=1, size=(10000,10)) # (1) apply buffer k-d tree implementation nbrs_buffer_kd_tree = NearestNeighbors(algorithm="buffer_kd_tree", tree_depth=9, plat_dev_ids=plat_dev_ids, verbose=verbose) nbrs_buffer_kd_tree.fit(X) dists, inds = nbrs_buffer_kd_tree.kneighbors(X, n_neighbors=n_neighbors) print("\nbuffer_kd_tree output\n" + str(dists[0])) # (2) apply brute-force implementation nbrs_brute = NearestNeighbors(algorithm="brute", plat_dev_ids=plat_dev_ids, verbose=verbose) nbrs_brute.fit(X) dists, inds = nbrs_brute.kneighbors(X, n_neighbors=n_neighbors) print("\nbrute output\n" + str(dists[0])) # (3) apply k-d tree mplementation nbrs_kd_tree = NearestNeighbors(algorithm="kd_tree",