Beispiel #1
0
class TestPCADiscretizedProjections(unittest.TestCase):

    def setUp(self):
        self.vectors = numpy.random.randn(10, 100)
        self.pdp = PCADiscretizedProjections('pdp', 4, self.vectors, 0.1)

    def test_hash_format(self):
        h = self.pdp.hash_vector(numpy.random.randn(10))
        self.assertEqual(len(h), 1)
        self.assertEqual(type(h[0]), type(''))

    def test_hash_deterministic(self):
        x = numpy.random.randn(10)
        first_hash = self.pdp.hash_vector(x)[0]
        for k in range(100):
            self.assertEqual(first_hash, self.pdp.hash_vector(x)[0])

    def test_hash_format_sparse(self):
        h = self.pdp.hash_vector(scipy.sparse.rand(10, 1, density=0.6))
        self.assertEqual(len(h), 1)
        self.assertEqual(type(h[0]), type(''))

    def test_hash_deterministic_sparse(self):
        x = scipy.sparse.rand(10, 1, density=0.6)
        first_hash = self.pdp.hash_vector(x)[0]
        for k in range(100):
            self.assertEqual(first_hash, self.pdp.hash_vector(x)[0])
Beispiel #2
0
class TestPCADiscretizedProjections(unittest.TestCase):

    def setUp(self):
        self.vectors = numpy.random.randn(10, 100)
        self.pdp = PCADiscretizedProjections('pdp', 4, self.vectors, 0.1)

    def test_hash_format(self):
        h = self.pdp.hash_vector(numpy.random.randn(10))
        self.assertEqual(len(h), 1)
        self.assertEqual(type(h[0]), type(''))

    def test_hash_deterministic(self):
        x = numpy.random.randn(10)
        first_hash = self.pdp.hash_vector(x)[0]
        for k in range(100):
            self.assertEqual(first_hash, self.pdp.hash_vector(x)[0])

    def test_hash_format_sparse(self):
        h = self.pdp.hash_vector(scipy.sparse.rand(10, 1, density=0.6))
        self.assertEqual(len(h), 1)
        self.assertEqual(type(h[0]), type(''))

    def test_hash_deterministic_sparse(self):
        x = scipy.sparse.rand(10, 1, density=0.6)
        first_hash = self.pdp.hash_vector(x)[0]
        for k in range(100):
            self.assertEqual(first_hash, self.pdp.hash_vector(x)[0])