python - How to write a sampling algorithm from a custom distribution? -
i'm generating random galaxies line of sight velocities drawn normal distribution, , random positions 2d gaussian. little more physical draw these positions nfw profile given by:
rho(r) = rho_0/(r/r_s*(1+r/r_s)^2
where rho_0
, r_s
constant parameters.
how can write algorithm sample distribution ?
basically i'm trying plop down couple hundred galaxies follow density distribution.
i've been using numpy.random.normal
sample gaussians, i'd sample nfw profile rather gaussians. i'm sure stats training place start, point in right direction helpful , appreciated.
assuming have function rho(r), takes values [0..1] , returns values [0..1], it's pretty easy:
def getrhosample(): #get uniform random number value = numpy.random.random() #sample custom function return rho(value)
Comments
Post a Comment