In my case I'm trying to generate an array of independent Bernoulli r.v.s
where the parameter for each Bernoulli is given in an array p. In R, I'd do
rbinom(length(p),
1, p). It looks like the Distributions package does not support this sort
of thing. I have a few solutions to my particular problem shown at the
bottom of this message but I'm curious about the best way to do this in
general.
Is this something the Distributions package will support in the future or
is there a better/built in way to do this? It seems to me that it would
come up frequently and having to write a function to vectorize it every
time is a pain.
Sam
#Some solutions
rbern(p) = rand(Bernoulli(p))
@vectorize_1arg Real rbern
type RandBernoulli <: Functor{1} end
NumericExtensions.evaluate(::RandBernoulli, p) = rbern(p) #then map
rbern2(p) = int(rand(length(p)) .< p)