Mathematics¶
This page formalizes the main mathematical ideas used in kfc-procedure.
1. Bregman divergence¶
A Bregman divergence is generated by a strictly convex differentiable function:
For two points \(x, y \in \mathcal{X}\), the Bregman divergence is:
Variable definitions¶
| Symbol | Meaning |
|---|---|
| \(x\) | input sample |
| \(y\) | reference point or centroid |
| \(\phi\) | strictly convex generator |
| \(\nabla \phi(y)\) | gradient of generator at \(y\) |
| \(D_\phi(x, y)\) | divergence from \(x\) to \(y\) |
Important property
A Bregman divergence is not necessarily symmetric. Usually, \(D_\phi(x, y) \neq D_\phi(y, x)\).
2. Bregman K-Means objective¶
Given samples:
and centroids:
Bregman K-Means minimizes:
where:
The assignment step is:
The centroid update used in the implementation is the arithmetic mean:
Intuition¶
The assignment step asks: "Which centroid is closest under this divergence?" The update step moves each centroid to the average of the samples assigned to it.
3. Supported divergences¶
Squared Euclidean divergence¶
Generator:
Gradient:
Divergence:
Domain:
Use this as the default for general numerical data.
Generalized Kullback-Leibler divergence¶
Generator:
Gradient:
Divergence:
Domain:
Use this for strictly positive count-like or intensity-like features.
Itakura-Saito divergence¶
Generator:
Gradient:
Divergence:
Domain:
This divergence is scale-sensitive and useful for positive-valued data.
Logistic divergence¶
Generator:
Gradient:
Divergence:
Domain:
Use this for probability-like features bounded between 0 and 1.
4. KFCProcedure formulation¶
Let there be \(m\) divergences:
For each divergence \(D_{\phi_j}\), K-step learns a clustering function:
For each divergence \(j\) and cluster \(k\), F-step fits a local predictor:
For a new sample \(x\), the divergence-specific prediction is:
The prediction vector is:
The C-step combiner learns or applies:
Final prediction:
5. Regression combiners¶
Mean combiner¶
where \(P \in \mathbb{R}^{n \times m}\) is the prediction matrix.
Weighted mean combiner¶
The weighted combiner fits a linear model:
When fit_intercept=False, this becomes:
The ordinary least squares objective is:
Stacking regressor¶
A meta-regressor \(g_\theta\) is trained on the prediction matrix:
The default meta-model is linear regression.
6. Classification combiners¶
Majority vote¶
For prediction row \(P_i = [P_{i1}, \ldots, P_{im}]\), the majority vote prediction is:
Stacking classifier¶
The default stacking classifier uses logistic regression as a meta-classifier:
7. COBRA mathematical formulation¶
Let \(r_1, \ldots, r_q\) be base estimators. The prediction-space representation of a sample \(x\) is:
For a test sample \(x\), COBRA compares \(z(x)\) with calibration prediction vectors \(z(x_l)\).
Distance:
Kernel weight:
where:
| Symbol | Meaning |
|---|---|
| \(\kappa\) | kernel function |
| \(\lambda\) | bandwidth or scaling parameter |
| \(x_i^{(l)}\) | calibration sample |
| \(y_i^{(l)}\) | calibration target |
Regression prediction:
The bandwidth is selected by minimizing cross-validation loss:
8. MixCOBRA formulation¶
MixCOBRA combines input-space and prediction-space distances.
Input-space distance:
Prediction-space distance:
Two-parameter mixing:
The optimized parameters are:
One-parameter mode concatenates normalized input and prediction features and optimizes a single bandwidth-like parameter.
9. Loss functions in COBRA core¶
The COBRA core supports several losses:
| Loss | Formula |
|---|---|
| MSE | \(\frac{1}{n}\sum_i (y_i - \hat{y}_i)^2\) |
| MAE | $\frac{1}{n}\sum_i |
| Huber | quadratic for small errors, linear for large errors |
| Quantile | \(\max(\tau e, (\tau-1)e)\) where \(e=y-\hat{y}\) |
| Log loss | cross-entropy for probabilistic classification |
| Hinge | \(\max(0, 1-y\hat{y})\) |
10. Kernel functions in COBRA core¶
Kernel functions convert distances into weights.
| Kernel | Weight form |
|---|---|
radial, gaussian, rbf |
\(\exp(-D)\) |
exponential |
\(\exp(-D^p)\) |
cauchy |
\(\frac{1}{1+D}\) |
reverse_cosh |
\(\frac{1}{\cosh(D)^p}\) |
epanechnikov |
\(1-D\) if \(D<1\), else 0 |
triangular |
$1- |
biweight |
\((1-D)^2\) if \(D<1\), else 0 |
triweight |
\((1-D)^3\) if \(D<1\), else 0 |
cobra |
indicator \(\mathbb{1}[D < \tau]\) |
Implementation detail
The code often applies a kernel adapter before the kernel. For example, the one-parameter adapter transforms a distance matrix as bandwidth * D.