Beispiel #1
0
            #print("num of non 0 elements in expected : ", expected[expectedIndices].nonzero().numel())
            #print("num of non 0 elements in result : ", result[expectedIndices].nonzero().numel())
            print('csvec accuracy :', csvec_accuracy)
            print('expected :', expected)
            print('result :', result)

            for h_i, h in enumerate(hVals):
                result = torch.zeros(len(summed), device=device)
                h_curr = int(h * k)
                w_0 = TopHCS(d=d,
                             c=c,
                             r=r,
                             h=h_curr,
                             numBlocks=numBlocks,
                             device=device)
                w_0.store(vecs[0])
                print(w_0.topH)

                print("")
                w_1 = TopHCS(d=d,
                             c=c,
                             r=r,
                             h=h_curr,
                             numBlocks=numBlocks,
                             device=device)
                w_1.store(vecs[1])

                print(w_0.topH)
                print("")
                w_2 = TopHCS(d=d,
                             c=c,
Beispiel #2
0
        diff = recovered_1[recovered_1 != 0] - expected[recovered_1 != 0]
        L1_1[k_i] = torch.median(torch.abs(diff))
        L2_1[k_i] = torch.median(diff**2)

        for h_i, hVal in enumerate(hVals):
            h = int(k * hVal)
            workers = []  #reusing
            for vec in vecs:
                w = TopHCS(h=h,
                           d=d,
                           c=c,
                           r=r,
                           numBlocks=numBlocks,
                           device=device)
                w.store(vec)
                workers.append(w)

            assert (len(workers) == len(vecs))

            recovered_2 = TopHCS.topKSum(workers, k)
            indexAcc_2[
                h_i,
                k_i] = (expected[expectedIndices] *
                        recovered_2[expectedIndices]).nonzero().numel() / k

            diff = recovered_2[recovered_2 != 0] - expected[recovered_2 != 0]
            L1_2[h_i, k_i] = torch.median(torch.abs(diff))
            L2_2[h_i, k_i] = torch.median(diff**2)

            #indexAcc = (expected == recovered).nonzero().numel() / k
        diff = recovered_1[diff] - summed[
            diff]  #ugly code, but overwriting to reduce vars
        L1_1[k_i] = torch.median(torch.abs(diff))
        L2_1[k_i] = torch.median(diff**2)

        for h_i, hVal in enumerate(hVals):
            h = int(k * hVal)
            workers = []  #re-initialize
            for v in vecs:
                w = TopHCS(h=h,
                           d=d,
                           c=c,
                           r=r,
                           numBlocks=numBlocks,
                           device=device)
                w.store(v)
                workers.append(w)

            assert (len(workers) == len(vecs))

            recovered_2 = TopHCS.topKSum(workers, k)
            print("Heap @ exp Indices : ", recovered_2[expectedIndices])
            indexAcc_2[
                h_i,
                k_i] = (expected[expectedIndices] *
                        recovered_2[expectedIndices]).nonzero().numel() / k

            diff = torch.sort(
                torch.nonzero(recovered_2.view(-1).data).squeeze())[0]
            assert (len(diff) == k)
            print("Heap @ reported Indices : ", recovered_2[diff])
Beispiel #4
0
			w_0 += vecs[0]
			print("worker added")
			w_1 = CSVec(d=d, c=c, r=r, numBlocks=numBlocks, device=device)
			w_1 += vecs[1]
			print("worker added")
			
			workersSummed = w_0 + w_1
			result = workersSummed.unSketch(k)
			csvecAcc[k_i] = (expected[expectedIndices] * result[expectedIndices]).nonzero().numel() / k
			print("k = {}".format(k))
			csvecL2[k_i] = (torch.sum((result - expected)**2))**0.5
			for h_i, h in enumerate(hVals):
				result = torch.zeros(len(summed), device=device)
				h_curr = int(h*k)
				w_0 = TopHCS(d=d, c=c, r=r, h=h_curr, numBlocks=numBlocks, device=device)
				w_0.store(vecs[0])
				print("worker added")
				w_1 = TopHCS(d=d, c=c, r=r, h=h_curr, numBlocks=numBlocks, device=device)
				w_1.store(vecs[1])
				print("worker added")
				workers = [w_0, w_1]
				result = TopHCS.topKSum(workers, k)
				 
				topHCSAcc[h_i, k_i]  = (expected[expectedIndices] * result[expectedIndices]).nonzero().numel() / k
				print("h_curr = {}".format(h_curr))
				topHCSL2[h_i, k_i] = (torch.sum((result - expected)**2))**0.5
			print('topHCS accuracy :', '\n', topHCSAcc)
			print('CSVec accuracy :', '\n', csvecAcc)
		numColors = len(hVals) + 1
		colors = plt.cm.plasma(np.linspace(0,1,numColors))
		axs[p, 0].set_xlabel("k")
Beispiel #5
0
            print("worker added")

            result = w_0.unSketch(k)
            csvecAcc[k_i] = (expected[expectedIndices] *
                             result[expectedIndices]).nonzero().numel() / k
            print("k = {}".format(k))
            csvecL2[k_i] = (torch.sum((result - expected)**2))**0.5
            for h_i, h in enumerate(hVals):
                result = torch.zeros(len(summed), device=device)
                w_0 = TopHCS(d=d,
                             c=c,
                             r=r,
                             h=h,
                             numBlocks=numBlocks,
                             device=device)
                w_0.store(vecs[0])
                print("worker added")
                workers = [w_0]
                result = TopHCS.topKSum(workers, k)

                topHCSAcc[
                    h_i, k_i] = (expected[expectedIndices] *
                                 result[expectedIndices]).nonzero().numel() / k
                print("h_curr = {}".format(h_curr))
                topHCSL2[h_i, k_i] = (torch.sum((result - expected)**2))**0.5
            print('topHCS accuracy :', '\n', topHCSAcc)
            print('CSVec accuracy :', '\n', csvecAcc)
        numColors = len(hVals) + 1
        colors = plt.cm.plasma(np.linspace(0, 1, numColors))
        axs[p, 0].set_xlabel("k")
        axs[p, 0].set_ylabel("index accuracy")