MCPcopy Create free account
hub / github.com/dblalock/bolt / load_dataset

Function load_dataset

experiments/python/datasets.py:194–278  ·  view source on GitHub ↗
(which_dataset, N=-1, D=-1, norm_mean=False, norm_len=False,
                 num_queries=10, Ntrain=-1, D_multiple_of=-1)

Source from the content-addressed store, hash-verified

192
193# @_memory.cache # uncomment to get same randomness each time
194def load_dataset(which_dataset, N=-1, D=-1, norm_mean=False, norm_len=False,
195 num_queries=10, Ntrain=-1, D_multiple_of=-1):
196 true_nn = None
197
198 # randomly generated datasets
199 if which_dataset == Random.UNIFORM:
200 X_test = np.random.rand(N, D)
201 X_train = np.random.rand(Ntrain, D) if Ntrain > 0 else X_test
202 Q = np.random.rand(num_queries, D)
203 elif which_dataset == Random.GAUSS:
204 X_test = np.random.randn(N, D)
205 X_train = np.random.randn(Ntrain, D) if Ntrain > 0 else X_test
206 Q = np.random.randn(num_queries, D)
207 elif which_dataset == Random.WALK:
208 X_test = np.random.randn(N, D)
209 X_test = np.cumsum(X_test, axis=1)
210 X_train = np.copy(X_test)
211 if Ntrain > 0:
212 X_train = np.random.randn(Ntrain, D)
213 X_train = np.cumsum(X_train)
214 Q = np.random.randn(num_queries, D)
215 Q = np.cumsum(Q, axis=-1)
216 elif which_dataset == Random.BLOBS:
217 # centers is D x D, and centers[i, j] = (i + j)
218 centers = np.arange(D)
219 centers = np.sum(np.meshgrid(centers, centers), axis=0)
220 X_test, _ = make_blobs(n_samples=N, centers=centers)
221 X_train = np.copy(X_test)
222 if Ntrain > 0:
223 X_train, _ = make_blobs(n_samples=Ntrain, centers=centers)
224 Q, true_nn = make_blobs(n_samples=num_queries, centers=centers)
225
226 # datasets that are just one block of a "real" dataset
227 elif isinstance(which_dataset, str):
228 # assert False # TODO rm after real experiments
229 X_test = load_file(which_dataset)
230 X_test, Q = extract_random_rows(X_test, how_many=num_queries)
231 X_train = np.copy(X_test)
232 true_nn = _ground_truth_for_dataset(which_dataset)
233
234 # "real" datasets with predefined train, test, queries, truth
235 elif which_dataset in ALL_REAL_DATASETS:
236 X_train, Q, X_test, true_nn = _load_complete_dataset(
237 which_dataset, num_queries=num_queries)
238
239 else:
240 raise ValueError("unrecognized dataset {}".format(which_dataset))
241
242 N = X_test.shape[0] if N < 1 else N
243 D = X_test.shape[1] if D < 1 else D
244 X_test, X_train = np.copy(X_test)[:N, :D], X_train[:N, :D]
245 Q = Q[:, :D] if len(Q.shape) > 1 else Q[:D]
246
247 train_is_test = X_train.base is X_test or X_test.base is X_train
248 train_is_test = train_is_test or np.array_equal(X_train[:100], X_test[:100])
249
250 if train_is_test:
251 print "WARNING: Training data is also the test data!"

Callers

nothing calls this directly

Calls 9

load_fileFunction · 0.85
extract_random_rowsFunction · 0.85
_load_complete_datasetFunction · 0.85
formatMethod · 0.80
sumMethod · 0.45
meanMethod · 0.45
normMethod · 0.45

Tested by

no test coverage detected