Пример #1
0
 def testCompute(self):
     """ Check that there are no errors in call to compute. """
     inputs = SDR(100).randomize(.05)
     active = SDR(100)
     sp = SP(inputs.dimensions, active.dimensions, stimulusThreshold=1)
     sp.compute(inputs, True, active)
     assert (active.getSum() > 0)
Пример #2
0
 def testNan(self):
     gc = GridCellEncoder(size=200,
                          sparsity=.25,
                          periods=[6, 8.5, 12, 17, 24],
                          seed=42)
     zero = SDR(gc.dimensions)
     zero.randomize(.25)
     gc.encode([3, float('nan')], zero)
     assert (zero.getSum() == 0)
Пример #3
0
 def testNaNs(self):
     p = ScalarEncoderParameters()
     p.size = 100
     p.activeBits = 10
     p.minimum = 0
     p.maximum = 100
     enc = ScalarEncoder(p)
     sdr = SDR(100)
     enc.encode(float("nan"), sdr)
     assert (sdr.getSum() == 0)
Пример #4
0
    def testSetSDR(self):
        A = SDR((103, ))
        B = SDR((103, ))
        A.sparse = [66]
        B.setSDR(A)
        assert (B.dense[66] == 1)
        assert (B.getSum() == 1)
        B.dense[77] = 1
        B.dense = B.dense
        A.setSDR(B)
        assert (set(A.sparse) == set((66, 77)))

        # Test wrong dimensions assigned
        C = SDR((2, 4, 5, 1, 1, 1, 1, 3))
        C.randomize(.5)
        try:
            A.setSDR(C)
        except RuntimeError:
            pass
        else:
            self.fail()
Пример #5
0
 def testMirroring(self):
     A = SDR(100)
     A.randomize(.05)
     Ax10 = SDR(100 * 10)
     Ax10.concatenate([A] * 10)
     assert (Ax10.getSum() == 100 * 10 * .05)
Пример #6
0
 def testGetSum(self):
     A = SDR((103, ))
     assert (A.getSum() == 0)
     A.dense = np.ones(A.size)
     assert (A.getSum() == 103)