Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How I accept generated [x,y] samples that fall into a probability density function or an equivalent area?

1 回表示 (過去 30 日間)
DIMITRIS GEORGIADIS
DIMITRIS GEORGIADIS 2017 年 10 月 14 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I generate samples in 2-d space, i.e. x,y coordinates. I have a normal pdf and I want to keep/accept the samples that fall inside the pdf. Let as denote this area W. Is there a specific command for this? How can I implement it? I found in Matlab inpolygon command , but it works only for polygonal region and not on curves, such as pdf .
  2 件のコメント
Star Strider
Star Strider 2017 年 10 月 14 日
The normal distribution extends from -Inf to +Inf. All the real values you create are by definition ‘inside the PDF’.
DIMITRIS GEORGIADIS
DIMITRIS GEORGIADIS 2017 年 10 月 15 日
Maybe I was not clear. Please see my comment below and the .m file.

回答 (1 件)

Image Analyst
Image Analyst 2017 年 10 月 14 日
I'm not sure you mean "fall inside the pdf" since, of course, all values generated must come from the PDF. I think you mean "fall inside the area", presumably one defined by some limits on x and y
% Get x and y somehow
if x < x1 || x > x2 || y < y1 || y > y2
% Coordinate is out of bounds. Skip this one.
continue;
end
% Else do something with it.
  2 件のコメント
DIMITRIS GEORGIADIS
DIMITRIS GEORGIADIS 2017 年 10 月 15 日
編集済み: DIMITRIS GEORGIADIS 2017 年 10 月 15 日
My fault. Maybe I was not clear. I need a simple rejection sampling algorithm, such as the following:
1. K=200 %number of simulations
2. k=1 % first iteration
3. Generate a sample x (for k=1) from f(x) % prior pdf
4. Generate a sample p from the standard uniform distribution in [0,1].
5. if [x,p] ε (i.e. belong) W-space
a. Accept x
b. k=k+1
6. Stop if k=K, else go to 3.
Here is my .m file for the above. My question is HOW I express the if condition? The accepted samples must fall inside W-space (the shaded area).

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by