tgmm.constraints API¶
The exact block solvers behind GaussianMixture's weight_bounds, mean_bounds and covariance_bounds (see
Fixed values and bounds for the mathematics). Each maximises the
expected complete-data log-likelihood over one parameter block, so the constrained M-step is an ECM step. Most users never call them
directly.
water_fill_weights(counts, lo, hi)
¶
Maximiser of :math:\sum_k n_k\log\pi_k subject to :math:\sum_k\pi_k=1 and :math:lo_k\le\pi_k\le hi_k.
The Lagrangian gives :math:\pi_k=\mathrm{clip}(n_k/\nu,\,lo_k,\,hi_k) where the multiplier :math:\nu>0 solves
:math:\sum_k\mathrm{clip}(n_k/\nu,lo_k,hi_k)=1. The left-hand side is decreasing in :math:\nu, so the root is
bracketed by doubling and found by bisection. When the unconstrained solution :math:n_k/\sum_j n_j is feasible it is
returned as is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
counts
|
(Tensor, shape(K))
|
Non-negative (effective) component counts :math: |
required |
lo
|
(Tensor, shape(K))
|
Bounds; |
required |
hi
|
(Tensor, shape(K))
|
Bounds; |
required |
Returns:
| Type | Description |
|---|---|
(Tensor, shape(K))
|
Weights summing to 1 (to floating-point precision) inside the bounds. |
Source code in tgmm/constraints.py
box_qp_coordinate_ascent(ybar, precision, lo, hi, x0, max_sweeps=50, tol=1e-12)
¶
Maximiser of :math:-\tfrac12 (x-\bar y)^\top P (x-\bar y) over the box :math:lo\le x\le hi, per row, by exact coordinate
ascent started at the feasible point x0.
The conditional maximiser in coordinate :math:j is
:math:x_j=\mathrm{clip}\big(\bar y_j-\sum_{l\ne j}P_{jl}(x_l-\bar y_l)/P_{jj},\,lo_j,\,hi_j\big), so every sweep
never decreases the objective (ECM) and repeated sweeps converge to the box-QP optimum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ybar
|
(Tensor, shape(K, d))
|
|
required |
lo
|
(Tensor, shape(K, d))
|
|
required |
hi
|
(Tensor, shape(K, d))
|
|
required |
x0
|
(Tensor, shape(K, d))
|
|
required |
precision
|
(Tensor, shape(K, d, d))
|
Positive-definite :math: |
required |
max_sweeps
|
int
|
Upper bound on the number of full sweeps over the coordinates. |
50
|
tol
|
float
|
Stop when no coordinate moved by more than |
1e-12
|
Source code in tgmm/constraints.py
clip_eigenvalues(S, lo, hi)
¶
Closest feasible covariance in the sense of the Gaussian likelihood: the minimiser of
:math:n\log|\Sigma|+\mathrm{tr}(\Sigma^{-1}T) over :math:lo\,I\preceq\Sigma\preceq hi\,I with :math:S=T/n has the
eigenvectors of :math:S and its eigenvalues clipped to :math:[lo,hi] (von Neumann's trace inequality reduces the problem
to one scalar problem per eigenvalue).
Matrices that already satisfy the bounds are returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
(Tensor, shape(..., d, d))
|
Symmetric matrices. |
required |
lo
|
float or Tensor
|
Scalars, or tensors broadcastable to the leading shape |
required |
hi
|
float or Tensor
|
Scalars, or tensors broadcastable to the leading shape |
required |