필터 지우기
필터 지우기

Generate random numbers with custom PDF

조회 수: 26 (최근 30일)
Michael
Michael 2012년 6월 11일
편집: Walter Roberson 2018년 6월 10일
Hi, as it may become clear I'm fairly weak on probability distributions
I want to generate a set of random numbers between 0 and 1, but able to alter the weighting of these numbers. For example if I could input some sort of "bias" parameter which determines the extent to which the numbers tend to be closer to 0 than to 1, for example.
I don't know which of MATLAB's many distributions I should use. So far I've been using the uniform distribution and taking it to the power N, but N=0.5 seems to give an entirely different PDF shape (in favour of numbers close to 1) than the intended opposite bias, N=2 (in favour of numbers close to 0). Squaring it seems to favour small numbers far more than sqrt-ing seems to favour large numbers, so I've rejected this approach as unfair.
Is there a common distribution for this? Numbers have to be between 0 and 1 and I want to take control of how close they are, on average, to either.
Thanks Mike

답변 (4개)

Image Analyst
Image Analyst 2013년 5월 10일
In general, you basically compute the CDF of your PDF function and invert it. Go here for a generally applicable explanation of how to do it: http://en.wikipedia.org/wiki/Inverse_transform_sampling

Pantelis Sopasakis
Pantelis Sopasakis 2013년 5월 10일
You may consider using this PDFSampler. I believe, it does exactly what you need. You just need to specify how you want your samples to be distributed, e.g. you may provide their histogram.

Tom Lane
Tom Lane 2012년 6월 11일
If you have the Statistics Toolbox, then take a look at the beta distribution. Use it with disttool to see how the parameters affect the distribution, randtool to see what a random sample from this distribution looks like, and betarnd to generate your own sample from the command line or inside a function.

Ka Mirul
Ka Mirul 2017년 11월 14일
편집: Walter Roberson 2018년 6월 10일
I have create a video about generating random number in MATLAB https://www.youtube.com/watch?v=MyH3-ONYL_k
Hope that will help you

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by