scipy.stats.invwishart#

scipy.stats.invwishart = <scipy.stats._multivariate.invwishart_gen object>[源代码]#

逆 Wishart 随机变量。

df 关键字指定自由度。scale 关键字指定尺度矩阵,它必须是对称和正定的。 在这种上下文中,尺度矩阵通常被解释为多元正态协方差矩阵。

参数:
dfint

自由度,必须大于或等于尺度矩阵的维度

scalearray_like

分布的对称正定尺度矩阵

seed{None, int, np.random.RandomState, np.random.Generator}, optional

用于绘制随机变量。 如果 seedNone,则使用 RandomState 单例。 如果 seed 是一个整数,则使用一个新的 RandomState 实例,并用 seed 作为种子。 如果 seed 已经是一个 RandomStateGenerator 实例,则使用该对象。 默认值为 None

方法

pdf(x, df, scale)

概率密度函数。

logpdf(x, df, scale)

概率密度函数的对数。

rvs(df, scale, size=1, random_state=None)

从逆 Wishart 分布中抽取随机样本。

entropy(df, scale)

分布的微分熵。

引发:
scipy.linalg.LinAlgError

如果尺度矩阵 scale 不是正定的。

另请参见

wishart

注释

尺度矩阵 scale 必须是对称正定矩阵。 不支持奇异矩阵,包括对称半正定情况。 不检查对称性; 仅使用下三角部分。

逆 Wishart 分布通常表示为

\[W_p^{-1}(\nu, \Psi)\]

其中 \(\nu\) 是自由度, \(\Psi\)\(p \times p\) 尺度矩阵。

invwishart 的概率密度函数支持正定矩阵 \(S\); 如果 \(S \sim W^{-1}_p(\nu, \Sigma)\),则其 PDF 由下式给出

\[f(S) = \frac{|\Sigma|^\frac{\nu}{2}}{2^{ \frac{\nu p}{2} } |S|^{\frac{\nu + p + 1}{2}} \Gamma_p \left(\frac{\nu}{2} \right)} \exp\left( -tr(\Sigma S^{-1}) / 2 \right)\]

如果 \(S \sim W_p^{-1}(\nu, \Psi)\) (逆 Wishart),则 \(S^{-1} \sim W_p(\nu, \Psi^{-1})\) (Wishart)。

如果尺度矩阵是一维的且等于 1,则逆 Wishart 分布 \(W_1(\nu, 1)\) 将折叠为逆 Gamma 分布,其参数 shape = \(\frac{\nu}{2}\) 和 scale = \(\frac{1}{2}\)

此处使用 [4] 中的算法直接生成随机逆 Wishart 矩阵,而无需像 [2] 中描述的那样反转随机生成的 Wishart 矩阵。

在 0.16.0 版本中添加。

参考文献

[1]

M.L. Eaton, “Multivariate Statistics: A Vector Space Approach”, Wiley, 1983.

[2]

M.C. Jones, “Generating Inverse Wishart Matrices”, Communications in Statistics - Simulation and Computation, vol. 14.2, pp.511-514, 1985.

[3]

Gupta, M. and Srivastava, S. “Parametric Bayesian Estimation of Differential Entropy and Relative Entropy”. Entropy 12, 818 - 843. 2010.

[4]

S.D. Axen, “Efficiently generating inverse-Wishart matrices and their Cholesky factors”, arXiv:2310.15884v1. 2023.

示例

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.stats import invwishart, invgamma
>>> x = np.linspace(0.01, 1, 100)
>>> iw = invwishart.pdf(x, df=6, scale=1)
>>> iw[:3]
array([  1.20546865e-15,   5.42497807e-06,   4.45813929e-03])
>>> ig = invgamma.pdf(x, 6/2., scale=1./2)
>>> ig[:3]
array([  1.20546865e-15,   5.42497807e-06,   4.45813929e-03])
>>> plt.plot(x, iw)
>>> plt.show()
../../_images/scipy-stats-invwishart-1_00_00.png

输入分位数可以是任何形状的数组,只要最后一个轴标记组件即可。

或者,可以调用该对象(作为函数)来固定自由度和尺度参数,返回一个“冻结”的逆 Wishart 随机变量

>>> rv = invwishart(df=1, scale=1)
>>> # Frozen object with the same methods but holding the given
>>> # degrees of freedom and scale fixed.