【问题标题】:Python: Evaluating multivariate normal distribution at the same point but different means and standard deviationsPython:在同一点评估多元正态分布,但均值和标准差不同
【发布时间】:2020-05-21 17:34:41
【问题描述】:

我尝试使用scipy.stats.multivariate_normal() 来评估点 x 处的 pdf,以获得不同的平均值和标准差值。但是,它不广播。

最小的工作示例

import numpy as np
from scipy import stats

# A single x where I want to evaluate it at
x = np.array([1.0])
# Multiple means where I want to evaluate the PDF at
means = np.array([1.0, 10.0])
standard_deviations = np.array([1.0, 2.0])

# If I use the stats function, it evaluates only at one point
stats.multivariate_normal.pdf(x=x, mean=means, cov=np.diag(means**2))

【问题讨论】:

  • 您使用哪个版本的 SciPy?因为上面生成:TypeError: pdf() got an unexpected keyword argument 'means'
  • 您只指定了一个多元正态分布。您想用两种不同的正态分布评估 x 的 pdf 吗?
  • @FBruzzesi 基本上我有一个观点x=np.array([1.0]),我想评估大量的单变量正态分布。这些分布由均值和方差指定,我存储在均值向量和标准差向量中

标签: python numpy scipy


【解决方案1】:

问题标题为“多元正态分布”,但代码显示x 的单变量输入,并且在评论中您说“......我想评估大量单变量正态分布......”。

要在单个点评估不同的单变量正态分布,请使用scipy.stats.norm,并将数组作为参数传递。 pdf 方法处理输入的广播。

例如,

In [1]: from scipy.stats import norm

In [2]: x = np.array([1.0])

In [3]: means = np.array([1.0, 10.0])

In [4]: standard_deviations = np.array([1.0, 2.0])

In [5]: norm.pdf(x, means, standard_deviations)
Out[5]: array([3.98942280e-01, 7.99187055e-06])

【讨论】:

  • 你能添加一个多元正态的答案吗?我知道 OP 没有显示这样的用例,但我通过“多元正态”一词找到了这篇文章,我想要答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 2019-05-08
  • 1970-01-01
  • 2020-03-25
  • 2013-12-20
  • 1970-01-01
相关资源
最近更新 更多