adelie.glm.multinomial#

adelie.glm.multinomial(y: ndarray, *, weights: ndarray | None = None, dtype: float32 | float64 | None = None)[source]#

Creates a Multinomial GLM family object.

The Multinomial GLM family specifies the loss function as:

\[\begin{align*} \ell(\eta) = \frac{1}{K} \sum\limits_{i=1}^n w_i \left( -\sum\limits_{k=1}^{K} y_{ik} \eta_{ik} + \log\left( \sum\limits_{\ell=1}^{K} e^{\eta_{i\ell}} \right) \right) \end{align*}\]

The link function is given by

\[\begin{align*} g(\mu)_{ik} &= \log(\mu_{ik}) + C_i \end{align*}\]

for any arbitrary constants \(C_i\).

We assume that every \(y_{ik} \in [0,1]\) and for each fixed \(i\), \(\sum_{k=1}^K y_{ik} = 1\).

Note

The hessian() method computes \(2 \mathrm{diag}(\nabla^2 \ell(\eta))\) as the diagonal majorization.

Parameters:
y(n, K) ndarray

Response matrix \(y\).

weights(n,) ndarray, optional

Observation weights \(W\). Weights are normalized such that they sum to 1. Default is None, in which case, it is set to np.full(n, 1/n).

dtypeUnion[float32, float64], optional

The underlying data type. If None, it is inferred from y, in which case y must have an underlying data type of numpy.float32 or numpy.float64. Default is None.

Returns:
glm

Multinomial GLM object.