如何计算 Scipy 中多元高斯分布的概率?
How does one calculate the probability of a multivariate Gaussian in Scipy?
如何计算 Scipy 中 x
点的多元高斯概率?
我试过了
probability = multivariate_normal(x, mean, v)
其中 x
、mean
、v
都是大小正确的向量,但我得到:
probability = multivariate_normal(x, mean, v )
TypeError: __call__() takes at most 3 arguments (4 given)
首先是错误。当您调用 multivariate_normal
时,您实际上是在调用 multivariate_normal_gen
class 的 __call__
(第 555 行的 source)。因为它是一个方法,它本身 self
作为一个参数,它总是第一个参数。当您再添加三个参数时,参数总数为四个。
关于您的问题,您通过调用 pdf
of multivariate_normal
来评估给定点的概率密度函数。示例:
from scipy.stats import multivariate_normal
import numpy as np
x = np.array([[1,2], [3,4]])
multivariate_normal.pdf(x, mean=[0, 1], cov=[5, 2])
打印出:
Out[44]: array([ 0.0354664 , 0.00215671])
如何计算 Scipy 中 x
点的多元高斯概率?
我试过了
probability = multivariate_normal(x, mean, v)
其中 x
、mean
、v
都是大小正确的向量,但我得到:
probability = multivariate_normal(x, mean, v )
TypeError: __call__() takes at most 3 arguments (4 given)
首先是错误。当您调用 multivariate_normal
时,您实际上是在调用 multivariate_normal_gen
class 的 __call__
(第 555 行的 source)。因为它是一个方法,它本身 self
作为一个参数,它总是第一个参数。当您再添加三个参数时,参数总数为四个。
关于您的问题,您通过调用 pdf
of multivariate_normal
来评估给定点的概率密度函数。示例:
from scipy.stats import multivariate_normal
import numpy as np
x = np.array([[1,2], [3,4]])
multivariate_normal.pdf(x, mean=[0, 1], cov=[5, 2])
打印出:
Out[44]: array([ 0.0354664 , 0.00215671])