简体   繁体   English

从python中的多元概率密度函数采样

[英]Sampling from a multivariate probability density function in python

I have a multivariate probability density function P(x,y,z), and I want to sample from it.我有一个多元概率密度函数 P(x,y,z),我想从中采样。 Normally, I would use numpy.random.choice() for this sort of task, but this function only works for 1-dimensional probability densities.通常,我会使用 numpy.random.choice() 来完成此类任务,但此函数仅适用于一维概率密度。 Is there an equivalent function for multivariate pdfs?多元pdf是否有等价的函数?

There a few different paths one can follow here.在这里可以遵循几种不同的路径。

(1) If P(x,y,z) factors as P(x,y,z) = P(x) P(y) P(z) (ie, x, y, and z are independent) then you can sample each one separately. (1) 如果 P(x,y,z) 因子为 P(x,y,z) = P(x) P(y) P(z)(即 x、y 和 z 是独立的),那么您可以分别取样每一个。

(2) If P(x,y,z) has a more general factorization, you can reduce the number of variables that need to be sampled to whatever's conditional on the others. (2) 如果 P(x,y,z) 具有更一般的因式分解,您可以将需要采样的变量数量减少到以其他变量为条件的任何变量。 Eg if P(x,y,z) = P(z|x, y) P(y | x) P(x), then you can sample x, y given x, and z given y and x in turn.例如,如果 P(x,y,z) = P(z|x, y) P(y | x) P(x),那么您可以依次对给定 x 的 x、y 和给定 y 和 x 的 z 进行采样。

(3) For some particular distributions, there are known ways to sample. (3) 对于某些特定的分布,有已知的抽样方法。 Eg for multivariate Gaussian, if x is a sample from a mean 0 and identity covariance Gaussian (ie just sample each x_i as N(0, 1)), then y = L x + m has mean m and covariance S = LL' where L is the lower-triangular Cholesky decomposition of S, which must be positive definite.例如,对于多元高斯,如果 x 是来自均值 0 和恒等协方差高斯的样本(即只是将每个 x_i 采样为 N(0, 1)),则 y = L x + m 具有均值 m 和协方差 S = LL' 其中L 是 S 的下三角 Cholesky 分解,它必须是正定的。

(4) For many multivariate distributions, none of the above apply, and a more complicated scheme such as Markov chain Monte Carlo is applied. (4) 对于很多多元分布,以上都不适用,而采用更复杂的方案,如马尔可夫链蒙特卡罗。

Maybe if you say more about the problem, more specific advice can be given.或许问题多说一些,可以给出更具体的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM