How can I generate random samples from two-dimensional normal and student T-bits in C ++?

What is the best approach for generating random samples from two-dimensional normal and student T-distributions? In both cases, the sigma is one, the average is 0 - so the only parameter that interests me is the correlation (and degrees of freedom for the student t). I need to have a solution in C ++, so I can not, unfortunately, use already implemented functions from MatLab or Mathematica.

+4
source share
3 answers

You can use the GNU GSL libraries. See here for Bivariate normal:

http://www.gnu.org/software/gsl/manual/html_node/The-Bivariate-Gaussian-Distribution.html

and student t-distribution here:

http://www.gnu.org/software/gsl/manual/html_node/The-t_002ddistribution.html

They are directly used.

+6
source

For a two-dimensional normal with a covariance unit and zero mean, we simply draw two one-dimensional normals.

If you want to draw a two-dimensional normal with the means (m1, m2), standard deviations (s1, s2) and the correlation rho, then draw two unit one-dimensional normals X and Y and set

u = m1 + s1 * X v = m2 + s2 * (rho X + sqrt(1 - rho^2) Y) 

Then u and v are distributed as you wish.

For student T, you should draw a normal variable N and chi ^ 2 variate V. Then N / sqrt (V) has a distribution T.

To draw chi ^ 2 you have to use a package. Or look in Chapter 7, Numerical Recipes, on how to draw from the gamma distribution (xhi ^ 2 - a special case of Gamma).

+4
source

You should take a look at the random distributions of Boost libraries - see http://www.boost.org/doc/libs/1_41_0/libs/random/random-distributions.html . I found them very easy to use as soon as you wrap your basic concept. Unfortunately, I don’t know enough about statistics to tell you if they will fit your needs exactly.

+3
source

Source: https://habr.com/ru/post/1299255/


All Articles