Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discrete.py docs updated #7442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions pymc/distributions/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,12 +1189,15 @@ class OrderedLogistic:
R"""Ordered Logistic distribution.

Useful for regression on ordinal data values whose values range
from 1 to K as a function of some predictor, :math:`\eta`. The
from 0 to K-1 as a function of some predictor, :math:`\eta`. The
cutpoints, :math:`c`, separate which ranges of :math:`\eta` are
mapped to which of the K observed dependent variables. The number
of cutpoints is K - 1. It is recommended that the cutpoints are
constrained to be ordered.

Note: The observed values should use 0-based indexing (0, 1, ..., K-1),
consistent with Python's indexing convention.

.. math::

f(k \mid \eta, c) = \left\{
Expand All @@ -1203,9 +1206,9 @@ class OrderedLogistic:
\,, \text{if } k = 0 \\
\text{logit}^{-1}(\eta - c_{k - 1}) -
\text{logit}^{-1}(\eta - c_{k})
\,, \text{if } 0 < k < K \\
\,, \text{if } 0 < k < K-1 \\
\text{logit}^{-1}(\eta - c_{K - 1})
\,, \text{if } k = K \\
\,, \text{if } k = K-1 \\
\end{array}
\right.

Expand Down Expand Up @@ -1233,9 +1236,9 @@ class OrderedLogistic:
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
y = np.concatenate((np.zeros(n1_c),
np.ones(n2_c),
2*np.ones(n3_c))).astype(int)

# Ordered logistic regression
with pm.Model() as model:
Expand Down Expand Up @@ -1288,12 +1291,15 @@ class OrderedProbit:
Ordered Probit distributions.

Useful for regression on ordinal data values whose values range
from 1 to K as a function of some predictor, :math:`\eta`. The
from 0 to K-1 as a function of some predictor, :math:`\eta`. The
cutpoints, :math:`c`, separate which ranges of :math:`\eta` are
mapped to which of the K observed dependent variables. The number
of cutpoints is K - 1. It is recommended that the cutpoints are
constrained to be ordered.

Note: The observed values should use 0-based indexing (0, 1, ..., K-1),
consistent with Python's indexing convention.

In order to stabilize the computation, log-likelihood is computed
in log space using the scaled error function `erfcx`.

Expand All @@ -1305,9 +1311,9 @@ class OrderedProbit:
\,, \text{if } k = 0 \\
\text{normal_cdf}(0, \sigma, \eta - c_{k - 1}) -
\text{normal_cdf}(0, \sigma, \eta - c_{k})
\,, \text{if } 0 < k < K \\
\,, \text{if } 0 < k < K-1 \\
\text{normal_cdf}(0, \sigma, \eta - c_{K - 1})
\,, \text{if } k = K \\
\,, \text{if } k = K-1 \\
\end{array}
\right.

Expand Down Expand Up @@ -1337,9 +1343,10 @@ class OrderedProbit:
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
# Note: y uses 0-based indexing (0, 1, 2)
y = np.concatenate((np.zeros(n1_c),
np.ones(n2_c),
2*np.ones(n3_c))).astype(int)

# Ordered probit regression
with pm.Model() as model:
Expand Down Expand Up @@ -1386,4 +1393,4 @@ def compute_p(cls, eta, cutpoints, sigma):
axis=-1,
)
p = pt.exp(log_p)
return p
return p
Loading