예제 #1
0
 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)
예제 #2
0
 def testExampleUsage(self):
     A = SDR(10)
     B = SDR(10)
     X = SDR(A.dimensions)
     A.sparse = [0, 1, 2, 3]
     B.sparse = [2, 3, 4, 5]
     X.intersection(A, B)
     assert (set(X.sparse) == set([2, 3]))
예제 #3
0
 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)