Esempio n. 1
0
    def testAddNoise(self):
        A = SDR((103, ))
        B = SDR((103, ))
        A.randomize(.1)
        B.setSDR(A)
        A.addNoise(.5)
        assert (A.getOverlap(B) == 5)

        A.randomize(.3, 42)
        B.randomize(.3, 42)
        A.addNoise(.5)
        B.addNoise(.5)
        assert (A != B)

        A.randomize(.3, 42)
        B.randomize(.3, 42)
        A.addNoise(.5, 42)
        B.addNoise(.5, 42)
        assert (A == B)
Esempio n. 2
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()