【问题标题】:Why is scipy's probability density function not accepting size of my mean?为什么 scipy 的概率密度函数不接受我的均值大小?
【发布时间】:2022-11-26 02:54:05
【问题描述】:

我正在使用一个函数来计算似然密度。

我正在运行两个 xs,它们是长度为 7 的向量。

def lhd(x0, x1, dt): #Define a function to calculate the likelihood density given two values. 
    d = len(x0) #Save the length of the inputs for the below pdf input.
    print(d)
    print(len(x1))
    lh = multivariate_normal.pdf(x1, mean=(1-dt)*x0, cov=2*dt*np.identity(d)) #Take the pdf from a multivariate normal built from x0, given x1.
    return lh #Return this pdf value.

这里的均值是一个长度为 7 的向量,协方差是一个 (7,7) 数组。

当我运行它时,出现错误

ValueError: Array 'mean' must be a vector of length 49.

但是查看pdf的公式我认为这是不正确的。知道这里出了什么问题吗?

【问题讨论】:

    标签: python scipy scipy.stats


    【解决方案1】:

    如果dt是一个(7,7)数组,(1-dt)也是(7,7),(1-dt)*x0中的*运算符是逐元素乘法,如果x0是长度为7的向量结果将是一个 (7,7) 数组。

    我猜你打算使用矩阵乘法,你可以使用 x0 - dt @ x0(其中 @ 表示矩阵乘法运算符)。

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 2015-07-31
      • 2015-06-18
      • 2019-08-21
      • 1970-01-01
      • 2020-08-07
      • 2020-04-22
      • 1970-01-01
      • 2012-11-21
      相关资源
      最近更新 更多