Please, I need to know the name of algorithm used by MATLAB 'randsample' function for the random selection without replacement

댓글 수: 3

riad didou
riad didou 2020년 8월 12일
편집: riad didou 2020년 8월 12일
But i can't find the name of the algorithm for the randsample (i didn't mean the RNG function)!
Adam Danz
Adam Danz 2020년 8월 12일
편집: Adam Danz 2020년 8월 12일
But my answer tells you how to find that.
The answer explains that the syntax you're using in randsample is using randperm which uses a uniform pseudorandom number generator of which there are several types. See the "To determine which one you're using..." section to learn how to find which type you're using.

댓글을 달려면 로그인하십시오.

답변 (1개)

Bruno Luong
Bruno Luong 2020년 8월 12일
편집: Bruno Luong 2020년 8월 12일

0 개 추천

댓글 수: 4

Adam Danz
Adam Danz 2020년 8월 12일
편집: Adam Danz 2020년 8월 12일
Thanks for pointing to that discussion, Bruno Luong. Note that this algorithm still depends on the random number generator state settings as I tried to explain in this answer but knowing about the Fisher-Yates-Durstenfeld shuffle (FYD) is useful.
For OP, the FYD can be understood as randomly drawing k values from a hat containing n values where k<n. The "random" part uses the rng settings.
For example,
% Use the default Mersenne Twister(mt19937ar) with seed 9999
rng(9999, 'twister')
randsample(100,8)'
% ans =
% 43 61 83 55 4 16 22 19
% You can repeate those two lines and will get the same values.
% Now change the random number generator to Combined multiple recursive (mrg32k3a) with the same seed
rng(9999, 'combRecursive')
randsample(100,8)'
% ans =
% 80 9 63 42 78 13 89 71
% You can repeate those two lines and will get the same values but note how they differ from the Mersenne Twister.
% Reset generator back to default
rng('default')
Maybe the OP didn't intend to dig that deeply.
riad didou
riad didou 2020년 8월 12일
편집: riad didou 2020년 8월 12일
for example: i have a set of 20 samples and i would like to select 7 samples with 'randsample' function without introducing 'rng' function ; so how the algorithm pick these 7 samples ?because even if we don't use a random number generator the algorithm still working ! did you get my question
Bruno Luong
Bruno Luong 2020년 8월 12일
Read the pseudo code on the wikipedia link I posted above.
Adam Danz
Adam Danz 2020년 8월 12일
편집: Adam Danz 2020년 8월 12일
@riad didou, if you plan on using Matlab's randsample function, you will be relying on a random number generator.
I don't know how else to explain it other than this:
If you call randsample(n,k) or randsample(population, k), that function uses the randperm function whether you want it to or not. According to Matlab's document which I mentioned in the original thread, "The sequence of numbers produced by randperm is determined by the internal settings of the uniform pseudorandom number generator".
"Even if we don't use a random number generator the algorithm still working"
That's not true. The link Bruno provided vaguely describes that values from your array are "randomly" chosen. That requires you to use a random process which is what the random number generator is. Even if you write your own version that doesn't use rng() you'll still need to replace it with some kind of random processes.
Maybe it would help to know your end goal. If the goal it to write about it in a methods section of a paper, I wonder what bits of information you're missing. Many people just write that the function randsample was used in Matlab and they they cite Mathworks but you'd need to document the generator type and seed for reproducibility.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 8월 12일

편집:

2020년 8월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by