(dataset, encoder, dist_func_true=None, dist_func_enc=None,
eval_dists=True, verbosity=1, plot=False, smaller_better=True)
| 315 | # ================================================================ Main |
| 316 | |
| 317 | def eval_encoder(dataset, encoder, dist_func_true=None, dist_func_enc=None, |
| 318 | eval_dists=True, verbosity=1, plot=False, smaller_better=True): |
| 319 | |
| 320 | X = dataset.X_test |
| 321 | queries = dataset.Q |
| 322 | true_nn = dataset.true_nn |
| 323 | |
| 324 | if true_nn is not None: |
| 325 | print "eval encoder(): got true_nn with shape: ", true_nn.shape |
| 326 | |
| 327 | queries = queries[:1000] # TODO rm for tables; fine for plots |
| 328 | print "queries.shape", queries.shape |
| 329 | |
| 330 | need_true_dists = eval_dists or plot or true_nn is None |
| 331 | |
| 332 | if len(queries.shape) == 1: |
| 333 | queries = [queries] |
| 334 | |
| 335 | if dist_func_true is None: |
| 336 | dist_func_true = encoder.dists_true |
| 337 | if dist_func_enc is None: |
| 338 | dist_func_enc = encoder.dists_enc |
| 339 | |
| 340 | t0 = time.time() |
| 341 | |
| 342 | # performance metrics |
| 343 | RECALL_Rs = [1, 5, 10, 50, 100, 500, 1000] |
| 344 | recall_counts = np.zeros(len(RECALL_Rs)) |
| 345 | fracs_below_max = [] |
| 346 | if eval_dists: |
| 347 | all_corrs = [] |
| 348 | all_rel_errs = [] |
| 349 | all_errs = [] |
| 350 | total_dist = 0. |
| 351 | |
| 352 | if need_true_dists: |
| 353 | X = X[:10000] # limit to 10k points because otherwise it takes forever |
| 354 | queries = queries[:256, :] |
| 355 | |
| 356 | print "encoding X..." |
| 357 | X_enc = encoder.encode_X(X) |
| 358 | print "trying queries..." |
| 359 | for i, q in enumerate(queries): |
| 360 | |
| 361 | if i % 100 == 0: |
| 362 | print "trying query {}...".format(i) |
| 363 | |
| 364 | q_enc = encoder.encode_q(q) |
| 365 | encoder.fit_query(q) |
| 366 | if need_true_dists: |
| 367 | all_true_dists = dist_func_true(X, q) |
| 368 | |
| 369 | all_enc_dists = dist_func_enc(X_enc, q_enc) |
| 370 | |
| 371 | # ------------------------ begin analysis / reporting code |
| 372 | |
| 373 | # find true knn |
| 374 | if need_true_dists: |
no test coverage detected