gpt4 book ai didi

c++ - gsl 中的 matlab mvnrnd

转载 作者:行者123 更新时间:2023-11-28 03:37:32 24 4
gpt4 key购买 nike

您好,我不确定我的算法是否正确,我正在尝试复制 mvnrnd matlab 的功能,但在 gsl 中。我在一些期刊文章中发现了一种生成多元正态 vector 的算法,但我需要一个多元正态随机数矩阵

假设分布是 Z~(mu,sigma);

假设 sigma 是一个已经正定的矩阵。

我从网上找到的一个算法说

1. cholskey(sigma) = A
2. generate uniform gaussian vector r
3. matrix vector triangular product with gsl_blas_dtrmv A * r
4. add mu to Ar and that will be a vector of multivariate normal random numbers

下面是我的方法

以下更改是否正确以生成随机变量矩阵

    1. cholskey(sigma) = A
2. generate uniform gaussian matrix R
3. matrix matrix scalar product AR
4. add mu to AR and that will be a matrix of multivariate normal random numbers

最佳答案

是的,没错。参见例如this Wikipedia entry on multivariate normal RNGs其中有这个部分:

Drawing values from the distribution

A widely used method for drawing a random vector x from the N-dimensional multivariate normal distribution with mean vector μ and covariance matrix Σ works as follows:

  1. Find any real matrix A such that A AT = Σ. When Σ is positive-definite, the Cholesky decomposition is typically used. [...]

  2. Let z = (z1, …, zN)T be a vector whose components are N independent standard normal variates (which can be generated, for example, by using the Box–Muller transform).

  3. Let x be μ + Az. This has the desired distribution due to the affine transformation property.

它描述了相同的算法。

R 也有几种实现方式,例如 MASS 中的 mvrnorm每个 R 安装都附带的软件包。

关于c++ - gsl 中的 matlab mvnrnd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10405905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com