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)
Test_Case_2 = np.load('datasets/Test_files/Test/Test_Case_2.npy') Test_Case_2_Cent = np.load('datasets/Test_files/Test/Test_Case_2_Cent.npy') Test_Case_2_Query = np.load('datasets/Test_files/Test/Test_Case_2_Query.npy') Test_Case_3 = np.load('datasets/Test_files/Test/Test_Case_3.npy') Test_Case_3_Cent = np.load('datasets/Test_files/Test/Test_Case_3_Cent.npy') Test_Case_3_Query = np.load('datasets/Test_files/Test/Test_Case_3_Query.npy') # How to run your implementation for Part 1 with open('datasets/Data_File', 'rb') as f: Data_File = pickle.load(f, encoding='bytes') with open('datasets/Centroids_File', 'rb') as f: Centroids_File = pickle.load(f, encoding='bytes') start = time.time() codebooks, codes = submission.pq(Data_File, 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()