I am looking to sample a binomial distribution dependent on an exponential distribution. I would like to use different parameters for each binomial random sampling dependent upon the output of the exponential distribution, for each independent sample taken.
An example is shown below, where the binomial probability depends on the output of the exponential distribution:
import scipy.stats as stats
import numpy as np
a = np.array(stats.expon.rvs(size=1000))
b = np.array(
[
stats.binom.rvs(
n=1,
p=(np.exp(-_a/5)), size=1
)
for _a in a
]
)
This is, however, very slow indeed, as I am sampling once in a loop for a thousand iterations.
I have attempted a solution using vectors by implementing the example below.
b = np.array(stats.binom.rvs(
n=np.ones(1000).astype(int),
p=(np.exp(a/5)),
size=1000
)
)
Firstly, is my attempt correct?
If this it is not, what other solutions do I have to be able to achieve what I want?
Aucun commentaire:
Enregistrer un commentaire