由买买提看人间百态

topics

全部话题 - 话题: bernolli
(共0页)
f***a
发帖数: 329
1
来自主题: Statistics版 - 问个面试问题
Here you are. coded in R. It is easy to read and get the idea directly from
the code. Have fun!
###############
n <- 10 # how many Bernolli variables
m <- 6 # how many "1"s you want
nout <- 100 # how many such samples you want
p <- runif(n) # pre-specified probability of Bernolli variables
pp <- p/sum(p)
out <- matrix(0,nout,n)
for(irun in 1:nout)
{
ind <- numeric(m)
iter <- 1
while(iter<=m)
{
res <- sum(runif(1) > cumsum(pp))+1
if(!(res %in% ind)) {ind[iter] <- res; iter <- iter+1}
}
out[irun,i... 阅读全帖
p*********g
发帖数: 226
2
来自主题: Statistics版 - 问个面试问题
俺先确认对你的算法理解正确:
S = empty
loop until |S| = m
sample i with prob pi / sum_{j=1}^n p_j
if i is not in S
add i to S
end
end
return S

n <- 10 # how many Bernolli variables
m <- 6 # how many "1"s you want
nout <- 100 # how many such samples you want
p <- runif(n) # pre-specified probability of Bernolli variables
pp <- p/sum(p)
out <- matrix(0,nout,n)
for(irun in 1:nout)
{
ind <- numeric(m)
iter <- 1
while(iter<=m)
{
res <- sum(runif(1) > cumsum(pp))+1
if(!(res %in% ind)) {ind[iter] <- ... 阅读全帖
f***a
发帖数: 329
3
来自主题: Statistics版 - 问个面试问题
回来了回来了。
重新想了下,这个其实就是在一堆iid variables之间加了一个constraint。貌似
sample起来不难。
以最简单的n=2,m=1为例:
Without constraint, outputs space is {(0,0),(0,1),(1,0),(1,1)}.
The corresponding probability space is {(1-p1)*(1-p2), ..., p1*p2}.
With constraint, outputs space is O={(0,1),(1,0)}.
The corresponding probability space is P={(1-p1)*(p2), p1*(1-p2)}.
Under the constrain, standardize the probability space into
P.std={P1/(P1+P2),P2/(P1+P2)}.
Then under constrain, output (0,1) has the probability P1/(P1+P2) to be
sam... 阅读全帖
f***a
发帖数: 329
4
来自主题: Statistics版 - 问个面试问题
Here you are. coded in R. It is easy to read and get the idea directly from
the code. Have fun!
###############
n <- 10 # how many Bernolli variables
m <- 6 # how many "1"s you want
nout <- 100 # how many such samples you want
p <- runif(n) # pre-specified probability of Bernolli variables
pp <- p/sum(p)
out <- matrix(0,nout,n)
for(irun in 1:nout)
{
ind <- numeric(m)
iter <- 1
while(iter<=m)
{
res <- sum(runif(1) > cumsum(pp))+1
if(!(res %in% ind)) {ind[iter] <- res; iter <- iter+1}
}
out[irun,i... 阅读全帖
p*********g
发帖数: 226
5
来自主题: Statistics版 - 问个面试问题
俺先确认对你的算法理解正确:
S = empty
loop until |S| = m
sample i with prob pi / sum_{j=1}^n p_j
if i is not in S
add i to S
end
end
return S

n <- 10 # how many Bernolli variables
m <- 6 # how many "1"s you want
nout <- 100 # how many such samples you want
p <- runif(n) # pre-specified probability of Bernolli variables
pp <- p/sum(p)
out <- matrix(0,nout,n)
for(irun in 1:nout)
{
ind <- numeric(m)
iter <- 1
while(iter<=m)
{
res <- sum(runif(1) > cumsum(pp))+1
if(!(res %in% ind)) {ind[iter] <- ... 阅读全帖
f***a
发帖数: 329
6
来自主题: Statistics版 - 问个面试问题
回来了回来了。
重新想了下,这个其实就是在一堆iid variables之间加了一个constraint。貌似
sample起来不难。
以最简单的n=2,m=1为例:
Without constraint, outputs space is {(0,0),(0,1),(1,0),(1,1)}.
The corresponding probability space is {(1-p1)*(1-p2), ..., p1*p2}.
With constraint, outputs space is O={(0,1),(1,0)}.
The corresponding probability space is P={(1-p1)*(p2), p1*(1-p2)}.
Under the constrain, standardize the probability space into
P.std={P1/(P1+P2),P2/(P1+P2)}.
Then under constrain, output (0,1) has the probability P1/(P1+P2) to be
sam... 阅读全帖
n*****a
发帖数: 64
7
来自主题: Environmental版 - 请教一个hydraulic方面的问题
if the total pressure (P0) is specified (such as a flow discharged from a
big tank), and if the flow rate (V) in the tunnel is also known (while
usually these two conditions are not given at same time, but the maximum
flow rate should be known anyway), then the tunnel outlet height where
tunnel becomes partially filled can be determined simply by bernolli
equation: P0=rho*V^2/2+rho*g*H+Patm,
Similarly, plugging Vmax in the equation, the lowest possible elevation can
be determined.
See "Siphon Wi
p*********g
发帖数: 226
8
来自主题: Statistics版 - 简单问题求助
有 n 个独立的 Bernolli 随机变量 x_i. p(x_i=1) = a_i. 现要他们和的分布(即和
为0,1,...,n的概率)。有没有复杂度为O(n)的线性算法?递归需要O(n^2).
多谢。
p*********g
发帖数: 226
9
来自主题: Statistics版 - 问个面试问题
给了 n 个独立的 Bernolli 随机变量X_i,p(X_i = 1) = p_i. 现要采样(X_1, ...,
X_n) 使得它们的和为 m (m <=n). 如何高效地采样?
当然规定了和之后,它们就不再独立了。
简单的方法:独立采样所有 X_i, 如果和不为m,扔掉,重新采。当然效率太低了。
p*********g
发帖数: 226
10
来自主题: Statistics版 - 问个面试问题
给了 n 个独立的 Bernolli 随机变量X_i,p(X_i = 1) = p_i. 现要采样(X_1, ...,
X_n) 使得它们的和为 m (m <=n). 如何高效地采样?
当然规定了和之后,它们就不再独立了。
简单的方法:独立采样所有 X_i, 如果和不为m,扔掉,重新采。当然效率太低了。
(共0页)