當前位置: 首頁>>代碼示例>>Python>>正文


Python random.binomial方法代碼示例

本文整理匯總了Python中numpy.random.binomial方法的典型用法代碼示例。如果您正苦於以下問題:Python random.binomial方法的具體用法?Python random.binomial怎麽用?Python random.binomial使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.random的用法示例。


在下文中一共展示了random.binomial方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_binomial

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def test_binomial(self):
        n = [1]
        p = [0.5]
        bad_n = [-1]
        bad_p_one = [-1]
        bad_p_two = [1.5]
        binom = np.random.binomial
        desired = np.array([1, 1, 1])

        self.setSeed()
        actual = binom(n * 3, p)
        assert_array_equal(actual, desired)
        assert_raises(ValueError, binom, bad_n * 3, p)
        assert_raises(ValueError, binom, n * 3, bad_p_one)
        assert_raises(ValueError, binom, n * 3, bad_p_two)

        self.setSeed()
        actual = binom(n, p * 3)
        assert_array_equal(actual, desired)
        assert_raises(ValueError, binom, bad_n, p * 3)
        assert_raises(ValueError, binom, n, bad_p_one * 3)
        assert_raises(ValueError, binom, n, bad_p_two * 3) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_random.py

示例2: get_example_data

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def get_example_data(*, sparse=False):
    # create test object
    adata = AnnData(np.multiply(binomial(1, 0.15, (100, 20)), negative_binomial(2, 0.25, (100, 20))))
    # adapt marker_genes for cluster (so as to have some form of reasonable input
    adata.X[0:10, 0:5] = np.multiply(binomial(1, 0.9, (10, 5)), negative_binomial(1, 0.5, (10, 5)))

    # The following construction is inefficient, but makes sure that the same data is used in the sparse case
    if sparse:
        adata.X = sp.csr_matrix(adata.X)

    # Create cluster according to groups
    adata.obs['true_groups'] = pd.Categorical(np.concatenate((
        np.zeros((10,), dtype=int),
        np.ones((90,), dtype=int),
    )))

    return adata 
開發者ID:theislab,項目名稱:scanpy,代碼行數:19,代碼來源:test_rank_genes_groups.py

示例3: sample_binomial_frag_len

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def sample_binomial_frag_len(frag_mean=200, frag_variance=100):
    """
    Sample a fragment length from a binomial distribution parameterized with a
    mean and variance.

    If frag_variance > frag_mean, use a Negative-Binomial distribution.
    """
    assert(abs(frag_mean - frag_variance) > 1)  
    if frag_variance < frag_mean:
	p = 1 - (frag_variance/float(frag_mean))
	# N = mu/(1-(sigma^2/mu))
	n = float(frag_mean) / (1 - (float(frag_variance)/float(frag_mean)))
	return binomial(n, p)
    else:
	r = -1 * (power(frag_mean, 2)/float(frag_mean - frag_variance))
	p = frag_mean / float(frag_variance)
	print "Sampling frag_mean=",frag_mean, " frag_variance=", frag_variance
	print "r: ",r, "  p: ", p
	return negative_binomial(r, p) 
開發者ID:Xinglab,項目名稱:rmats2sashimiplot,代碼行數:21,代碼來源:read_simulator.py

示例4: test_n_zero

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def test_n_zero(self):
        # Tests the corner case of n == 0 for the binomial distribution.
        # binomial(0, p) should be zero for any p in [0, 1].
        # This test addresses issue #3480.
        zeros = np.zeros(2, dtype='int')
        for p in [0, .5, 1]:
            assert_(random.binomial(0, p) == 0)
            assert_array_equal(random.binomial(zeros, p), zeros) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_random.py

示例5: test_p_is_nan

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def test_p_is_nan(self):
        # Issue #4571.
        assert_raises(ValueError, random.binomial, 1, np.nan) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:test_random.py

示例6: test_negative_binomial

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def test_negative_binomial(self):
        # Ensure that the negative binomial results take floating point
        # arguments without truncation.
        self.prng.negative_binomial(0.5, 0.5) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:test_random.py

示例7: test_n_zero

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def test_n_zero(self):
        # Tests the corner case of n == 0 for the binomial distribution.
        # binomial(0, p) should be zero for any p in [0, 1].
        # This test addresses issue #3480.
        zeros = np.zeros(2, dtype='int')
        for p in [0, .5, 1]:
            assert_(random.binomial(0, p) == 0)
            np.testing.assert_array_equal(random.binomial(zeros, p), zeros) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:10,代碼來源:test_random.py

示例8: test_binomial

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def test_binomial(self):
        np.random.seed(self.seed)
        actual = np.random.binomial(100.123, .456, size=(3, 2))
        desired = np.array([[37, 43],
                         [42, 48],
                         [46, 45]])
        np.testing.assert_array_equal(actual, desired) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:9,代碼來源:test_random.py

示例9: flip

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def flip(p):
  return random.binomial(1, p) 
開發者ID:vladfi1,項目名稱:gym-dolphin,代碼行數:4,代碼來源:util.py

示例10: test_negative_binomial

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import binomial [as 別名]
def test_negative_binomial(self):
        """ Ensure that the negative binomial results take floating point
        arguments without truncation.
        """
        self.prng.negative_binomial(0.5, 0.5) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:test_random.py


注:本文中的numpy.random.binomial方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。