Pseudorandom Pair Sampling Without Replacement

버전 1.3 (1.68 KB) 작성자: Seong Hun Lee
This is a simple and fast implementation of random pair sampling without replacement.
다운로드 수: 14
업데이트 날짜: 2021/11/20

라이선스 보기

For example, let's say we have 1D data [1,2,3,...,10], and we want to sample 20 non-overlapping pairs and get something like (4,3), (8,2), (1,6), etc.
We assume that the order doesn't matter, i.e., (4,3) is the same as (3,4).
There are multiple ways to do this, but it can be quite slow when we try to sample many pairs from a large data.
So, I came up with a simple and fast method. The idea is as follows.
1. Randomly shuffle the data: 5 9 6 10 4 3 8 1 2 7.
2. Without replacement, randomly pick pairs of direct neighbors: (6,10), (3,8), (5,9), ..., (10,4).
3. Without replacement, randomly pick pairs with one in-between neighbor: (4,8), (5,6), (1,7), ..., (9,10).
4. Without replacement, randomly pick pairs with two in-between neighbors: (9,4), (3,2), (5,10), ..., (8,7).
5. Without replacement, randomly pick pairs with three, four, ..., etc. in-between neighbors. In the end, the final pair will be (5,7).
If you do this to pick large enough number of pairs, then you will eventually get every possible pairs.
You stop the process as soon as you obtain the desired number of pairs.
To further increase the "randomness", we even randomize the order of steps (between step 2-5).
This means that the following example can happen:
We first pick ALL random pairs with three in-between neighbors, and then ALL random pairs with five in-between neighbors, and then ALL random pairs of direct neighbors, and so on.

인용 양식

Seong Hun Lee (2024). Pseudorandom Pair Sampling Without Replacement (https://www.mathworks.com/matlabcentral/fileexchange/75407-pseudorandom-pair-sampling-without-replacement), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2016b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.3

Change in title.

1.2

Instead of increasing the gap incrementally, change it randomly.

1.1.2

Updated the description.

1.1.1

Updated the description

1.1

Update 1.1: When picking pairs with a given gap, do it randomly.

1.0.0