当前位置: 首页>>代码示例>>Python>>正文


Python DescriptorMemoryElement.vector方法代码示例

本文整理汇总了Python中smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement.vector方法的典型用法代码示例。如果您正苦于以下问题:Python DescriptorMemoryElement.vector方法的具体用法?Python DescriptorMemoryElement.vector怎么用?Python DescriptorMemoryElement.vector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement的用法示例。


在下文中一共展示了DescriptorMemoryElement.vector方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_none_set

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
    def test_none_set(self):
        d = DescriptorMemoryElement('test', 0)
        ntools.assert_false(d.has_vector())

        d.set_vector(numpy.ones(16))
        ntools.assert_true(d.has_vector())
        numpy.testing.assert_equal(d.vector(), numpy.ones(16))

        d.set_vector(None)
        ntools.assert_false(d.has_vector())
        ntools.assert_is(d.vector(), None)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:13,代码来源:test_DescriptorMemoryElement.py

示例2: test_none_set

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
    def test_none_set(self):
        d = DescriptorMemoryElement('test', 0)
        self.assertFalse(d.has_vector())

        d.set_vector(numpy.ones(16))
        self.assertTrue(d.has_vector())
        numpy.testing.assert_equal(d.vector(), numpy.ones(16))

        d.set_vector(None)
        self.assertFalse(d.has_vector())
        self.assertIs(d.vector(), None)
开发者ID:Kitware,项目名称:SMQTK,代码行数:13,代码来源:test_DescriptorMemoryElement.py

示例3: test_output_immutability

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
 def test_output_immutability(self):
     # make sure that data stored is not susceptible to modifications after
     # extraction
     v = numpy.ones(16)
     d = DescriptorMemoryElement('test', 0)
     ntools.assert_false(d.has_vector())
     d.set_vector(v)
     r = d.vector()
     r[:] = 0
     ntools.assert_equal(r.sum(), 0)
     ntools.assert_equal(d.vector().sum(), 16)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:13,代码来源:test_DescriptorMemoryElement.py

示例4: _random_euclidean

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
    def _random_euclidean(self, hash_ftor, hash_idx,
                          ftor_train_hook=lambda d: None):
        # :param hash_ftor: Hash function class for generating hash codes for
        #   descriptors.
        # :param hash_idx: Hash index instance to use in local LSH algo
        #   instance.
        # :param ftor_train_hook: Function for training functor if necessary.

        # make random descriptors
        i = 1000
        dim = 256
        td = []
        np.random.seed(self.RANDOM_SEED)
        for j in range(i):
            d = DescriptorMemoryElement('random', j)
            d.set_vector(np.random.rand(dim))
            td.append(d)

        ftor_train_hook(td)

        di = MemoryDescriptorIndex()
        kvstore = MemoryKeyValueStore()
        index = LSHNearestNeighborIndex(hash_ftor, di, kvstore,
                                        hash_index=hash_idx,
                                        distance_method='euclidean')
        index.build_index(td)

        # test query from build set -- should return same descriptor when k=1
        q = td[255]
        r, dists = index.nn(q, 1)
        self.assertEqual(r[0], q)

        # test query very near a build vector
        td_q = td[0]
        q = DescriptorMemoryElement('query', i)
        v = td_q.vector().copy()
        v_min = max(v.min(), 0.1)
        v[0] += v_min
        v[dim-1] -= v_min
        q.set_vector(v)
        r, dists = index.nn(q, 1)
        self.assertFalse(np.array_equal(q.vector(), td_q.vector()))
        self.assertEqual(r[0], td_q)

        # random query
        q = DescriptorMemoryElement('query', i+1)
        q.set_vector(np.random.rand(dim))

        # for any query of size k, results should at least be in distance order
        r, dists = index.nn(q, 10)
        for j in range(1, len(dists)):
            self.assertGreater(dists[j], dists[j-1])
        r, dists = index.nn(q, i)
        for j in range(1, len(dists)):
            self.assertGreater(dists[j], dists[j-1])
开发者ID:Kitware,项目名称:SMQTK,代码行数:57,代码来源:test_NNI_lsh.py

示例5: test_input_immutability

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
    def test_input_immutability(self):
        # make sure that data stored is not susceptible to shifts in the
        # originating data matrix they were pulled from.

        #
        # Testing this with a single vector
        #
        v = numpy.random.rand(16)
        t = tuple(v.copy())
        d = DescriptorMemoryElement('test', 0)
        d.set_vector(v)
        v[:] = 0
        ntools.assert_true((v == 0).all())
        ntools.assert_false(sum(t) == 0.)
        numpy.testing.assert_equal(d.vector(), t)

        #
        # Testing with matrix
        #
        m = numpy.random.rand(20, 16)

        v1 = m[3]
        v2 = m[15]
        v3 = m[19]

        # Save truth values of arrays as immutable tuples (copies)
        t1 = tuple(v1.copy())
        t2 = tuple(v2.copy())
        t3 = tuple(v3.copy())

        d1 = DescriptorMemoryElement('test', 1)
        d1.set_vector(v1)
        d2 = DescriptorMemoryElement('test', 2)
        d2.set_vector(v2)
        d3 = DescriptorMemoryElement('test', 3)
        d3.set_vector(v3)

        numpy.testing.assert_equal(v1, d1.vector())
        numpy.testing.assert_equal(v2, d2.vector())
        numpy.testing.assert_equal(v3, d3.vector())

        # Changing the source should not change stored vectors
        m[:, :] = 0.
        ntools.assert_true((v1 == 0).all())
        ntools.assert_true((v2 == 0).all())
        ntools.assert_true((v3 == 0).all())
        ntools.assert_false(sum(t1) == 0.)
        ntools.assert_false(sum(t2) == 0.)
        ntools.assert_false(sum(t3) == 0.)
        numpy.testing.assert_equal(d1.vector(), t1)
        numpy.testing.assert_equal(d2.vector(), t2)
        numpy.testing.assert_equal(d3.vector(), t3)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:54,代码来源:test_DescriptorMemoryElement.py

示例6: test_set_state_version_1

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
    def test_set_state_version_1(self):
        # Test support of older state version
        expected_type = 'test-type'
        expected_uid = 'test-uid'
        expected_v = numpy.array([1, 2, 3])
        expected_v_b = BytesIO()
        # noinspection PyTypeChecker
        numpy.save(expected_v_b, expected_v)
        expected_v_dump = expected_v_b.getvalue()

        e = DescriptorMemoryElement(None, None)
        e.__setstate__((expected_type, expected_uid, expected_v_dump))
        self.assertEqual(e.type(), expected_type)
        self.assertEqual(e.uuid(), expected_uid)
        numpy.testing.assert_array_equal(e.vector(), expected_v)
开发者ID:Kitware,项目名称:SMQTK,代码行数:17,代码来源:test_DescriptorMemoryElement.py

示例7: _random_euclidean

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
    def _random_euclidean(self, hash_ftor, hash_idx, ftor_train_hook=lambda d: None):
        # make random descriptors
        i = 1000
        dim = 256
        td = []
        numpy.random.seed(self.RANDOM_SEED)
        for j in xrange(i):
            d = DescriptorMemoryElement("random", j)
            d.set_vector(numpy.random.rand(dim))
            td.append(d)

        ftor_train_hook(td)

        di = MemoryDescriptorIndex()
        index = LSHNearestNeighborIndex(hash_ftor, di, hash_idx, distance_method="euclidean")
        index.build_index(td)

        # test query from build set -- should return same descriptor when k=1
        q = td[255]
        r, dists = index.nn(q, 1)
        ntools.assert_equal(r[0], q)

        # test query very near a build vector
        td_q = td[0]
        q = DescriptorMemoryElement("query", i)
        v = td_q.vector().copy()
        v_min = max(v.min(), 0.1)
        v[0] += v_min
        v[dim - 1] -= v_min
        q.set_vector(v)
        r, dists = index.nn(q, 1)
        ntools.assert_false(numpy.array_equal(q.vector(), td_q.vector()))
        ntools.assert_equal(r[0], td_q)

        # random query
        q = DescriptorMemoryElement("query", i + 1)
        q.set_vector(numpy.random.rand(dim))

        # for any query of size k, results should at least be in distance order
        r, dists = index.nn(q, 10)
        for j in xrange(1, len(dists)):
            ntools.assert_greater(dists[j], dists[j - 1])
        r, dists = index.nn(q, i)
        for j in xrange(1, len(dists)):
            ntools.assert_greater(dists[j], dists[j - 1])

        DescriptorMemoryElement.MEMORY_CACHE = {}
开发者ID:liangkai,项目名称:SMQTK,代码行数:49,代码来源:test_NNI_lsh.py

示例8: test_random_descriptors_euclidean

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
    def test_random_descriptors_euclidean(self):
        # make random descriptors
        i = 1000
        dim = 256
        bits = 32
        td = []
        for j in xrange(i):
            d = DescriptorMemoryElement('random', j)
            d.set_vector(numpy.random.rand(dim))
            td.append(d)

        index = self._make_inst('euclidean', bits)
        index.build_index(td)

        # test query from build set -- should return same descriptor when k=1
        q = td[255]
        r, dists = index.nn(q, 1)
        ntools.assert_equal(r[0], q)

        # test query very near a build vector
        td_q = td[0]
        q = DescriptorMemoryElement('query', i)
        v = numpy.array(td_q.vector())  # copy
        v_min = max(v.min(), 0.1)
        v[0] += v_min
        v[dim-1] -= v_min
        q.set_vector(v)
        r, dists = index.nn(q, 1)
        ntools.assert_false(numpy.array_equal(q.vector(), td_q.vector()))
        ntools.assert_equal(r[0], td_q)

        # random query
        q = DescriptorMemoryElement('query', i+1)
        q.set_vector(numpy.random.rand(dim))

        # for any query of size k, results should at least be in distance order
        r, dists = index.nn(q, 10)
        for j in xrange(1, len(dists)):
            ntools.assert_greater(dists[j], dists[j-1])
        r, dists = index.nn(q, i)
        for j in xrange(1, len(dists)):
            ntools.assert_greater(dists[j], dists[j-1])
开发者ID:msarahan,项目名称:SMQTK,代码行数:44,代码来源:test_NNI_itq.py

示例9: test_known_descriptors_euclidean_ordered

# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import vector [as 别名]
        def test_known_descriptors_euclidean_ordered(self):
            index = self._make_inst('euclidean')

            # make vectors to return in a known euclidean distance order
            i = 10
            test_descriptors = []
            for j in xrange(i):
                d = DescriptorMemoryElement('ordered', j)
                d.set_vector(numpy.array([j, j*2], float))
                test_descriptors.append(d)
            random.shuffle(test_descriptors)
            index.build_index(test_descriptors)

            # Since descriptors were build in increasing distance from (0,0),
            # returned descriptors for a query of [0,0] should be in index order.
            q = DescriptorMemoryElement('query', 99)
            q.set_vector(numpy.array([0, 0], float))
            r, dists = index.nn(q, i)
            for j, d, dist in zip(range(i), r, dists):
                ntools.assert_equal(d.uuid(), j)
                numpy.testing.assert_equal(d.vector(), [j, j*2])
开发者ID:dhandeo,项目名称:SMQTK,代码行数:23,代码来源:test_NNI_FLANN.py


注:本文中的smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement.vector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。