@@ -10,7 +10,9 @@ cat(' * <a href="binomial-distribution-logit-parameterization.html">Binomial Dis
1010cat(' * <a href="beta-binomial-distribution.html">Beta-Binomial Distribution</a>\n')
1111cat(' * <a href="hypergeometric-distribution.html">Hypergeometric Distribution</a>\n')
1212cat(' * <a href="categorical-distribution.html">Categorical Distribution</a>\n')
13+ cat(' * <a href="categorical-logit-glm.html">Categorical Logit Generalised Linear Model (Softmax Regression)</a>\n')
1314cat(' * <a href="ordered-logistic-distribution.html">Ordered Logistic Distribution</a>\n')
15+ cat(' * <a href="ordered-logistic-glm.html">Ordered Logistic Generalised Linear Model (Ordinal Regression)</a>\n')
1416cat(' * <a href="ordered-probit-distribution.html">Ordered Probit Distribution</a>\n')
1517}
1618```
@@ -296,6 +298,81 @@ Generate a categorical variate with outcome in range $1:N$ from
296298log-odds vector beta; may only be used in transformed data and generated
297299quantities blocks
298300
301+ ## Categorical Logit Generalised Linear Model (Softmax Regression) {#categorical-logit-glm}
302+
303+ Stan also supplies a single primitive for a Generalised Linear Model
304+ with Categorical likelihood and logit link function, i.e. a primitive
305+ for a softmax regression. This should provide a more efficient
306+ implementation of softmax regression than a manually written
307+ regression in terms of a Categorical likelihood and matrix
308+ multiplication.
309+
310+ ### Probability Mass Functions
311+
312+ If $N,M,K \in \mathbb{N}$, $N,M,K > 0$, and if $x\in \mathbb{R}^{M\cdot K}, \alpha \in \mathbb{R}^N, \beta\in \mathbb{R}^{K\cdot N}$, then for $y \in \{ 1,\ldots,N\} ^M$,
313+ \[ \text{CategoricalLogitGLM}(y~ |~ x,\alpha,\beta) = \\ [ 5pt]
314+ \prod_ {1\leq i \leq M}\text{CategoricalLogit}(y_i~ |~ \alpha+\beta_i\cdot x_i) = \\ [ 15pt]
315+ \prod_ {1\leq i \leq M}\text{Categorical}(y_i~ |~ softmax(\alpha+\beta_i\cdot x_i)). \]
316+ See section [ softmax] ( #softmax ) for the definition of the softmax function.
317+
318+ ### Sampling Statement
319+
320+ ` y ~ ` ** ` categorical_logit_glm ` ** ` (x, alpha, beta) `
321+
322+ Increment target log probability density with ` categorical_logit_glm(y | x, alpha, beta) `
323+ dropping constant additive terms.
324+ <!-- real; categorical_logit_glm ~; -->
325+ \index{{\tt \bfseries categorical\_ logit\_ glm }!sampling statement|hyperpage}
326+
327+
328+ ### Stan Functions
329+
330+ <!-- real; categorical_logit_glm_lpmf; (int y | row_vector x, vector alpha, matrix beta); -->
331+ \index{{\tt \bfseries categorical\_ logit\_ glm\_ lpmf }!{\tt (int y \textbar\ row\_ vector x, vector alpha, matrix beta): real}|hyperpage}
332+
333+ ` real ` ** ` categorical_logit_glm_lpmf ` ** ` (int y | row_vector x, vector alpha, matrix beta) ` <br >\newline
334+ The log categorical probability mass function with outcome ` y ` in
335+ $1: N $ given $N$-vector of log-odds of outcomes ` alpha + x * beta ` .
336+ The size of independant variable row vector ` x ` needs to match the number of rows of the
337+ weight matrix ` beta ` . The size of intercept vector ` alpha ` must match number
338+ of columns of the weight matrix ` beta ` .
339+
340+ <!-- real; categorical_logit_glm_lpmf; (int y | matrix x, vector alpha, matrix beta); -->
341+ \index{{\tt \bfseries categorical\_ logit\_ glm\_ lpmf }!{\tt (int y \textbar\ matrix x, vector alpha, matrix beta): real}|hyperpage}
342+
343+ ` real ` ** ` categorical_logit_glm_lpmf ` ** ` (int y | matrix x, vector alpha, matrix beta) ` <br >\newline
344+ The log categorical probability mass function with outcomes ` y ` in
345+ $1: N $ given $N$-vector of log-odds of outcomes ` alpha + x * beta ` .
346+ Same vector of intercepts ` alpha ` and same dependant variable value ` y ` are used for all instances.
347+ The number of columns of independant variable ` x ` needs to match the number of rows of the
348+ weight matrix ` beta ` . The size of intercept vector ` alpha ` must match number
349+ of columns of the weight matrix ` beta ` . If ` x ` and ` y ` are data (not parameters) this function can be executed on a GPU.
350+
351+ <!-- real; categorical_logit_glm_lpmf; (int[] y | vector theta); -->
352+ \index{{\tt \bfseries categorical\_ logit\_ glm\_ lpmf }!{\tt (int[ ] y \textbar\ row\_ vector x, vector alpha, matrix beta): real}|hyperpage}
353+
354+ ` real ` ** ` categorical_logit_glm_lpmf ` ** ` (int[] y | row_vector x, vector alpha, matrix beta) ` <br >\newline
355+ The log categorical probability mass function with outcomes ` y ` in
356+ $1: N $ given $N$-vector of log-odds of outcomes ` alpha + x * beta ` .
357+ Same vector of intercepts ` alpha ` and same row vector of independant variables ` x ` are used for all instances.
358+ The size of independant variable matrix ` x ` needs to match the number of rows of the
359+ weight vector ` beta ` . The size of intercept vector ` alpha ` must match number
360+ of columns of the weight vector ` beta ` .
361+
362+ <!-- real; categorical_logit_glm_lpmf; (int[] y | vector theta); -->
363+ \index{{\tt \bfseries categorical\_ logit\_ glm\_ lpmf }!{\tt (int[ ] y \textbar\ matrix x, vector alpha, matrix beta): real}|hyperpage}
364+
365+ ` real ` ** ` categorical_logit_glm_lpmf ` ** ` (int[] y | matrix x, vector alpha, matrix beta) ` <br >\newline
366+ The log categorical probability mass function with outcomes ` y ` in
367+ $1: N $ given $N$-vector of log-odds of outcomes ` alpha + x * beta ` .
368+ Same vector of intercepts ` alpha ` is used for all instances.
369+ The number of rows of the independent variable
370+ matrix ` x ` needs to match the length of the dependent variable vector
371+ ` y ` . The number of columns of independant variable ` x ` needs to match the number of rows of the
372+ weight matrix ` beta ` . The size of intercept vector ` alpha ` must match number
373+ of columns of the weight matrix ` beta ` . If ` x ` and ` y ` are data (not parameters) this function can be executed on a GPU.
374+
375+
299376## Ordered Logistic Distribution
300377
301378### Probability Mass Function
@@ -339,6 +416,73 @@ eta, and cutpoints c.
339416Generate an ordered logistic variate with linear predictor eta and
340417cutpoints c; may only be used in transformed data and generated quantities blocks
341418
419+ ## Ordered Logistic Generalised Linear Model (Ordinal Regression)
420+
421+ ### Probability Mass Function
422+
423+ If $N,M,K \in \mathbb{N}$ with $N, M > 0$, $K > 2$, $c \in \mathbb{R}^{K-1}$ such that
424+ $c_k < c_ {k+1}$ for $k \in \{ 1,\ldots,K-2\} $, and $x\in \mathbb{R}^{N\cdot M}, \beta\in \mathbb{R}^M$, then for $y \in \{ 1,\ldots,K\} ^N$,
425+ \[ \text{OrderedLogisticGLM}(y~ |~ x,\beta,c) = \\ [ 4pt]
426+ \prod_ {1\leq i \leq N}\text{OrderedLogistic}(y_i~ |~ x_i\cdot \beta,c) = \\ [ 17pt]
427+ \prod_ {1\leq i \leq N}\left\{ \begin{array}{ll}
428+ 1 - \text{logit}^{-1}(x_i\cdot \beta - c_1) & \text{if } y = 1, \\ [ 4pt]
429+ \text{logit}^{-1}(x_i\cdot \beta - c_ {y-1}) - \text{logit}^{-1}(x_i\cdot \beta - c_ {y}) & \text{if } 1 < y < K, \text{and} \\ [ 4pt]
430+ \text{logit}^{-1}(x_i\cdot \beta - c_ {K-1}) - 0 & \text{if } y = K.
431+ \end{array} \right. \] The $k=K$
432+ case is written with the redundant subtraction of zero to illustrate
433+ the parallelism of the cases; the $y=1$ and $y=K$ edge cases can be
434+ subsumed into the general definition by setting $c_0 = -\infty$ and
435+ $c_K = +\infty$ with $\text{logit}^{-1}(-\infty) = 0$ and
436+ $\text{logit}^{-1}(\infty) = 1$.
437+
438+ ### Sampling Statement
439+
440+ ` y ~ ` ** ` ordered_logistic_glm ` ** ` (x, beta, c) `
441+
442+ Increment target log probability density with ` ordered_logistic_lpmf(y | x, beta, c) `
443+ dropping constant additive terms.
444+ <!-- real; ordered_logistic ~; -->
445+ \index{{\tt \bfseries ordered\_ logistic\_ glm }!sampling statement|hyperpage}
446+
447+ ### Stan Functions
448+
449+ <!-- real; ordered_logistic_glm_lpmf; (int y | row_vector x, vector beta, vector c); -->
450+ \index{{\tt \bfseries ordered\_ logistic\_ glm\_ lpmf }!{\tt (int y \textbar\ row\_ vector x, vector beta, vector c): real}|hyperpage}
451+
452+ ` real ` ** ` ordered_logistic_glm_lpmf ` ** ` (int y | row_vector x, vector beta, vector c) ` <br >\newline
453+ The log ordered logistic probability mass of y, given linear predictors ` x * beta ` , and cutpoints c.
454+ The size of independant variable row vector ` x ` needs to match the size of the weight vector ` beta ` .
455+ Cutpoints ` c ` must be ordered.
456+
457+ <!-- real; ordered_logistic_glm_lpmf; (int y | matrix x, vector beta, vector c); -->
458+ \index{{\tt \bfseries ordered\_ logistic\_ glm\_ lpmf }!{\tt (int y \textbar\ matrix x, vector beta, vector c): real}|hyperpage}
459+
460+ ` real ` ** ` ordered_logistic_glm_lpmf ` ** ` (int y | matrix x, vector beta, vector c) ` <br >\newline
461+ The log ordered logistic probability mass of y, given linear predictors ` x * beta ` , and cutpoints c.
462+ Same value of independant variable ` y ` is used for all instances.
463+ The number of columns of independant variable row vector ` x ` needs to match the size of the weight vector ` beta ` .
464+ Cutpoints ` c ` must be ordered. If ` x ` and ` y ` are data (not parameters) this function can be executed on a GPU.
465+
466+ <!-- real; ordered_logistic_glm_lpmf; (int[] y | row_vector x, vector beta, vector c); -->
467+ \index{{\tt \bfseries ordered\_ logistic\_ glm\_ lpmf }!{\tt (int[ ] y \textbar\ row\_ vector x, vector beta, vector c): real}|hyperpage}
468+
469+ ` real ` ** ` ordered_logistic_glm_lpmf ` ** ` (int[] y | row_vector x, vector beta, vector c) ` <br >\newline
470+ The log ordered logistic probability mass of y, given linear predictors ` x * beta ` , and cutpoints c.
471+ Same row vector of independant variables ` x ` is used for all instances.
472+ The size of independant variable row vector ` x ` needs to match the size of the weight vector ` beta ` .
473+ Cutpoints ` c ` must be ordered.
474+
475+ <!-- real; ordered_logistic_glm_lpmf; (int[] y | matrix x, vector beta, vector c); -->
476+ \index{{\tt \bfseries ordered\_ logistic\_ glm\_ lpmf }!{\tt (int[ ] y \textbar\ matrix x, vector beta, vector c): real}|hyperpage}
477+
478+ ` real ` ** ` ordered_logistic_glm_lpmf ` ** ` (int[] y | matrix x, vector beta, vector c) ` <br >\newline
479+ The log ordered logistic probability mass of y, given linear predictors
480+ ` x * beta ` , and cutpoints c.
481+ The number of rows of the independent variable matrix ` x ` needs to match the length of the dependent variable vector ` y ` .
482+ The number of columns of independant variable row vector ` x ` needs to match the size of the weight vector ` beta ` .
483+ Cutpoints ` c ` must be ordered. If ` x ` and ` y ` are data (not parameters) this function can be executed on a GPU.
484+
485+
342486## Ordered Probit Distribution
343487
344488### Probability Mass Function
0 commit comments