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

Python composition.closure函数代码示例

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

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



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

示例1: test_multiplicative_replacement

    def test_multiplicative_replacement(self):
        amat = multiplicative_replacement(closure(self.data3))
        npt.assert_allclose(amat,
                            np.array([[0.087273, 0.174545, 0.261818,
                                       0.04, 0.436364],
                                      [0.092, 0.04, 0.04, 0.368, 0.46],
                                      [0.066667, 0.133333, 0.2,
                                       0.266667, 0.333333]]),
                            rtol=1e-5, atol=1e-5)

        amat = multiplicative_replacement(closure(self.data4))
        npt.assert_allclose(amat,
                            np.array([0.087273, 0.174545, 0.261818,
                                      0.04, 0.436364]),
                            rtol=1e-5, atol=1e-5)

        amat = multiplicative_replacement(closure(self.data6))
        npt.assert_allclose(amat,
                            np.array([[0.087273, 0.174545, 0.261818,
                                       0.04, 0.436364],
                                      [0.092, 0.04, 0.04, 0.368, 0.46],
                                      [0.066667, 0.133333, 0.2,
                                       0.266667, 0.333333]]),
                            rtol=1e-5, atol=1e-5)

        with self.assertRaises(ValueError):
            multiplicative_replacement(self.bad1)
        with self.assertRaises(ValueError):
            multiplicative_replacement(self.bad2)

        # make sure that inplace modification is not occurring
        multiplicative_replacement(self.data4)
        npt.assert_allclose(self.data4, np.array([1, 2, 3, 0, 5]))
开发者ID:7924102,项目名称:scikit-bio,代码行数:33,代码来源:test_composition.py


示例2: test_clr

    def test_clr(self):
        cmat = clr(closure(self.data1))
        A = np.array([.2, .2, .6])
        B = np.array([.4, .4, .2])

        npt.assert_allclose(cmat,
                            [np.log(A / np.exp(np.log(A).mean())),
                             np.log(B / np.exp(np.log(B).mean()))])
        cmat = clr(closure(self.data2))
        A = np.array([.2, .2, .6])
        npt.assert_allclose(cmat,
                            np.log(A / np.exp(np.log(A).mean())))

        cmat = clr(closure(self.data5))
        A = np.array([.2, .2, .6])
        B = np.array([.4, .4, .2])

        npt.assert_allclose(cmat,
                            [np.log(A / np.exp(np.log(A).mean())),
                             np.log(B / np.exp(np.log(B).mean()))])
        with self.assertRaises(ValueError):
            clr(self.bad1)
        with self.assertRaises(ValueError):
            clr(self.bad2)

        # make sure that inplace modification is not occurring
        clr(self.data2)
        npt.assert_allclose(self.data2, np.array([2, 2, 6]))
开发者ID:7924102,项目名称:scikit-bio,代码行数:28,代码来源:test_composition.py


示例3: test_closure_warning

    def test_closure_warning(self):
        with self.assertRaises(ValueError):
            closure([0., 0., 0.])

        with self.assertRaises(ValueError):
            closure([[0., 0., 0.],
                     [0., 5., 5.]])
开发者ID:disulfidebond,项目名称:scikit-bio,代码行数:7,代码来源:test_composition.py


示例4: setUp

    def setUp(self):
        data_dir = "../../data/tick/meshnick_tech_reps"
        biom_file = "%s/373_otu_table.biom" % data_dir
        meta_file = "%s/meta.txt" % data_dir

        table = load_table(biom_file)
        Z = 1
        mat = np.array(table._get_sparse_data().todense()).T
        x = np.ravel(mat[Z, :])
        self.tick_pvals = closure(np.array(x[x > 0]))
        self.uniform_pvals = closure(np.array([10000] * len(self.tick_pvals)))
        self.exponential_pvals = closure(np.exp(
            np.linspace(0, 4,len(self.tick_pvals))))
开发者ID:mortonjt,项目名称:benchmarkThis,代码行数:13,代码来源:test_coverage.py


示例5: test_permutative_f_scaled

    def test_permutative_f_scaled(self):

        test_table = pd.DataFrame(
            closure([[12, 11, 10, 10, 10, 10, 10],
                     [9,  11, 12, 10, 10, 10, 10],
                     [1,  11, 10, 11, 10, 5,  9],
                     [2,  11, 10, 11, 10, 5,  9],
                     [221, 210, 9,  10, 10, 10, 10],
                     [220, 210, 9,  10, 10, 10, 10],
                     [200, 220, 10, 10, 13, 10, 10],
                     [230, 210, 14, 10, 10, 10, 10]]),
            index=['s1', 's2', 's3', 's4',
                   's5', 's6',  's7', 's8'],
            columns=['b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7'])
        test_cats = pd.Series([0, 0, 0, 0, 1, 1, 1, 1],
                              index=['s1', 's2', 's3', 's4',
                                     's5', 's6',  's7', 's8'])

        np.random.seed(0)
        original_table = copy.deepcopy(test_table)
        original_cats = copy.deepcopy(test_cats)
        result = ancom(test_table, test_cats,
                       significance_test='permutative-anova')
        # Test to make sure that the input table hasn't be altered
        assert_data_frame_almost_equal(original_table, test_table)
        # Test to make sure that the input table hasn't be altered
        pdt.assert_series_equal(original_cats, test_cats)
        exp = pd.DataFrame({'W': np.array([5, 5, 2, 2, 2, 2, 2]),
                            'reject': np.array([True, True, False, False,
                                                False, False, False],
                                               dtype=bool)},
                           index=['b1', 'b2', 'b3', 'b4',
                                  'b5', 'b6', 'b7'])
        assert_data_frame_almost_equal(result, exp)
开发者ID:mortonjt,项目名称:canvas,代码行数:34,代码来源:test_ancom.py


示例6: test_exponential_uniform

 def test_exponential_uniform(self):
     samp_table = np.random.multinomial(n=500,
                                        pvals=self.exponential_pvals)
     bvals = brive(samp_table, replace_zeros=False)
     rel = closure(samp_table)
     m = bvals.sum()
     npt.assert_array_less(rel-bvals, 1.1/500)
     self.assertLess(m, 1 - robbins(samp_table))
开发者ID:mortonjt,项目名称:benchmarkThis,代码行数:8,代码来源:test_coverage.py


示例7: test_centralize

    def test_centralize(self):
        cmat = centralize(closure(self.data1))
        npt.assert_allclose(cmat,
                            np.array([[0.22474487, 0.22474487, 0.55051026],
                                      [0.41523958, 0.41523958, 0.16952085]]))
        cmat = centralize(closure(self.data5))
        npt.assert_allclose(cmat,
                            np.array([[0.22474487, 0.22474487, 0.55051026],
                                      [0.41523958, 0.41523958, 0.16952085]]))

        with self.assertRaises(ValueError):
            centralize(self.bad1)
        with self.assertRaises(ValueError):
            centralize(self.bad2)

        centralize(self.data1)
        npt.assert_allclose(self.data1,
                            np.array([[2, 2, 6],
                                      [4, 4, 2]]))
开发者ID:7924102,项目名称:scikit-bio,代码行数:19,代码来源:test_composition.py


示例8: test_power

    def test_power(self):
        pmat = power(closure(self.data1), 2)
        npt.assert_allclose(pmat,
                            np.array([[.04/.44, .04/.44, .36/.44],
                                      [.16/.36, .16/.36, .04/.36]]))

        pmat = power(closure(self.data2), 2)
        npt.assert_allclose(pmat, np.array([.04, .04, .36])/.44)

        pmat = power(closure(self.data5), 2)
        npt.assert_allclose(pmat,
                            np.array([[.04/.44, .04/.44, .36/.44],
                                      [.16/.36, .16/.36, .04/.36]]))

        with self.assertRaises(ValueError):
            power(self.bad1, 2)

        # make sure that inplace modification is not occurring
        power(self.data2, 4)
        npt.assert_allclose(self.data2, np.array([2, 2, 6]))
开发者ID:7924102,项目名称:scikit-bio,代码行数:20,代码来源:test_composition.py


示例9: test_centralize

    def test_centralize(self):
        cmat = centralize(closure(self.cdata1))
        npt.assert_allclose(cmat,
                            np.array([[0.22474487, 0.22474487, 0.55051026],
                                      [0.41523958, 0.41523958, 0.16952085]]))
        cmat = centralize(closure(self.cdata5))
        npt.assert_allclose(cmat,
                            np.array([[0.22474487, 0.22474487, 0.55051026],
                                      [0.41523958, 0.41523958, 0.16952085]]))

        with self.assertRaises(ValueError):
            centralize(self.bad1)
        with self.assertRaises(ValueError):
            centralize(self.bad2)

        # make sure that inplace modification is not occurring
        centralize(self.cdata1)
        npt.assert_allclose(self.cdata1,
                            np.array([[2, 2, 6],
                                      [4, 4, 2]]))
开发者ID:disulfidebond,项目名称:scikit-bio,代码行数:20,代码来源:test_composition.py


示例10: test_closure

    def test_closure(self):

        npt.assert_allclose(closure(self.data1),
                            np.array([[.2, .2, .6],
                                      [.4, .4, .2]]))
        npt.assert_allclose(closure(self.data2),
                            np.array([.2, .2, .6]))
        npt.assert_allclose(closure(self.data5),
                            np.array([[.2, .2, .6],
                                      [.4, .4, .2]]))
        with self.assertRaises(ValueError):
            closure(self.bad1)

        with self.assertRaises(ValueError):
            closure(self.bad2)

        # make sure that inplace modification is not occurring
        closure(self.data2)
        npt.assert_allclose(self.data2, np.array([2, 2, 6]))
开发者ID:7924102,项目名称:scikit-bio,代码行数:19,代码来源:test_composition.py


示例11: test_ilr_inv_basis

 def test_ilr_inv_basis(self):
     exp = closure(np.array([[1., 10.],
                             [1.14141414, 9.90909091],
                             [1.28282828, 9.81818182],
                             [1.42424242, 9.72727273],
                             [1.56565657, 9.63636364]]))
     basis = np.array([[0.80442968, 0.19557032]])
     table = np.array([[np.log(1/10)*np.sqrt(1/2),
                        np.log(1.14141414 / 9.90909091)*np.sqrt(1/2),
                        np.log(1.28282828 / 9.81818182)*np.sqrt(1/2),
                        np.log(1.42424242 / 9.72727273)*np.sqrt(1/2),
                        np.log(1.56565657 / 9.63636364)*np.sqrt(1/2)]]).T
     res = ilr_inv(table, basis=basis)
     npt.assert_allclose(res, exp)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:14,代码来源:test_composition.py


示例12: test_ilr_inv

    def test_ilr_inv(self):
        mat = closure(self.cdata7)
        npt.assert_array_almost_equal(ilr_inv(ilr(mat)), mat)

        npt.assert_allclose(ilr_inv(np.identity(3)), self.ortho1,
                            rtol=1e-04, atol=1e-06)

        with self.assertRaises(ValueError):
            ilr_inv(self.cdata1, basis=self.cdata1)

        # make sure that inplace modification is not occurring
        ilr_inv(self.cdata1)
        npt.assert_allclose(self.cdata1,
                            np.array([[2, 2, 6],
                                      [4, 4, 2]]))
开发者ID:disulfidebond,项目名称:scikit-bio,代码行数:15,代码来源:test_composition.py


示例13: test_ilr

    def test_ilr(self):
        mat = closure(self.cdata7)
        npt.assert_array_almost_equal(ilr(mat),
                                      np.array([0.70710678, 0.40824829]))

        # Should give same result as inner
        npt.assert_allclose(ilr(self.ortho1), np.identity(3),
                            rtol=1e-04, atol=1e-06)

        with self.assertRaises(ValueError):
            ilr(self.cdata1, basis=self.cdata1)

        # make sure that inplace modification is not occurring
        ilr(self.cdata1)
        npt.assert_allclose(self.cdata1,
                            np.array([[2, 2, 6],
                                      [4, 4, 2]]))
开发者ID:disulfidebond,项目名称:scikit-bio,代码行数:17,代码来源:test_composition.py


示例14: test_ancom_basic_proportions

 def test_ancom_basic_proportions(self):
     # Converts from counts to proportions
     test_table = pd.DataFrame(closure(self.table1))
     original_table = copy.deepcopy(test_table)
     test_cats = pd.Series(self.cats1)
     original_cats = copy.deepcopy(test_cats)
     result = ancom(test_table,
                    test_cats,
                    multiple_comparisons_correction=None)
     # Test to make sure that the input table hasn't be altered
     assert_data_frame_almost_equal(original_table, test_table)
     # Test to make sure that the input table hasn't be altered
     pdt.assert_series_equal(original_cats, test_cats)
     exp = pd.DataFrame({'W': np.array([5, 5, 2, 2, 2, 2, 2]),
                         'reject': np.array([True, True, False, False,
                                             False, False, False],
                                            dtype=bool)})
     assert_data_frame_almost_equal(result, exp)
开发者ID:mortonjt,项目名称:canvas,代码行数:18,代码来源:test_ancom.py


示例15: split_balance

def split_balance(balance, tree):
    """ Splits a balance into its log ratio components.

    Parameters
    ----------
    balance : pd.Series
        A vector corresponding to a single balance.  These values
        that will be split into its numberator and denominator
        components.

    Returns
    -------
    pd.DataFrame
        Dataframe where the first column contains the numerator and the
        second column contains the denominator of the balance.

    Note
    ----
    The balance must have a name associated with it.
    """
    node = tree.find(balance.name)

    if node.is_tip():
        raise ValueError("%s is not a balance." % balance.name)

    left = node.children[0]
    right = node.children[1]
    if left.is_tip():
        L = 1
    else:
        L = len([n for n in left.tips()])
    if right.is_tip():
        R = 1
    else:
        R = len([n for n in right.tips()])
    b = np.expand_dims(balance.values, axis=1)
    # need to scale down by the number of children in subtrees
    b = np.exp(b / (np.sqrt((L*R) / (L + R))))
    o = np.ones((len(b), 1))
    k = np.hstack((b, o))
    p = closure(k)
    return pd.DataFrame(p, columns=[left.name, right.name],
                        index=balance.index)
开发者ID:biocore,项目名称:gneiss,代码行数:43,代码来源:util.py


示例16: test_ilr_basis_isomorphism

    def test_ilr_basis_isomorphism(self):
        # tests to make sure that the isomorphism holds
        # with the introduction of the basis.
        basis = np.array([[0.80442968, 0.19557032]])
        table = np.array([[np.log(1/10)*np.sqrt(1/2),
                           np.log(1.14141414 / 9.90909091)*np.sqrt(1/2),
                           np.log(1.28282828 / 9.81818182)*np.sqrt(1/2),
                           np.log(1.42424242 / 9.72727273)*np.sqrt(1/2),
                           np.log(1.56565657 / 9.63636364)*np.sqrt(1/2)]]).T
        res = ilr(ilr_inv(table, basis=basis), basis=basis)
        npt.assert_allclose(res, table.squeeze())

        table = np.array([[1., 10.],
                          [1.14141414, 9.90909091],
                          [1.28282828, 9.81818182],
                          [1.42424242, 9.72727273],
                          [1.56565657, 9.63636364]])

        res = ilr_inv(np.atleast_2d(ilr(table, basis=basis)).T, basis=basis)
        npt.assert_allclose(res, closure(table.squeeze()))
开发者ID:RNAer,项目名称:scikit-bio,代码行数:20,代码来源:test_composition.py


示例17: variation_matrix

def variation_matrix(X):
    """ Calculate Aitchison variation matrix.

    This calculates the Aitchison variation matrix.  Given a compositional
    matrix :math:`X`, and columns :math:`i` and :math:`j`, the :math:`ij` entry
    in the variation matrix of :math:`X` is given by

    .. math:
        V_{ij} = \frac{1}{2} var(\ln \frac{x_i}{x_j})

    Parameters
    ----------
    X : pd.DataFrame
        Contingency table where there are n rows corresponding to samples
        and p features corresponding to columns.

    Returns
    -------
    skbio.DistanceMatrix
        Total variation matrix of size n x n.

    References
    ----------
    .. [1] V. Pawlowsky-Glahn, J. J. Egozcue, R. Tolosana-Delgado (2015),
       Modeling and Analysis of Compositional Data, Wiley, Chichester, UK

    .. [2] J. J. Egozcue, V. Pawlowsky-Glahn (2004), Groups of Parts and
       Their Balances in Compositional Data Analysis, Mathematical Geology
    """
    v = np.zeros((X.shape[1], X.shape[1]))
    x = closure(X)
    for i in range(X.shape[1]):
        for j in range(i):
            v[i, j] = np.var(np.log(x[:, i]) - np.log(x[:, j]))
    # Making matrix symmetry since V(ln (x/y) ) = V(ln (y/x) )
    # Also dividing by 2, to ensure unit norm for balances.
    # See Eqn 4 in [2]
    return DistanceMatrix((v + v.T) / 2, ids=X.columns)
开发者ID:biocore,项目名称:gneiss,代码行数:38,代码来源:_variance.py


示例18: test_perturb

    def test_perturb(self):
        pmat = perturb(closure(self.data1),
                       closure(np.array([1, 1, 1])))
        npt.assert_allclose(pmat,
                            np.array([[.2, .2, .6],
                                      [.4, .4, .2]]))

        pmat = perturb(closure(self.data1),
                       closure(np.array([10, 10, 20])))
        npt.assert_allclose(pmat,
                            np.array([[.125, .125, .75],
                                      [1./3, 1./3, 1./3]]))

        pmat = perturb(closure(self.data1),
                       closure(np.array([10, 10, 20])))
        npt.assert_allclose(pmat,
                            np.array([[.125, .125, .75],
                                      [1./3, 1./3, 1./3]]))

        pmat = perturb(closure(self.data2),
                       closure([1, 2, 1]))
        npt.assert_allclose(pmat, np.array([1./6, 2./6, 3./6]))

        pmat = perturb(closure(self.data5),
                       closure(np.array([1, 1, 1])))
        npt.assert_allclose(pmat,
                            np.array([[.2, .2, .6],
                                      [.4, .4, .2]]))

        with self.assertRaises(ValueError):
            perturb(closure(self.data5), self.bad1)

        # make sure that inplace modification is not occurring
        perturb(self.data2, [1, 2, 3])
        npt.assert_allclose(self.data2, np.array([2, 2, 6]))
开发者ID:7924102,项目名称:scikit-bio,代码行数:35,代码来源:test_composition.py


示例19: test_perturb_inv

    def test_perturb_inv(self):
        pmat = perturb_inv(closure(self.data1),
                           closure([.1, .1, .1]))
        imat = perturb(closure(self.data1),
                       closure([10, 10, 10]))
        npt.assert_allclose(pmat, imat)
        pmat = perturb_inv(closure(self.data1),
                           closure([1, 1, 1]))
        npt.assert_allclose(pmat,
                            closure([[.2, .2, .6],
                                     [.4, .4, .2]]))
        pmat = perturb_inv(closure(self.data5),
                           closure([.1, .1, .1]))
        imat = perturb(closure(self.data1), closure([10, 10, 10]))
        npt.assert_allclose(pmat, imat)

        with self.assertRaises(ValueError):
            perturb_inv(closure(self.data1), self.bad1)

        # make sure that inplace modification is not occurring
        perturb_inv(self.data2, [1, 2, 3])
        npt.assert_allclose(self.data2, np.array([2, 2, 6]))
开发者ID:7924102,项目名称:scikit-bio,代码行数:22,代码来源:test_composition.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python distance.mantel函数代码示例发布时间:2022-05-27
下一篇:
Python composition.ancom函数代码示例发布时间: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