Assume I have a distribution governing the possible outcome from a single random variable X.
This is something like [0.1, 0.4, 0.2, 0.3] for X being a value of either 1, 2, 3, 4.
Is it possible to sample from this distribution, i.e. generate pseudo random numbers upon each of the possible outcomes given the probability of that outcome. So if I wanted to know what the probability of getting a 2 is, the sampling operation may return 0.34 or something like that.
The reason I ask is that I'm trying to implement an action selection policy for a reinforcement learning method based on a research paper. From what I gather from the paper, the author is able to sample the distribution by "mapping the uniform distribution U[0,1] through cumulative probability density functions obtained by adaptive numerical integration". From this he then samples the transition probabilities for each trial…
I would be grateful for any info on this…
Thanks in advance
Best Answer
Sure. Here's an R function that will sample from that distribution
n
times, with replacement:If you want to go a little lower level, you can see the actual algorithm used by checking out the R source (written in C):