Ordered and Zero-Inflated Families¶
Ordered families model ranked outcomes, such as low, medium, and high, through thresholds on a linear predictor (McCullagh, 1980). The zero-inflated and hurdle families model extra zero outcomes (Mullahy, 1986; McLachlan and Peel, 2000): their parameters give the probability of the zero branch and the distribution on the other branch. Their log probabilities are computed with the stable methods of (Mรคchler, 2012).
For a proportion that may equal zero or one, an inflated beta distribution combines point masses at the endpoints with a density between them (Ospina and Ferrari, 2010). An endpoint probability and an interior density are different quantities, and each contribution is scored against its own measure, discrete or continuous.
Discrimination defaults to one and must be finite and strictly positive. The formula frontend additionally provides cumulative, adjacent-category, stopping-ratio, continuation-ratio, and hurdle-cumulative constructions through a shared log-probability kernel. Their ordinal guide and formal laws distinguish cumulative threshold ordering from unconstrained noncumulative thresholds and identify the hurdle response codes.
The module gives ordered categorical families, conditional and inline, and the zero-inflated, hurdle, and mixture distributions that PyTorch does not include.
ordered
¶
Cutpoint-parameterised ordered-categorical morphisms.
Ordered-categorical distributions assign probability mass to a
discrete set of ordered categories {0, 1, ..., K-1} via a latent
real-valued eta and K - 1 cutpoints
c_0 < c_1 < ... < c_{K-2}. The cumulative probability of
landing at or below category k is CDF(c_k - eta), where
CDF is either the logistic or the standard normal cumulative
distribution function:
P(Y <= k | eta, c) = CDF(c_k - eta) for 0 <= k < K - 1
P(Y = k | eta, c) = CDF(c_k - eta) - CDF(c_{k-1} - eta)
P(Y = 0 | eta, c) = CDF(c_0 - eta)
P(Y = K - 1 | eta, c) = 1 - CDF(c_{K-2} - eta)
The cutpoints argument is supplied at call time as a 1-D tensor
of length K - 1, allowing the same morphism to be reused with
different cutpoint vectors across observations or models.
Sampling is non-reparameterisable: the support is discrete.
ConditionalOrderedLogistic
¶
ConditionalOrderedLogistic(domain: AnySpace, codomain: AnySpace, num_categories: int, hidden_dim: int | Sequence[int] | None = None, param_source: ParamSource | None = None, param_source_option: str | None = None)
Bases: _ConditionalOrdered
Conditional ordered-logistic over num_categories ordered classes.
The latent eta(x) is computed by the parameter source. Given
a vector of num_categories - 1 ordered cutpoints supplied at
call time, the probability of category k is
P(Y = k) = sigmoid(c_k - eta) - sigmoid(c_{k-1} - eta)
with the conventions sigmoid(c_{-1} - eta) = 0 and
sigmoid(c_{K-1} - eta) = 1.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source space.
TYPE:
|
codomain
|
Target space; semantically the set of ordered categories.
TYPE:
|
num_categories
|
Number of ordered categories
TYPE:
|
hidden_dim
|
Hidden layer width for the neural parameter source.
TYPE:
|
Source code in src/quivers/continuous/ordered.py
ConditionalOrderedProbit
¶
ConditionalOrderedProbit(domain: AnySpace, codomain: AnySpace, num_categories: int, hidden_dim: int | Sequence[int] | None = None, param_source: ParamSource | None = None, param_source_option: str | None = None)
Bases: _ConditionalOrdered
Conditional ordered-probit over num_categories ordered classes.
Identical to :class:ConditionalOrderedLogistic but uses the
standard normal cumulative distribution function in place of the
logistic CDF.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source space.
TYPE:
|
codomain
|
Target space; semantically the set of ordered categories.
TYPE:
|
num_categories
|
Number of ordered categories
TYPE:
|
hidden_dim
|
Hidden layer width for the neural parameter source.
TYPE:
|
Source code in src/quivers/continuous/ordered.py
_ordered
¶
Compatibility constructors for cumulative ordinal logit and probit distributions.
OrderedLogistic
¶
Bases: OrdinalDistribution
Ordered-logit distribution over K = cutpoints.shape[-1] + 1
ordered categories indexed 0 .. K - 1.
With a real predictor eta and a sorted cutpoint vector
c = (c_0 < c_1 < ... < c_{K-2}):
P(Y = 0) = sigmoid(c_0 - eta)P(Y = k) = sigmoid(c_k - eta) - sigmoid(c_{k-1} - eta)for0 < k < K - 1P(Y = K - 1) = 1 - sigmoid(c_{K-2} - eta)
Cutpoint broadcasting:
- Shared cutpoints
cof shape(K - 1,)apply uniformly to every row. - Per-row cutpoints of shape
(batch, K - 1)apply distinct thresholds per observation (the ordinal-mixed-model case). - Arbitrary leading batch shape is supported; the last axis is always the cutpoint axis.
Log probabilities are computed without forming the difference of
sigmoids: with a < b the two cutpoint offsets bounding a
category, sigmoid(b) - sigmoid(a) equals
sigmoid(b) * sigmoid(-a) * (1 - exp(a - b)), so its log is a sum
of two log-sigmoids and a log(1 - exp(.)) term, each accurate in
both tails. A category far from the predictor thus keeps its exact
log probability rather than one floored at the smallest normal
float.
| PARAMETER | DESCRIPTION |
|---|---|
predictor
|
Finite real predictor with arbitrary batch dimensions.
TYPE:
|
cutpoints
|
Finite, strictly increasing thresholds with final dimension K-1.
TYPE:
|
validate_args
|
Whether to validate arguments and response codes.
TYPE:
|
References
Source code in src/quivers/continuous/_ordered.py
OrderedProbit
¶
Bases: OrderedLogistic
Ordered-probit distribution over K = cutpoints.shape[-1] + 1
ordered categories indexed 0 .. K - 1.
The ordered-logistic construction with standard normal latent noise:
P(Y <= k) = Phi(c_k - eta) for the standard normal distribution
function Phi, so P(Y = k) = Phi(c_k - eta) - Phi(c_{k-1} -
eta). Predictor and cutpoint broadcasting follow OrderedLogistic.
Log probabilities are computed without forming the difference of
distribution functions: with a < b the offsets bounding a
category, log(Phi(b) - Phi(a)) = log Phi(b) + log(1 - exp(log
Phi(a) - log Phi(b))), and for a category above the predictor
(a > 0) the same identity on the mirrored offsets -b < -a,
since Phi(b) - Phi(a) = Phi(-a) - Phi(-b). Each term is accurate in
both tails, so a category far from the predictor keeps its log
probability.
| PARAMETER | DESCRIPTION |
|---|---|
predictor
|
The real predictor
TYPE:
|
cutpoints
|
The sorted cutpoints,
TYPE:
|
validate_args
|
Whether to validate arguments and values.
TYPE:
|
Source code in src/quivers/continuous/_ordered.py
_zip_hurdle
¶
Zero-inflated, hurdle, and Normal mixture families.
The inflation and Normal-mixture families compose probability measures. The hurdle family scores a normalized positive Poisson component directly, including its point-mass limit at rate zero.
ZeroInflatedPoisson
¶
Bases: _InflatedCount
Mixture([pi, 1-pi], [PointMass(0), Poisson(rate)]).
Total zero mass pi + (1-pi) * exp(-rate) per Lambert 1992;
the count component is the unrestricted Poisson, so excess zeros
come from both the structural-zero spike and the natural Poisson
zeros. Contrast with
HurdlePoisson
in which the count component is zero-truncated.
Reference: Lambert 1992.
Source code in src/quivers/continuous/_zip_hurdle.py
HurdlePoisson
¶
Bases: _CountCDF, Distribution
A point mass at zero mixed with a normalized positive Poisson.
A Bernoulli with probability 1 - zero_prob selects the positive
component. At rate zero that component is the point mass at one,
giving the continuous extension in the rate. Negative rates are
refused. The disjoint supports permit direct scoring of each branch.
Reference: Mullahy 1986.
Source code in src/quivers/continuous/_zip_hurdle.py
log_prob
¶
Score counts against the normalized hurdle distribution.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Nonnegative integer observations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log probabilities broadcast over observations and parameters. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If validation is enabled and an observation is outside the support. |
Source code in src/quivers/continuous/_zip_hurdle.py
sample
¶
Draw counts using a conditioned first arrival for the positive branch.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
Dimensions prepended to the parameter batch shape. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Nonnegative integer draws, including the rate-zero limit. |
Source code in src/quivers/continuous/_zip_hurdle.py
MixtureNormal
¶
Bases: Distribution
Mixture(weights, [Normal(loc_k, scale_k) for k]).
Same-family Gaussian mixture with K = weights.shape[-1]
components. Mixing weights live in the K-simplex along the last
axis; component means and scales also vary along the last axis
and broadcast over the leading batch.
For mixing arbitrary families together, construct the
Mixture directly with a
list of heterogeneous components.
Reference: McLachlan & Peel 2000.
Source code in src/quivers/continuous/_zip_hurdle.py
recorded_event_log_prob
¶
recorded_event_log_prob(value: Tensor, *, status: Tensor | int | None = None, interval_upper: Tensor | float | None = None, trunc_lower: Tensor | float | None = None, trunc_upper: Tensor | float | None = None) -> Tensor
Score a recorded event with each component truncated separately.
brms normalizes every mixture component on the truncation interval and
then mixes the normalized components with the mixing weights. The
score is log sum_k w_k P_k(event) / P_k(lower <= Y <= upper), and
censoring alone reduces to the mass of the mixture. Cost: O(n K).
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Exact outcomes or first censoring endpoints.
TYPE:
|
status
|
Censoring codes -1 left, 0 exact, 1 right, 2 interval.
TYPE:
|
interval_upper
|
Upper endpoints of interval-censored rows.
TYPE:
|
trunc_lower
|
Inclusive truncation bounds.
TYPE:
|
trunc_upper
|
Inclusive truncation bounds.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Unweighted log likelihoods per row. |
Source code in src/quivers/continuous/_zip_hurdle.py
componentwise_truncation
¶
Mix the components after normalizing each on the truncation interval.
| PARAMETER | DESCRIPTION |
|---|---|
lower
|
Inclusive truncation bounds; None leaves a side open.
TYPE:
|
upper
|
Inclusive truncation bounds; None leaves a side open.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Mixture
|
The brms truncated mixture, sampled by component then by the component's truncated Normal law. |
Source code in src/quivers/continuous/_zip_hurdle.py
ZeroOneInflatedBeta
¶
ZeroOneInflatedBeta(mu: Tensor, phi: Tensor, zoi: Tensor, coi: Tensor, validate_args: bool | None = None)
Bases: Distribution
Zero-one inflated beta distribution.
Mixture of point masses at 0 and 1 with a continuous Beta on (0, 1):
P(y = 0) = zoi * (1 - coi)P(y = 1) = zoi * coiP(0 < y < 1) = 1 - zoi- On the open interval, the density is
(1 - zoi)times the density ofBeta(mu * phi, (1 - mu) * phi).
Parameters follow the mean-precision Beta reparameterization and the
brms zoi / coi inflation probabilities. The mean is strictly
between zero and one, precision is positive, and inflation
probabilities include both endpoints. Formula frontend emits
ZeroOneInflatedBeta(mu, phi, zoi, coi).
For the distributional background, see Ospina and Ferrari (2010). The parameter convention follows the brms family documentation.
Source code in src/quivers/continuous/_zip_hurdle.py
mean
property
¶
mean: Tensor
Expected response, including the atom at one and the interior mean.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The atom-at-one contribution plus the weighted interior mean. |
log_partial_first_moment
¶
log_partial_first_moment(low: Tensor, high: Tensor, *, lower_closed: bool | Tensor = True, upper_closed: bool | Tensor = True) -> Tensor
Log of the first moment restricted to an interval.
The atom at zero adds nothing, the atom at one adds its mass when
the interval holds one, and the interior adds 1 - zoi times the
partial moment of the beta law, which is its mean times an interval
mass of the beta law with its first shape raised by one.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Float64 interval ends, possibly infinite.
TYPE:
|
high
|
Float64 interval ends, possibly infinite.
TYPE:
|
lower_closed
|
Endpoint membership, which decides whether an end at one holds the atom there.
TYPE:
|
upper_closed
|
Endpoint membership, which decides whether an end at one holds the atom there.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Float64 |
Source code in src/quivers/continuous/_zip_hurdle.py
log_cdf_left
¶
Evaluate log P(Y < value), excluding an atom at the query.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Real query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Float64 log left limits of the CDF. |
Source code in src/quivers/continuous/_zip_hurdle.py
log_survival_function_left
¶
Evaluate log P(Y >= value), including an atom at the query.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Real query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Float64 log survival including the query point. |
Source code in src/quivers/continuous/_zip_hurdle.py
Cited sources¶
Peter McCullagh. Regression Models for Ordinal Data. Journal of the Royal Statistical Society: Series B (Methodological), 42(2):109โ127, 1980. URL: https://academic.oup.com/jrsssb/article/42/2/109/7027621, doi:10.1111/j.2517-6161.1980.tb01109.x.
John Mullahy. Specification and Testing of Some Modified Count Data Models. Journal of Econometrics, 33(3):341โ365, 1986. URL: https://www.sciencedirect.com/science/article/abs/pii/0304407686900023, doi:10.1016/0304-4076(86)90002-3.
Geoffrey McLachlan and David Peel. Finite Mixture Models. Wiley, 2000. URL: https://onlinelibrary.wiley.com/doi/book/10.1002/0471721182, doi:10.1002/0471721182.
Martin Mรคchler. Accurately Computing log(1 - exp(-|a|)): Assessed by the Rmpfr Package. Technical note, CRAN, 2012. Document dated April and October 2012; typeset September 5, 2026. URL: https://cran.r-project.org/package=Rmpfr/vignettes/log1mexp-note.pdf.
Raydonal Ospina and Silvia L. P. Ferrari. Inflated Beta Distributions. Statistical Papers, 51:111โ126, 2010. URL: https://link.springer.com/article/10.1007/s00362-008-0125-4, doi:10.1007/s00362-008-0125-4.