def fit(self, X): hashes = [] for k in xrange(self._hash_counts): nearpy_rbp = nearpy.hashes.RandomBinaryProjections('rbp_%d' % k, self._n_bits) hashes.append(nearpy_rbp) self._nearpy_engine = nearpy.Engine(X.shape[1], lshashes=hashes, distance=nearpy.distances.CosineDistance()) for i, x in enumerate(X): self._nearpy_engine.store_vector(x.tolist(), i)
def fit(self, X): hashes = [] # TODO: doesn't seem like the NearPy code is using the metric?? for k in xrange(self._hash_counts): nearpy_rbp = nearpy.hashes.RandomBinaryProjections('rbp_%d' % k, self._n_bits) hashes.append(nearpy_rbp) self._nearpy_engine = nearpy.Engine(X.shape[1], lshashes=hashes) for i, x in enumerate(X): self._nearpy_engine.store_vector(x.tolist(), i)
def fit(self, X): hashes = [] for k in xrange(self._hash_counts): nearpy_rbp = nearpy.hashes.RandomBinaryProjections( 'rbp_%d' % k, self._n_bits) hashes.append(nearpy_rbp) self._nearpy_engine = nearpy.Engine(X.shape[1], lshashes=hashes) for i, x in enumerate(X): self._nearpy_engine.store_vector(x.tolist(), i)
def fit(self, X): import nearpy, nearpy.hashes, nearpy.distances hashes = [] # TODO: doesn't seem like the NearPy code is using the metric?? for k in xrange(self._hash_counts): nearpy_rbp = nearpy.hashes.RandomBinaryProjections( 'rbp_%d' % k, self._n_bits) hashes.append(nearpy_rbp) self._nearpy_engine = nearpy.Engine(X.shape[1], lshashes=hashes) for i, x in enumerate(X): self._nearpy_engine.store_vector(x.tolist(), i)
def handle(self, *args, **options): import nearpy, nearpy.hashes, nearpy.distances resample_dim_pool = [[4,4,4],[6,6,6],[8,8,8],[10,10,10],[12,12,12],[14,14,14],[16,16,16]] subjects = 940 n_bits_pool = [2, 4, 6, 8, 10] hash_counts_pool = [2, 5, 10, 15, 20] metric_pool = ["euclidean","cosine"] z_score_pool = ["yes", "no"] for resample_dim in resample_dim_pool: features, dict_feat = createFeatures(subjects, resample_dim) scores = get_neurovault_scores(subjects, dict_feat) for n_bits in n_bits_pool: for hash_counts in hash_counts_pool: for metric in metric_pool: #for z_score in z_score_pool: if metric == "euclidean": distance = nearpy.distances.EuclideanDistance() else: distance = nearpy.distances.EuclideanDistance() # fit hashes = [] for k in xrange(hash_counts): nearpy_rbp = nearpy.hashes.RandomBinaryProjections('rbp_%d' % k, n_bits) hashes.append(nearpy_rbp) nearpy_engine = nearpy.Engine(features.shape[1], lshashes=hashes, distance=distance) for i, x in enumerate(features): nearpy_engine.store_vector(x.tolist(), dict_feat[i]) #query for i in range(features.shape[0]): results = nearpy_engine.neighbours(features[i])
features, dict_feat = np.load('/code/neurovault/apps/statmaps/tests/features_940_16_16_16.npy').T, \ pickle.load(open('/code/neurovault/apps/statmaps/tests/dict_feat.p', "rb")) import timeit ## NEARPY TEST n_bits = 5 hash_counts = 20 metric = "euclidean" name = 'NearPy(n_bits=%d, hash_counts=%d)' % (n_bits, hash_counts) # fiting import nearpy, nearpy.hashes, nearpy.distances hashes = [] # doesn't seem like the NearPy code is using the metric?? for k in xrange(hash_counts): nearpy_rbp = nearpy.hashes.RandomBinaryProjections('rbp_%d' % k, n_bits) hashes.append(nearpy_rbp) filter_N = nearpy.filters.NearestFilter(100) nearpy_engine = nearpy.Engine(features.shape[1], distance= nearpy.distances.EuclideanDistance(), lshashes=hashes,vector_filters=[filter_N]) #indexing t = Timer() with t: for i, x in enumerate(features): nearpy_engine.store_vector(x.tolist(), dict_feat[i]) # querying for i in range(features.shape[0]): t = Timer() with t: results = nearpy_engine.neighbours(features[i])