• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python _vq.vq函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scipy.cluster._vq.vq函数的典型用法代码示例。如果您正苦于以下问题:Python vq函数的具体用法?Python vq怎么用?Python vq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_vq_large_nfeat

    def test_vq_large_nfeat(self):
        X = np.random.rand(20, 20)
        code_book = np.random.rand(3, 20)

        codes0, dis0 = _vq.vq(X, code_book)
        codes1, dis1 = py_vq(X, code_book)
        assert_allclose(dis0, dis1, 1e-5)
        assert_array_equal(codes0, codes1)

        X = X.astype(np.float32)
        code_book = code_book.astype(np.float32)

        codes0, dis0 = _vq.vq(X, code_book)
        codes1, dis1 = py_vq(X, code_book)
        assert_allclose(dis0, dis1, 1e-5)
        assert_array_equal(codes0, codes1)
开发者ID:Benj1,项目名称:scipy,代码行数:16,代码来源:test_vq.py


示例2: test_vq

 def test_vq(self):
     initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
     if TESTC:
         label1, dist = _vq.vq(X, initc)
         assert_array_equal(label1, LABEL1)
         tlabel1, tdist = vq(X, initc)
     else:
         print("== not testing C imp of vq ==")
开发者ID:beiko-lab,项目名称:gengis,代码行数:8,代码来源:test_vq.py


示例3: test_vq_1d

 def test_vq_1d(self):
     """Test special rank 1 vq algo, python implementation."""
     data = X[:, 0]
     initc = data[:3]
     a, b = _vq.vq(data, initc)
     ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis])
     assert_array_equal(a, ta)
     assert_array_equal(b, tb)
开发者ID:Benj1,项目名称:scipy,代码行数:8,代码来源:test_vq.py


示例4: test_vq_large_features

    def test_vq_large_features(self):
        X = np.random.rand(10, 5) * 1000000
        code_book = np.random.rand(2, 5) * 1000000

        codes0, dis0 = _vq.vq(X, code_book)
        codes1, dis1 = py_vq(X, code_book)
        assert_allclose(dis0, dis1, 1e-5)
        assert_array_equal(codes0, codes1)
开发者ID:Benj1,项目名称:scipy,代码行数:8,代码来源:test_vq.py


示例5: test_vq_1d

 def test_vq_1d(self):
     """Test special rank 1 vq algo, python implementation."""
     data = X[:, 0]
     initc = data[:3]
     if TESTC:
         a, b = _vq.vq(data, initc)
         ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis])
         assert_array_equal(a, ta)
         assert_array_equal(b, tb)
     else:
         print("== not testing C imp of vq (rank 1) ==")
开发者ID:beiko-lab,项目名称:gengis,代码行数:11,代码来源:test_vq.py


示例6: test_vq

 def test_vq(self):
     initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
     label1, dist = _vq.vq(X, initc)
     assert_array_equal(label1, LABEL1)
     tlabel1, tdist = vq(X, initc)
开发者ID:Benj1,项目名称:scipy,代码行数:5,代码来源:test_vq.py


示例7: test_vq

 def test_vq(self):
     initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
     for tp in np.array, np.matrix:
         label1, dist = _vq.vq(tp(X), tp(initc))
         assert_array_equal(label1, LABEL1)
         tlabel1, tdist = vq(tp(X), tp(initc))
开发者ID:dyao-vu,项目名称:meta-core,代码行数:6,代码来源:test_vq.py


示例8: vq

def vq(obs, code_book, check_finite=True):
    """
    Assign codes from a code book to observations.

    Assigns a code from a code book to each observation. Each
    observation vector in the 'M' by 'N' `obs` array is compared with the
    centroids in the code book and assigned the code of the closest
    centroid.

    The features in `obs` should have unit variance, which can be
    achieved by passing them through the whiten function.  The code
    book can be created with the k-means algorithm or a different
    encoding algorithm.

    Parameters
    ----------
    obs : ndarray
        Each row of the 'M' x 'N' array is an observation.  The columns are
        the "features" seen during each observation. The features must be
        whitened first using the whiten function or something equivalent.
    code_book : ndarray
        The code book is usually generated using the k-means algorithm.
        Each row of the array holds a different code, and the columns are
        the features of the code.

         >>> #              f0    f1    f2   f3
         >>> code_book = [
         ...             [  1.,   2.,   3.,   4.],  #c0
         ...             [  1.,   2.,   3.,   4.],  #c1
         ...             [  1.,   2.,   3.,   4.]]  #c2

    check_finite : bool, optional
        Whether to check that the input matrices contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.
        Default: True

    Returns
    -------
    code : ndarray
        A length M array holding the code book index for each observation.
    dist : ndarray
        The distortion (distance) between the observation and its nearest
        code.

    Examples
    --------
    >>> from numpy import array
    >>> from scipy.cluster.vq import vq
    >>> code_book = array([[1.,1.,1.],
    ...                    [2.,2.,2.]])
    >>> features  = array([[  1.9,2.3,1.7],
    ...                    [  1.5,2.5,2.2],
    ...                    [  0.8,0.6,1.7]])
    >>> vq(features,code_book)
    (array([1, 1, 0],'i'), array([ 0.43588989,  0.73484692,  0.83066239]))

    """
    obs = _asarray_validated(obs, check_finite=check_finite)
    code_book = _asarray_validated(code_book, check_finite=check_finite)
    ct = common_type(obs, code_book)

    # avoid copying when dtype is the same
    # should be replaced with c_obs = astype(ct, copy=False)
    # when we get to numpy 1.7.0
    if obs.dtype != ct:
        c_obs = obs.astype(ct)
    else:
        c_obs = obs

    if code_book.dtype != ct:
        c_code_book = code_book.astype(ct)
    else:
        c_code_book = code_book

    if ct in (single, double):
        results = _vq.vq(c_obs, c_code_book)
    else:
        results = py_vq(obs, code_book)
    return results
开发者ID:archonren,项目名称:similarity,代码行数:80,代码来源:scivq.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python hierarchy.cophenet函数代码示例发布时间:2022-05-27
下一篇:
Python cluster.vq函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap