Random multivariate normal distribution

泄露秘密 提交于 2019-12-10 17:12:37

问题


I've run into a problem where I have to be able to generate a set of randomly chosen numbers of a multivariate normal distribution with mean 0 and a given 3*3 variance-covariance matrix in Java.

Is there an easy way as to do this?


回答1:


1) Use a library implementation, as suggested by Dima.

Or, if you really feel a burning need to do this yourself:

2) Assuming you want to generate normals with a mean vector M and variance/covariance matrix V, perform Cholesky Decomposition on V to come up with lower triangular matrix L such that V=LLt (where the superscript t indicates transpose). Generate a vector Z of three independent standard normals (using Random.nextGaussian() to get the individual elements). Then LZ + M will have the desired multivariate normal distribution.




回答2:


Apache Commons has what you are looking for:

MultivariateNormalDistribution mnd = new MultivariateNormalDistribution(means, covariances);
double vals[] = mnd.sample();


来源:https://stackoverflow.com/questions/27823738/random-multivariate-normal-distribution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!