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


Python random.multinomial方法代碼示例

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


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

示例1: draw_links

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def draw_links(self,n=1,log_sampling=False):
        """ Draw multiple random links. """
        urls = []
        domain_array = np.array([dmn for dmn in self.domain_links])
        domain_count = np.array([len(self.domain_links[domain_array[k]]) for k in range(domain_array.shape[0])])
        p = np.array([np.float(c) for c in domain_count])
        count_total = p.sum()
        if log_sampling:  # log-sampling [log(x+1)] to bias lower count domains
            p = np.fromiter((np.log1p(x) for x in p), dtype=p.dtype)
        if count_total > 0:
            p = p/p.sum()
            cnts = npr.multinomial(n, pvals=p)
            if n > 1:
                for k in range(cnts.shape[0]):
                    domain = domain_array[k]
                    cnt = min(cnts[k],domain_count[k])
                    for url in random.sample(self.domain_links[domain],cnt):
                        urls.append(url)
            else:
                k = int(np.nonzero(cnts)[0])
                domain = domain_array[k]
                url = random.sample(self.domain_links[domain],1)[0]
                urls.append(url)
        return urls 
開發者ID:essandess,項目名稱:isp-data-pollution,代碼行數:26,代碼來源:isp_data_pollution.py

示例2: test_basic

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def test_basic(self):
        random.multinomial(100, [0.2, 0.8]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_random.py

示例3: test_zero_probability

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def test_zero_probability(self):
        random.multinomial(100, [0.2, 0.8, 0.0, 0.0, 0.0]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_random.py

示例4: test_size

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def test_size(self):
        # gh-3173
        p = [0.5, 0.5]
        assert_equal(np.random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
        assert_equal(np.random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
        assert_equal(np.random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
        assert_equal(np.random.multinomial(1, p, [2, 2]).shape, (2, 2, 2))
        assert_equal(np.random.multinomial(1, p, (2, 2)).shape, (2, 2, 2))
        assert_equal(np.random.multinomial(1, p, np.array((2, 2))).shape,
                     (2, 2, 2))

        assert_raises(TypeError, np.random.multinomial, 1, p,
                      float(1)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_random.py

示例5: test_multinomial

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def test_multinomial(self):
        np.random.seed(self.seed)
        actual = np.random.multinomial(20, [1/6.]*6, size=(3, 2))
        desired = np.array([[[4, 3, 5, 4, 2, 2],
                             [5, 2, 8, 2, 2, 1]],
                            [[3, 4, 3, 6, 0, 4],
                             [2, 1, 4, 3, 6, 4]],
                            [[4, 4, 2, 5, 2, 3],
                             [4, 3, 4, 2, 3, 4]]])
        assert_array_equal(actual, desired) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_random.py

示例6: test_size

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def test_size(self):
        # gh-3173
        p = [0.5, 0.5]
        assert_equal(np.random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
        assert_equal(np.random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
        assert_equal(np.random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
        assert_equal(np.random.multinomial(1, p, [2, 2]).shape, (2, 2, 2))
        assert_equal(np.random.multinomial(1, p, (2, 2)).shape, (2, 2, 2))
        assert_equal(np.random.multinomial(1, p, np.array((2, 2))).shape,
                     (2, 2, 2))

        assert_raises(TypeError, np.random.multinomial, 1, p,
                      np.float(1)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:15,代碼來源:test_random.py

示例7: test_multinomial

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def test_multinomial(self):
        np.random.seed(self.seed)
        actual = np.random.multinomial(20, [1/6.]*6, size=(3, 2))
        desired = np.array([[[4, 3, 5, 4, 2, 2],
                             [5, 2, 8, 2, 2, 1]],
                            [[3, 4, 3, 6, 0, 4],
                             [2, 1, 4, 3, 6, 4]],
                            [[4, 4, 2, 5, 2, 3],
                             [4, 3, 4, 2, 3, 4]]])
        np.testing.assert_array_equal(actual, desired) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:12,代碼來源:test_random.py

示例8: test_multinomial

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import multinomial [as 別名]
def test_multinomial(self):
        np.random.seed(self.seed)
        actual = np.random.multinomial(20, [1/6.]*6, size=(3, 2))
        desired = np.array([[[4, 3, 5, 4, 2, 2],
                          [5, 2, 8, 2, 2, 1]],
                         [[3, 4, 3, 6, 0, 4],
                          [2, 1, 4, 3, 6, 4]],
                         [[4, 4, 2, 5, 2, 3],
                          [4, 3, 4, 2, 3, 4]]])
        np.testing.assert_array_equal(actual, desired) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:test_random.py


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