Ferdosi et al define six artificial datasets to test density estimation methods. Part of the fourth dataset is defined as:
$$ Uniform(x,y) = [0,100], Gaussian(z) = [M = 50, var = 5] $$
Where $M$ is defined as the mean of the distribution and $var$ as the variance. To test my own density estimator using this dataset I'd like to do two things:
- Sample $N$ items from this dataset.
- Compute the 'true' density of each of these samples drawn.
Sampling
For step (1) I tried the following in Matlab:
Draw $N$ samples from a uniform distribution (this gives a $N \times 1$ matrix).
uniform = makedist('uniform', 'lower', 0, 'upper', 100); x = uniform.random(N, 1);
Draw $N$ samples from a uniform distribution (this gives a $N \times 1$ matrix).
y = uniform.random(N,1);
Draw $N$ samples from a Gaussian distribution (resulting in a $N \times 1$ matrix).
z = mvnrnd(M,var,N);
Combine these two matrices to a $N \times 3$ matrix.
data = [x, y, z];
This seems to give the correct results, that is to say the resulting plot is the same as the plot shown in the article.
Is this the correct way to sample this distribution? If not how should I go about it? Is there a difference between sampling three different vectors or sampling the $x$ and $y$ vector from a bivariate distribution?
Computing the density
This wikipedia artikel defines ''the joint probability density function $fX,Y(x, y)$ for continuous random variables as:
$$ f_{X,Y}(x,y) = f_{Y\mid X}(y|x)f_X(x) = f_{X\mid Y}(x\mid y)f_Y(y)\ $$
where fY|X(y|x) and fX|Y(x|y) give the conditional distributions of Y given X = x and of X given Y = y respectively, and fX(x) and fY(y) give the marginal distributions for X and Y respectively.'' But I don't know how to use it, if it is the correct way, to determine the density of the defined distribution.
normrnd
should be sufficient. $\endgroup$normrnd
, OP needs to note thatnormrnd
takes standard deviation as input whilemvnrnd
takes variance. $\endgroup$