Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

random - Drawing from a multivarite normal, with "genmn" and "setgmn"

I am trying to draw random deviates from a multinormal distribution. There are two subroutines I found online: "setgmn" and "genmn", which are supposed to do exactly that. They are from the "ranlib" library.

http://www.netlib.org/random/

However, I have no clue how those to subroutines are supossed to work together. Setgmn combines the data in such a way that genmn can uses it. However I struggle wih the "parm" argument I am not exactly sure what I have to pass into it. And how those two subroutines need to be combined to actually work.

I could not find an example online. So I thought maybe someone here already used them or has a link to an example online.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the source:

First you have to call setgmn. This procedure will set the argument parm that you have to pass to getmn.

subroutine setgmn ( meanv, covm, p, parm )
  integer ( kind = 4 ) p
  real ( kind = 4 ) covm(p,p)
  real ( kind = 4 ) meanv(p)
  real ( kind = 4 ) parm(p*(p+3)/2+1)

Parameters:

MEANV: the means of the multivariate normal distribution.

COVM: On input, the covariance matrix of the multivariate distribution. On output, the information in COVM has been overwritten.

P: the number of dimensions.

PARM: parameters needed to generate multivariate normal deviates.

PARM(1) contains the size of the deviates, P

PARM(2:P+1) contains the mean vector.

PARM(P+2:P*(P+3)/2+1) contains the upper half of the Cholesky decomposition of the covariance matrix.


subroutine genmn ( parm, x, work )
  real ( kind = 4 ) parm(*)
  real ( kind = 4 ) work(*)
  real ( kind = 4 ) x(*)

Parameters:

PARM(P*(P+3)/2+1) : parameters set by SETGMN.

X(P): a random deviate from the distribution. Will be the output.

WORK(P): workspace


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...