def testInPlace(self): A = SDR(1000) B = SDR(1000) A.randomize(1.00) B.randomize(.50) A.intersection(A, B) assert (A.getSparsity() == .5) A.randomize(1.00) B.randomize(.50) A.intersection(B, A) assert (A.getSparsity() == .5)
def testSparsity(self): test_cases = [ (0.5, 0.5), (0.1, 0.9), (0.25, 0.3), (0.5, 0.5, 0.5), (0.95, 0.95, 0.95), (0.10, 0.10, 0.60), (0.0, 1.0, 1.0), (0.5, 0.5, 0.5, 0.5), (0.11, 0.25, 0.33, 0.5, 0.98, 0.98, 0.98, 0.98, 0.98, 0.98, 0.98), ] size = 10000 seed = 99 X = SDR(size) for sparsities in test_cases: sdrs = [] for S in sparsities: inp = SDR(size) inp.randomize(S, seed) seed += 1 sdrs.append(inp) X.intersection(sdrs) mean_sparsity = np.product(sparsities) assert (X.getSparsity() >= (2. / 3.) * mean_sparsity) assert (X.getSparsity() <= (4. / 3.) * mean_sparsity)
def testGetSparsity(self): A = SDR((103, )) assert (A.getSparsity() == 0) A.dense = np.ones(A.size) assert (A.getSparsity() == 1)