pymc.OrderedProbit#

class pymc.OrderedProbit(name, *args, compute_p=True, **kwargs)[源代码]#

有序概率分布的包装类。

用于回归有序数据值,其值范围从1到K,作为某些预测变量 \(\eta\) 的函数。切点 \(c\) 分隔了 \(\eta\) 的哪些范围映射到K个观测到的因变量中的哪一个。切点的数量为K - 1。建议将切点约束为有序。

为了稳定计算,对数似然在日志空间中使用缩放误差函数 erfcx 进行计算。

\[\begin{split}f(k \mid \eta, c) = \left\{ \begin{array}{l} 1 - \text{normal_cdf}(0, \sigma, \eta - c_1) \,, \text{如果 } k = 0 \\ \text{normal_cdf}(0, \sigma, \eta - c_{k - 1}) - \text{normal_cdf}(0, \sigma, \eta - c_{k}) \,, \text{如果 } 0 < k < K \\ \text{normal_cdf}(0, \sigma, \eta - c_{K - 1}) \,, \text{如果 } k = K \\ \end{array} \right.\end{split}\]
参数:
eta : 类似张量floattensor_like of float

预测器。

cutpoints类似张量的浮点数数组

分割点数组的长度为 K - 1,用于将 \(\eta\) 分割成多个区间。不要显式地将 \(c\) 的第一个和最后一个元素设置为负无穷和正无穷。

sigma : 类似张量float,默认值为 1.0tensor_like of python:float, 默认 1.0

probit 函数的标准差。

compute_p : 布尔值,默认值 Truebool, 默认 python:True

是否基于切点值计算并存储在跟踪中每个类别的推断概率。默认为 True。如果对内存使用有兴趣,可能需要禁用此功能。

示例

# Generate data for a simple 1 dimensional example problem
n1_c = 300; n2_c = 300; n3_c = 300
cluster1 = np.random.randn(n1_c) + -1
cluster2 = np.random.randn(n2_c) + 0
cluster3 = np.random.randn(n3_c) + 2

x = np.concatenate((cluster1, cluster2, cluster3))
y = np.concatenate((1*np.ones(n1_c),
                    2*np.ones(n2_c),
                    3*np.ones(n3_c))) - 1

# Ordered probit regression
with pm.Model() as model:
    cutpoints = pm.Normal("cutpoints", mu=[-1,1], sigma=10, shape=2,
                          transform=pm.distributions.transforms.ordered)
    y_ = pm.OrderedProbit("y", cutpoints=cutpoints, eta=x, observed=y)
    idata = pm.sample()

# Plot the results
plt.hist(cluster1, 30, alpha=0.5);
plt.hist(cluster2, 30, alpha=0.5);
plt.hist(cluster3, 30, alpha=0.5);
posterior = idata.posterior.stack(sample=("chain", "draw"))
plt.hist(posterior["cutpoints"][0], 80, alpha=0.2, color='k');
plt.hist(posterior["cutpoints"][1], 80, alpha=0.2, color='k');

方法

OrderedProbit.dist(*args, **kwargs)