How can I select three random sample of a matrix with minimum separation between samples?

조회 수: 2 (최근 30일)
Hi everyone,
I have the following problem: I have a matrix A(20x20) per example and I need select from this matrix 3 random samples that have to be different and with a minimum separation (distance) between samples. I mean that between samples chosen randomly, would exist a minimum separation of 4 samples, per example the sum of 3 samples to the right in the same row and 1 sample up in the column.
There exists a way to obtain this?
I have been trying to get this using the following, but if I repeat it 3 times, exists the probability to get the same sample. Also I don't know how to get the restriction of the minimum separation.
random_sample1 = A(randi(numel(A)))
Thank you very much in advance for your help.
J.F.
  댓글 수: 2
James Tursa
James Tursa 2021년 2월 8일
편집: James Tursa 2021년 2월 8일
You may need to do this either sequentially or with a rejection method to satisfy your distance requirement.
Javier Fuster
Javier Fuster 2021년 2월 8일
Yes, I think so. I was wondering if there was a method more robust than start to reject putting so many 'if'.
Also, thank you for your response.

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

채택된 답변

James Tursa
James Tursa 2021년 2월 8일
A rejection method is straightforward. Simply make your selections in a forever loop until you get something that works. The advisibility of this approach depends on the probability of getting a rejection. E.g., rejection method code for generating one sample set
n = numel(A);
nsamples = 3;
dmin = 4;
while( true )
sample_indexes = randperm(n,nsamples);
[row,col] = ind2sub(size(A),sample_indexes);
d = abs(row - row') + abs(col-col');
d(1:nsamples+1:end) = inf;
if( all(d(:)>=dmin) )
break;
end
end
samples = A(sample_indexes);
This assumes there is no wrap-around for row & column comparisons.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by