Example #1
0
    def test_hash_memory_storage_pcadp(self):
        train_vectors = numpy.random.randn(10, 100)
        hash1 = PCADiscretizedProjections('testPCADPHash', 4, train_vectors, 0.1)

        self.memory.store_hash_configuration(hash1)

        hash2 = PCADiscretizedProjections(None, None, None, None)
        hash2.apply_config(self.memory.load_hash_configuration('testPCADPHash'))

        self.assertEqual(hash1.dim, hash2.dim)
        self.assertEqual(hash1.hash_name, hash2.hash_name)
        self.assertEqual(hash1.bin_width, hash2.bin_width)
        self.assertEqual(hash1.projection_count, hash2.projection_count)

        for i in range(hash1.components.shape[0]):
            for j in range(hash1.components.shape[1]):
                self.assertEqual(hash1.components[i, j], hash2.components[i, j])
Example #2
0
    def test_hash_memory_storage_pcadp(self):
        train_vectors = numpy.random.randn(10, 100)
        hash1 = PCADiscretizedProjections('testPCADPHash', 4, train_vectors, 0.1)

        self.memory.store_hash_configuration(hash1)

        hash2 = PCADiscretizedProjections(None, None, None, None)
        hash2.apply_config(self.memory.load_hash_configuration('testPCADPHash'))

        self.assertEqual(hash1.dim, hash2.dim)
        self.assertEqual(hash1.hash_name, hash2.hash_name)
        self.assertEqual(hash1.bin_width, hash2.bin_width)
        self.assertEqual(hash1.projection_count, hash2.projection_count)

        for i in range(hash1.components.shape[0]):
            for j in range(hash1.components.shape[1]):
                self.assertEqual(hash1.components[i, j], hash2.components[i, j])
Example #3
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])
Example #4
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])
Example #5
0
 def setUp(self):
     self.vectors = numpy.random.randn(10, 100)
     self.pdp = PCADiscretizedProjections('pdp', 4, self.vectors, 0.1)
Example #6
0
 def setUp(self):
     self.vectors = numpy.random.randn(10, 100)
     self.pdp = PCADiscretizedProjections('pdp', 4, self.vectors, 0.1)