0

I have a support (supp_epsilon) and a probability mass function (pr_mass_epsilon) in Matlab, constructed as follows.

    supp_epsilon=[0.005 0.01;
                  0.01  0.015;
                  0.015 0.02;
                  0.02  0.025]; 

    suppsize_epsilon=size(supp_epsilon,1);

    pr_mass_epsilon=zeros(suppsize_epsilon,1);

    mu_epsilon=[0; 0];
    sigma_epsilon=[1 0.5; 0.5 1];
    
    pr_mass_epsilon=zeros(suppsize_epsilon,1);

    for j=1:suppsize_epsilon
 pr_mass_epsilon(j)=mvnpdf(supp_epsilon(j,:),mu_epsilon.',sigma_epsilon)/sum(mvnpdf(supp_epsilon,mu_epsilon.',sigma_epsilon));
     end

Note: supp_epsilon is 4x2. Each 1x2 row of supp_epsilon is an element of the support of interest.

Question: I want to draw n=10 vectors of size 1x2 from pr_mass_epsilon. Each of these vectors has to be a row of supp_epsilon. For n very large the empirical frequency of the drawn vectors has to be close to pr_mass_epsilon.

How can I do this?

Note: This question addresses the scalar case where the answer suggests to use randsample.

Community
  • 1
  • 1
TEX
  • 2,249
  • 20
  • 43
  • just use `randsample(whatever_it_is,2)` – bla Oct 30 '19 at 18:43
  • It gives me error: `epsilon=randsample(supp_epsilon, n, true, pr_mass_epsilon,2)`; – TEX Oct 30 '19 at 18:46
  • `Error using randsample (line 74) POPULATION must be a vector.` – TEX Oct 30 '19 at 18:46
  • 1
    You say you want `n` random vectors. What is `n`, and why is `supp_epsilon` a matrix and not a vector? – Luis Mendo Oct 30 '19 at 18:58
  • Thanks. `supp_epsilon` is now a matrix because it represents the support of a bivariate random vector. Each `1x2` row of `supp_epsilon` is a possible realisation of such bivariate random vector. `pr_mass_epsilon` is the associated probability mass function. – TEX Oct 30 '19 at 19:05
  • Is this a use-case for [`arrayfun`](https://www.mathworks.com/help/matlab/ref/arrayfun.html)? – SecretAgentMan Oct 30 '19 at 20:07
  • 1
    Is your bi-variate (or univariate) support discrete or continuous? Your use of the term probability mass function suggests **discrete**; invoking [`mvnpdf`](https://www.mathworks.com/help/stats/mvnpdf.html) suggests **continuous**. – SecretAgentMan Oct 30 '19 at 20:41
  • @SecretAgentMan The support is discrete and equal to `supp_epsilon`. I construct the probability mass function by truncating and discretising a multivariate normal, but this is just one example. – TEX Oct 30 '19 at 20:50
  • @user3285148 Ok, thanks. So `sum(pr_mass_epsilon) = 1` and it is indeed a PMF, not a PDF. The idea is to develop this for any given `pr_mass_epsilon`, is that right? – SecretAgentMan Oct 30 '19 at 21:19
  • yes, that is correct. – TEX Oct 30 '19 at 21:55

0 Answers0