Generate a set of sample data from a distribution


I know we can use gnoise(num) to generate a set of data with a Gaussian distribution;
similarly, is there an easy way to generate a set of data with an arbitrary distribution?


function generateQuadDis(prCount)
    wave prCount
    killwaves/z quad
    make/o/n=1 quad=1
    variable numRow = dimsize(prCount,0)
    variable m,n=0,k=-5
    variable numEntry
    for (m=0;m<numRow;m=m+1)
        numEntry = round(prCount[m])
        make/o/n=(numEntry) newWave
        newWave = -5+(n)*10e-4
        duplicate/o quad, quadToWrite
        concatenate/NP/o {newWave,quad},quadToWrite
        duplicate/o quadToWrite,quad
    numRow = dimsize(quad,0)
    deletePoints numRow-1,1,quad

The above is my naive implementation. prCount is the arbitrary distribution. First, I multiply prCount (outside of this function) to make a large portion of it to be above 1. Then I am just stacking up terms according to the rounded number of the distribution.



What I was thinking is to integrate the initial prCounts function to create a pseudo-cumulative distribution function.  I would normalize to 1 so the range of probability goes 0-1.  I would then get a random value (0-1) from a uniform distribution(enoise(value)) and then do a search the pseudo-CDF to get a corresponding input value.

I mocked up an example and hopefully it aligns to your request.

Made a probability function, red, and note it is not normalized.  These could be counts from a sensor or whatever.  I then integrate that curve to create a cumulative distribution function and I have normalized it to 1.  Now to get a random value from it you seed a uniformly seeded number fro enoise and input into a findlevel command to return a value based on your initial x value range.  For example if I do a findlevel CDF, 0.3 it returns 70.7887.

Hopefully this makes sense and does it do what you need?




probability CDF.png (116.5 KB)