mercredi 30 octobre 2019

How do I create a vectorized version of randsample in Matlab

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 have 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.




Aucun commentaire:

Enregistrer un commentaire