Generate random numbers from a probability density estimate

조회 수: 2 (최근 30일)
Andreas Palmgren
Andreas Palmgren 2021년 2월 8일
답변: Asvin Kumar 2021년 3월 15일
My problem is that I have data (2D coordinates) which I would like to generate more of. To solve my problem, I wanted to do a kernal density estimate and use it to both plot a heatmap and generate more data (which would generate data, which itself should create a similar heatmap).
I have a probability density estimate f which was returned from ksdensity(). The code I used to get f was
[f, xi, bw] = ksdensity(data, [X(:) Y(:)]);
where [X(:) Y(:)] was used to create my own grid covering my data. The data itself is a 2-column matrix, with each row representing a x- and y-coordinate.
f is a 20000x1 vector, which I could reshape and create a heatmap from. What I would like to do instead is using f somehow to generate new values from the probability density estimate which has been made over my data.
Do I need to use the bandwidth bw somehow?
Thank you for the help!

답변 (1개)

Asvin Kumar
Asvin Kumar 2021년 3월 15일
By heatmap, if you're looking to plot the estimated density function, you can plot that using f and xi. Here's a good example that illustrates that: Plot kernel density estimate of bivariate data
If you want to sample the estimated density function at points of your interest, you can use the second input argument pts. pts is basically the list of locations at which you want to query the estimated function's value. Here's a detailed example on using the pts input: Estimate CDF at specific values.
The output xi will match the input pts when it is specified. When pts is not specified, xi will take default values as mentioned in its description here.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by