3

I have a list of numbers, and would like to sample from that list. The sampling however is based on some distribution which is specified by a user. I am not sure if alias method (here) using weights is the right one; my limited knowledge says alias method uses uniform distribution alone (correct me on that please!). What if I need to specify something like sample using log-normal as the underlying distribution or poisson for that matter? How do I do this kind of sampling?

A related question, if my list is say [1, 2, 3, 4, 5] and mean is 3, how do I get the sampling?

Community
  • 1
  • 1
okkhoy
  • 1,298
  • 3
  • 16
  • 29

2 Answers2

2

Have you tried np.random.choice

b = np.random.choice(a=[1,2,3,4,5], p=[0.2, 0.2, 0.2, 0.2, 0.2])

b is randomly sampled from a based on the distribution p

You can also use poisson

Kenan
  • 13,156
  • 8
  • 43
  • 50
0

You can use bunch of numpy functions from here:

http://docs.scipy.org/doc/numpy/reference/routines.random.html

Standard python random library does not provide various distrubutions RNG. And yes, default one is an uniform.

soupault
  • 6,089
  • 4
  • 24
  • 35
  • 1
    thanks! that is a link to the documentation; but that link is not really useful in answering my question! – okkhoy Jun 24 '14 at 06:49
  • Well, so far almost every distribution density function in infinite, you should set some bound. Lets say, set bounds on 99% of density function area, and use kind of saturation. Then, you can enumerate your list, and make indexes range fit your distribution bounds. So, it becomes trivial now. Are you asking for this? – soupault Jun 25 '14 at 08:19
  • 1
    can you give an example so that I can understand your explanation better? thanks again! – okkhoy Jun 25 '14 at 11:04