Exemplo n.º 1
0
                            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))

print("Parsing data ...")
Xtrain, Ytrain, Xtest = generate.get_data_set(NUM_TRAIN=2000000, NUM_TEST=10000000)
print("-------------------------------- DATA --------------------------------")
print("Number of training patterns:\t %i" % Xtrain.shape[0])
print("Number of test patterns:\t %i" % Xtest.shape[0])
print("Dimensionality of patterns:\t%i" % Xtrain.shape[1])
print("----------------------------------------------------------------------")

print("\n\nRunning the GPU version ...")
run_algorithm(algorithm="buffer_kd_tree", tree_depth=9)

print("\n\nRunning the CPU version ...")
run_algorithm(algorithm="kd_tree", leaf_size=32)

# platform dependent parameters
# (might have to be adapted!)
plat_dev_ids = {0:[0, 1, 2, 3]}
n_jobs = 8

# parameters
ofilename = "benchmark.json"
n_test_range = [1000000, 2500000, 5000000, 7500000, 10000000]
algorithms = ["brute", "kd_tree", "buffer_kd_tree"]

verbose = 0
n_neighbors = 10

print("Parsing data ...")
Xtrain, Ytrain, Xtest = generate.get_data_set(NUM_TRAIN=2000000, NUM_TEST=10000000)
print("-------------------------------- DATA --------------------------------")
print("Number of training patterns:\t %i" % Xtrain.shape[0])
print("Number of test patterns:\t %i" % Xtest.shape[0])
print("Dimensionality of patterns:\t%i" % Xtrain.shape[1])
print("----------------------------------------------------------------------")

def compute_opt_tree_depth(algorithm, n_test_tree=2000000):

    opt_tree_depth = None

    if algorithm in ["buffer_kd_tree", "kd_tree"]:

        # the different tree depths that shall
        # be tested for this data set
        if algorithm == "buffer_kd_tree":
Exemplo n.º 3
0
# 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))