P=4,
                                 init_centroids=four_centroids,
                                 max_iter=20)
end = time.time()
time_cost_1 = end - start
print(time_cost_1)
print("Codebook shape: ", codebooks.shape)
print(" Codebook type: ", codebooks.dtype)
print("   Codes shape: ", codes.shape)
print("    Codes type: ", codes.dtype)

# How to run your implementation for Part 2
with open('datasets/Query_File', 'rb') as f:
    queries = pickle.load(f, encoding='bytes')
start = time.time()
candidates = submission.query(one28_que, codebooks, codes, T=10)
end = time.time()
time_cost_2 = end - start
print(time_cost_2)

# output for part 2.
print(candidates)

print(codes)
print(codebooks)

# ## Running Time Limits
#
# As shown in the above snippet, we will be recording the running time of both part 1 and part 2. Your implementation is expected to finish with Allowed time Limit. If your code takes longer than Allowed Time Limit, your program will be terminated and you will recieve 0 mark.
#
# For example, on CSE machine, e.g., **wagner**, your code is supposed to finish with in 3 seconds (for part 1) and 1 second (for part 2) for the toy example illustrated above.
Exemplo n.º 2
0
import submission
import pickle
import time

# How to run your implementation for Part 1
with open('./toy_example/Data_File', 'rb') as f:
    Data_File = pickle.load(f, encoding='bytes')
with open('./toy_example/Centroids_File', 'rb') as f:
    Centroids_File = pickle.load(f, encoding='bytes')
start = time.time()
codebooks, codes = submission.pq(Data_File,
                                 P=2,
                                 init_centroids=Centroids_File,
                                 max_iter=20)
end = time.time()
time_cost_1 = end - start

# How to run your implementation for Part 2
with open('./toy_example/Query_File', 'rb') as f:
    Query_File = pickle.load(f, encoding='bytes')
queries = Query_File
start = time.time()
candidates = submission.query(queries, codebooks, codes, T=10)
end = time.time()
time_cost_2 = end - start

# output for part 2.
print(candidates)
print(time_cost_2)
Exemplo n.º 3
0
import submission
import pickle
import time

# How to run your implementation for Part 1
with open('./toy_example/Data_File', 'rb') as f:
    Data_File = pickle.load(f, encoding='bytes')
with open('./toy_example/Centroids_File', 'rb') as f:
    Centroids_File = pickle.load(f, encoding='bytes')
start = time.time()

codebooks, codes = submission.pq(Data_File,
                                 P=2,
                                 init_centroids=Centroids_File,
                                 max_iter=20)
end = time.time()
time_cost_1 = end - start

# How to run your implementation for Part 2
with open('./toy_example/Query_File', 'rb') as f:
    Query_File = pickle.load(f, encoding='bytes')

start = time.time()
candidates = submission.query(Query_File, codebooks, codes, T=10)

end = time.time()
time_cost_2 = end - start

# output for part 2.
print(candidates)