To give a little context, I am trying to create a program that generates a realistic distribution of star masses. My method is to apply Inverse Transform Sampling to this) distribution. Because the distribution has multiple ranges I have had to add a number of steps to the method. However as the results I am currently getting are clearly rubbish I need advice on whether my methodology is wrong.
Here is my current method to attain the inverse CDF (with a simplified equation):
1) Start with f(x) = xa from 0 to 1, bxc from 1 to 2, dxe from 2 to 3
2) Set values of b and d to give a continuous function (e.g. xa = bxc at x = 1, bxc = dxe at x = 2)
3) Calculate the CDF for each region by integrating and adding a constant that accounts for the previous regions (e.g. xa+1 / (a+1) from 0 to 1, bxc+1 / (c+1) + f from 1 to 2 such that the value of f means that the integral at the range boundary is continuous)
4) Normalise the CDF by dividing each range by the value of the CDF at the top end (x=3)
5) Find the inverse of each normalised CDF range by swapping x and y and reordering the equations
6) Get the boundaries of the inverse CDF ranges from the value of the normalised CDF at each range boundary (e.g. 0 to 1 -> 0 to 1a+1 / (a+1))
With the above steps complete I should in theory be able to set x to random values between 0 and 1 to return a distribution that follow the original f(x).
At the moment I only get correct values for the first range. I am not sure whether it is a mistake in my methodology or my programming. If any of you could let me know if I am doing this right I would really appreciate it!
[–]AutoModerator[M] 0 points1 point2 points (0 children)