Skip to content

Commit

Permalink
adapted examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Gieseke committed Nov 11, 2016
1 parent 19a3fa7 commit 38d9d3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
8 changes: 3 additions & 5 deletions examples/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
n_jobs = 8

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

Expand Down Expand Up @@ -103,10 +103,6 @@ def run_algorithm(n_test, tree_depth=None, algorithm="buffer_kd_tree"):
end_time = time.time()
test_time = (end_time - start_time)
print("Testing time: %f" % test_time)

# store results
if algorithm not in results.keys():
results[algorithm] = {}

return train_time, test_time

Expand All @@ -116,6 +112,8 @@ def run_algorithm(n_test, tree_depth=None, algorithm="buffer_kd_tree"):
for i in xrange(len(algorithms)):

algorithm = algorithms[i]
results[algorithm] = {}

print("----------------------------------------------------------------------")
print("\n\nRunning %s ...\n" % (algorithm))
print("----------------------------------------------------------------------")
Expand Down
23 changes: 19 additions & 4 deletions examples/skcompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
"""
print(__doc__)

import json
import time
import generate
from bufferkdtree.neighbors import NearestNeighbors
from sklearn.neighbors import NearestNeighbors as NearestNeighborsSKLEARN

# parameters
n_jobs = 2
n_jobs = 4
leaf_size = 30
n_test = 100000
ofilename = "skcomparison.json"
n_test_range = [100000, 250000, 500000, 750000, 1000000]
algorithms = ["kd_tree_sklearn", "kd_tree"]

verbose = 0
Expand All @@ -34,6 +36,8 @@
print("Dimensionality of patterns:\t%i" % Xtrain.shape[1])
print("----------------------------------------------------------------------")

results = {}

def run_algorithm(n_test_local, leaf_size=30, algorithm="kd_tree"):

print("----------------------------------------------------------------------")
Expand Down Expand Up @@ -75,8 +79,19 @@ def run_algorithm(n_test_local, leaf_size=30, algorithm="kd_tree"):
for i in xrange(len(algorithms)):

algorithm = algorithms[i]
results[algorithm] = {}
print("----------------------------------------------------------------------")
print("\n\nRunning %s ...\n" % (algorithm))
print("----------------------------------------------------------------------")
run_algorithm(n_test, algorithm=algorithm, leaf_size=leaf_size)

for n_test in n_test_range:
train_time, test_time = run_algorithm(n_test,
algorithm=algorithm,
leaf_size=leaf_size)
results[algorithm][n_test] = {'train':train_time,
'test':test_time,
}

# write results after each step
print("Writing results to %s ..." % ofilename)
with open(ofilename, 'w') as f:
json.dump(results, f)

0 comments on commit 38d9d3d

Please sign in to comment.