Metadata-Version: 2.4
Name: gkm
Version: 0.1.2
Summary: Kernel Machines with stochastically motivated loss functions
Author-email: Nico Strasdat <nstrasdat@gmail.com>
License-Expression: MIT
Project-URL: repository, https://github.com/wotzlaff/gkm
Project-URL: replacement, https://wotzlaff.github.io/optimized-svm/theory/glm/
Classifier: Development Status :: 7 - Inactive
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy>=1.11
Requires-Dist: scikit-learn
Provides-Extra: dev
Requires-Dist: pytest>=7.3.1; extra == "dev"
Dynamic: license-file

# gkm: Generalized Kernel Method (deprecated)

> **DEPRECATED.** `gkm` is no longer maintained; 0.1.2 is the final release.
> It is superseded by [`optimized-svm`](https://pypi.org/project/optimized-svm/)
> ([documentation](https://wotzlaff.github.io/optimized-svm/),
> [repository](https://github.com/wotzlaff/optimized-svm)), which provides
> `KernelGLMRegressor` and `OptimizedKernelGLMRegressor` from version 0.4.0.
> See the theory page
> <https://wotzlaff.github.io/optimized-svm/theory/glm/> and the migration
> table below. `import gkm` emits a `DeprecationWarning`.

## What gkm was

`gkm` connected [generalized linear models (GLMs)](https://en.wikipedia.org/wiki/Generalized_linear_model)
with [kernel methods](https://en.wikipedia.org/wiki/Kernel_method):

- kernel machines whose loss is the deviance of an exponential-family
  distribution (Gaussian, Poisson, binomial, negative binomial, exponential),
- training by Newton's method with line search (`GKM`),
- hyperparameter tuning (regularization `lmbda`, RBF kernel width(s) `gamma`)
  by gradient descent on a K-fold cross-validation objective (relative
  deviance), where the hypergradient is computed with an adjoint
  ("sensitivity") approach instead of differentiating through the solver
  (`OptimizedGKM`).

## Migration to optimized-svm

| gkm | optimized-svm (>= 0.4.0) |
| --- | --- |
| `GKM` | `KernelGLMRegressor` |
| `OptimizedGKM` | `OptimizedKernelGLMRegressor` |
| `deviance.gaussian` | `SmoothSVR` / `OptimizedSVR` with `loss="squared"` (identity link) |
| `deviance.poisson` | `family="poisson"` |
| `deviance.Binomial` | `family="binomial"` (logit link) |
| `deviance.NegativeBinomial` (`geometric`) | `family="negative_binomial"` |
| `deviance.exponential` | `family="gamma"` (the exponential distribution is the gamma family with shape 1) |

Notes:

- **Links.** In gkm the negative binomial and exponential deviances use the
  canonical link, so the linear predictor satisfies `t < 0`. optimized-svm uses
  log links (logit for binomial). Fitted models are therefore not
  parameter-compatible; refit instead of converting.
- **Scaling of lambda.** gkm weights the loss by `1/n` (the objective is
  `0.5 * <a, K a>/lmbda + mean(loss)`), optimized-svm does not, so `lambda`
  differs by a factor of `n`.
- **No counterpart:** `regularization.penalize_gamma`, the AMSGrad optimizer
  (`minimize_method='amsgrad'`), the `links` module, and `glm.GLM`
  (linear GLM without kernel).
- optimized-svm additionally supports the tweedie family, offsets/exposure and
  a hypergradient-tuned negative binomial dispersion.

## Known issues (will not be fixed)

- `RBF.__call__` ignores `idx1`/`idx2` and always returns the full kernel
  matrix (`gkm/kernel/rbf.py:34-36`), so `OptimizedGKM(sample_objective < 1)`
  with `kernel_type='rbf'` fails.
- `RBF.compute` overwrites the stored training distance matrix `_dsqr`
  (`gkm/kernel/rbf.py:41`), so `deriv` returns wrong values after `predict`.
- `GKM(kernel_type='multi-rbf')` raises at construction: `get_initial` needs
  `dim`, which needs `prepare` to have been called (`gkm/gkm.py:29`,
  `gkm/kernel/multi_rbf.py:34-35`).
- The AMSGrad step is not a correct AMSGrad: the first moment uses
  `beta**t` instead of `beta` as decay factor and there is no bias correction
  (`gkm/amsgrad.py:46`).
- `glm.GLM` prints debug output (`gkm/glm.py:54`) and `fit` returns `None`
  instead of `self`.

## License

MIT
