필터 지우기
필터 지우기

How Matlab calculate randsample using randsample function

조회 수: 11 (최근 30일)
riad didou
riad didou 2020년 7월 14일
편집: Adam Danz 2020년 8월 12일
Hi
I need to understand the method of random selection (without replacement) (MATLAB 2019b); i mean behind this function how the algorithm works?
Knowing that i have used this:

채택된 답변

Adam Danz
Adam Danz 2020년 7월 14일
편집: Adam Danz 2020년 8월 12일
randsample(n,k) or randsample(population,k) merely creates a random permutation of your data (1:n or population) using randperm.
So the question becomes, how does the randperm function work?
You're in luck because it's explaind in the randperm documentation page. See the "Tips" section.
You'll see that randperm uses a uniform pseudorandom number generator that can have different internal settings and states. There are several types of random number generators. See the table:
To determine which one you're using, run
rng
Example output
>> rng
ans =
struct with fields:
Type: 'twister' % <------
Seed: 9999
State: [625×1 uint32]
For example, "twister" is defined by the mt19937ar generator which is fully described in the link above and contains citations to primary literature, depending on how far down the rabbit hole you want to go. You can also google these things and find lots of background information such as this Wiki article on the Mersenne Twister refenced in the code above.
To summarize, the randsample merely resamples or subsamples your data using randperm without replacement (unless the replacement flag is set to true). The random selection within randperm is controlled by the random number generator you're using which can be determined by running rng().
Also see this general list of topics regarding Matlab random number generation.
  댓글 수: 4
riad didou
riad didou 2020년 7월 14일
Thanks a lot
Adam Danz
Adam Danz 2020년 7월 14일
No problem. I'm not sure what you're expecting to find.
If you're trying to reproduce randomized results, you just need to set the rng seed at the beginning of your function / script.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by