(3)对于某些特定分布,有已知的采样方法.例如.对于多元高斯,如果x是来自均值0和恒等方差高斯的样本(即,仅将每个x_i采样为N(0,1)),则y = L x + m的均值为m,协方差S = LL',其中L是S的下三角Cholesky分解,必须为正定.(4)对于许多多元分布,以上都不适用,并且应用了更复杂的方案,例如马尔可夫链蒙特卡罗.也许您对这个问题说的更多,可以给出更具体的建议.I have a multivariate probability density function P(x,y,z), and I want to sample from it. Normally, I would use numpy.random.choice() for this sort of task, but this function only works for 1-dimensional probability densities. Is there an equivalent function for multivariate pdfs? 解决方案 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) (i.e., x, y, and z are independent) then you can sample each one separately.(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. E.g. 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.(3) For some particular distributions, there are known ways to sample. E.g. for multivariate Gaussian, if x is a sample from a mean 0 and identity covariance Gaussian (i.e. just sample each x_i as N(0, 1)), then y = L x + m has mean m and covariance S = L L' where L is the lower-triangular Cholesky decomposition of S, which must be positive definite.(4) For many multivariate distributions, none of the above apply, and a more complicated scheme such as Markov chain Monte Carlo is applied.Maybe if you say more about the problem, more specific advice can be given. 这篇关于从python中的多元概率密度函数采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!