如何在Lua/Torch中从多变量高斯中提取样本



我发现Torch没有任何内置函数来为给定所需协方差矩阵的多元高斯分布绘制样本。有人能告诉我如何使用所需的协方差矩阵从多元高斯分布中提取样本吗?

这是我的尝试:

我使用终端中的luarocks install randomkit从这里安装了randomkit包。然而,当我在Lua中执行require 'randomkit'时,我找不到multivariate_normal函数作为randomkit的元素之一。我做错什么了吗?

您可以使用torch分发包。要安装它,请在终端中运行以下命令:

luarocks install https://raw.github.com/jucor/torch-distributions/master/distributions-0-0.rockspec

以下是lua中从多元正态分布中提取样本的工作示例:

require 'distributions'
mu = torch.Tensor({10, 0})
sigma = torch.eye(2)
sample = distributions.mvn.rnd(mu, sigma) -- a sample from the distribution

最新更新