def report(prefix, encoded, data, post_cn): if post_cn: encoded = center_data(encoded) encoded = norm_data(encoded) val_l2 = rprec_l2( encoded["queries"], encoded["docs"], data["relevancy"], fast=True, report=False) if post_cn: val_ip = val_l2 else: val_ip = rprec_ip( encoded["queries"], encoded["docs"], data["relevancy"], fast=True, report=False) print(f'{prefix} rprec_ip: {val_ip:.3f}, rprec_l2: {val_l2:.3f}') return val_ip, val_l2
def summary_performance(name, dataReduced, dataReconstructed): if args.post_cn: dataReduced = center_data(dataReduced) dataReduced = norm_data(dataReduced) val_ip = rprec_ip(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True) val_l2 = rprec_l2(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True) loss_q = torch.nn.MSELoss()(torch.Tensor(data["queries"]), torch.Tensor(dataReconstructed["queries"])) loss_d = torch.nn.MSELoss()(torch.Tensor(data["docs"]), torch.Tensor(dataReconstructed["docs"])) return val_ip, val_l2, loss_q.item(), loss_d.item()
def summary_performance(name, dataReduced, dataReconstructed): if args.post_cn: dataReduced = center_data(dataReduced) dataReduced = norm_data(dataReduced) val_ip = rprec_ip(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True) val_l2 = rprec_l2(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True) loss_q = torch.nn.MSELoss()(torch.Tensor(data["queries"]), torch.Tensor(dataReconstructed["queries"])) loss_d = torch.nn.MSELoss()(torch.Tensor(data["docs"]), torch.Tensor(dataReconstructed["docs"])) name = name.replace("float", "f") print( f"{name:<21} {loss_d:>7.5f} {loss_q:>7.5f} {val_ip:>5.3f} {val_l2:>5.3f}" ) return val_ip, val_l2, loss_q.item(), loss_d.item()
print("\nReduced norms") print( f"Queries: {np.average(np.linalg.norm(dataReduced['queries'], axis=1)[:, np.newaxis]):.8f}" ) print( f"Docs: {np.average(np.linalg.norm(dataReduced['docs'], axis=1)[:, np.newaxis]):.8f}" ) print("\nPerformance") val_ip_pca = rprec_ip(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True) val_l2_pca = rprec_l2(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True) print(f"IP: {val_ip_pca}") print(f"L2: {val_l2_pca}") print("\nRenormalized performance") dataReduced = center_data(dataReduced) dataReduced = norm_data(dataReduced) val_ip_pca = rprec_ip(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True) val_l2_pca = rprec_l2(dataReduced["queries"], dataReduced["docs"], data["relevancy"], fast=True)