필터 지우기
필터 지우기

Generate constrained random vector

조회 수: 3 (최근 30일)
Saifullah Khalid
Saifullah Khalid 2017년 7월 14일
편집: Saifullah Khalid 2017년 7월 14일
I am trying to generate a random vector from two other random vectors and a scaller in Matlabsuch that λ* P - Φ.*μ < 0 where P, Φ, μ are vectors and λ is a scaler value. I have written following code in Matlab. But it stuck in while loop many times when I try to use higher values of λ e.g. λ = 30 or 50. I shall appreciate any help.
%generate P from uniform distribution: 0≤ P ≤1 and ∑P =1
a=rand(47,1);
a=[0;a;1];
a=sort(a);
b=zeros(48,1);
for i=1:48
b(i)=abs(a(i)-a(i+1));
end
P=b';
%---------------------------------------------
% Generate μ from uniform distribution: 1≤ μ ≤2
%----------------------------------------------
a=1; b=2; miu = a+(b-a)* rand(48,1);
%-----------------------------------------------------------------------
% Generate from uniform distribution: 0≤ Φ ≤1 such that λ* P - Φ.*μ < 0
%-----------------------------------------------------------------------
count=1; lamda=5;
while(count ~= 49)
tPhi = rand(1,1);
c = lamda* P(count) - tPhi.*miu(count);
if(c<0)
Phi(count,1)= tPhi;
count=count+1;
end
end
disp(Phi);
  댓글 수: 2
Jan
Jan 2017년 7월 14일
Of course this can be an infinite loop:
c = lamda * P(count) - tPhi.*miu(count);
P can have the max value 1, lamda is e.g. 30, tPhi has a max of 1 and miu a max of 2. Then there is no chance the c is negative.
Saifullah Khalid
Saifullah Khalid 2017년 7월 14일
편집: Saifullah Khalid 2017년 7월 14일
λ* P - Φ.*μ < 0 is one of the constraints in a research problem I am working on. I have found that if I create P by
x=rand(48,1); P=x./sum(x)
The problem of infinite loops occurs very less. But I do not want to do that way as data generated is probably not uniform. Secondly, if I increase 'u', it can work but I do not know whether that is a practically sound idea.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by