簡體   English   中英

從貝茨分布生成隨機數

[英]Generate random number from Bates distribution

簡單介紹一下,貝茨分布定義為均勻分布的平均隨機數。

我面臨的問題是從具有大 m 和 n 的 Bates 分布生成隨機數。

使用大的 m 和 n(例如 m=10000 和 n=10000000)時會消耗時間(非常慢),而我只是直接使用模擬均勻分布的隨機數然后取其平均值來生成隨機數。

python代碼如下

a = np.random.uniform(0, 1, size = (m, n)) 
bates_random_numbers = [np.mean(a[i]) for i in range(m)]

其中 m 是樣本數,n 是樣本大小

我們是否有機會從貝茨分布中生成隨機數,避免直接模擬均勻分布?

任何建議表示贊賞!

使用 TensorFlow,從貝茨分布生成隨機數的代碼可以很容易地寫成

import tensorflow as tf
import tensorflow_probability as tfp

# For example
m = 10000 # m is the number of samples

n1, n2 = 50, 100000 # n1, n2 are the number of used uniform distribution [0, 1] respectively

a = np.array(tfp.distributions.Bates(total_count=[n1, n2]).sample(m))
transposed = [list(i) for i in zip(*a)]

# Then we have the final two lists of random numbers from Bates distribution with n1 and n2.
bates_random_numbers_n1 = transposed[0] 
bates_random_numbers_n2 = transposed[1]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM