startTime = process_time() neighbours = vptree.knnQueryBatch(query, k=100, num_threads=2) end_time = process_time() searchTime = end_time - startTime rez = [] dist = [] for i in neighbours: rez.append(list(i[0])) dist.append(list(i[1])) rez = hp.fillIfNotAllAreFound(rez) result = np.asanyarray(rez) vptreeRecall = hp.returnRecall(result, groundTruth) avgDist = np.mean(list(chain.from_iterable(dist))) reacll.append(vptreeRecall) algorithm.append('vp-Tree-10k-mL' + str(maxLeave)) #algorithm.append('vp-Tree-maxLeaves'+str(maxLeaves)) construciotnTimes.append(constructionTime) searchTimes.append(searchTime) avgdistances.append(avgDist) del rez del dist del result gc.collect() #vptree.saveIndex('vptreeIndex.ann') del vptree
startTime = process_time() for q in query: res,d = t.get_nns_by_vector(q, 100, search_k = searchK, include_distances=True) rez.append(res) dist.append(d) #result.append(t.get_nns_by_vector(q, 100, include_distances=True)) end_time = process_time() searchTime = end_time - startTime endClock = time.clock() searchClock= endClock - startClock result = hp.fillIfNotAllAreFound(rez) result = np.asanyarray(result) annoyRecall = hp.returnRecall(result, groundTruth) avgDist = np.mean(list(chain.from_iterable(dist))) reacll.append(annoyRecall) algorithm.append('Annoy-trees-'+str(numTrees)) construciotnTimes.append(constructionTime) searchTimes.append(searchTime) avgdistances.append(avgDist) searchClocks.append(searchClock) constructionClocks.append(constructionClock) clockAlg.append('Annoy-trees-'+str(numTrees)) t.save('annoyIndex90.ann') del t del rez del dist del result
neighbours = hnsw.knnQueryBatch(query, k=100, num_threads=2) end_time = process_time() searchTime = end_time - startTime endClock = time.clock() searchClock = endClock - startClock rez = [] dist = [] for i in neighbours: rez.append(list(i[0])) dist.append(list(i[1])) result = hp.fillIfNotAllAreFound(rez) result = np.array(rez) hnswRecall = hp.returnRecall(result, groundTruth) avgDist = np.mean(np.sqrt(list(chain.from_iterable(dist)))) reacll.append(hnswRecall) algorithm.append('HNSW-M-' + str(MMAX)) construciotnTimes.append(constructionTime) searchTimes.append(searchTime) avgdistances.append(avgDist) constructionClocks.append(constructionClock) searchClocks.append(searchClock) clockAlg.append('HNSW-M-' + str(MMAX)) hnsw.saveIndex('hnswIndex40.ann') del hnsw del rez del dist del result
#flannparams = flann.build_index(train, algorithm ='autotuned', target_precision=tp, build_weight=0 ,memory_weight=0, sample_fraction=0.05) end_time = process_time() constructionTime = end_time - startTime endClock = time.clock() constructionClock = endClock - startClock startClock = time.clock() startTime = process_time() result, dist = flann.nn_index(query, 100) end_time = process_time() searchTime = end_time - startTime endClock = time.clock() searchClock = endClock - startClock result = hp.fillIfNotAllAreFound(result) result = np.asanyarray(result) rkdDflannRecall = hp.returnRecall(result, groundTruth) avgDist = np.mean(np.sqrt(dist)) para.append(flannparams) reacll.append(rkdDflannRecall) algorithm.append(flannparams['algorithm'] + '-flann-build005') construciotnTimes.append(constructionTime) searchTimes.append(searchTime) avgdistances.append(avgDist) searchClocks.append(searchClock) constructionClocks.append(constructionClock) clockAlg.append(flannparams['algorithm'] + '-flann-build005')
avgdistances = [] #bruteForce from sklearn.neighbors import NearestNeighbors startTime = process_time() nbrs = NearestNeighbors(n_neighbors=100, algorithm='brute').fit(train) end_time = process_time() constructionTime = end_time - startTime startTime = process_time() dist, result = nbrs.kneighbors(query, return_distance=True) end_time = process_time() searchTime = end_time - startTime bruteRecall = hp.returnRecall(result, groundTruth) avgDist = np.mean(np.mean(dist, axis=1)) reacll.append(bruteRecall) algorithm.append('brute force') construciotnTimes.append(constructionTime) searchTimes.append(searchTime) avgdistances.append(avgDist) #KDTree test scikit learn from sklearn.neighbors import KDTree startTime = process_time() kdt = KDTree(train, metric='euclidean', leaf_size=2) end_time = process_time() constructionTime = end_time - startTime