Skip to main content

InvexAPI

License: BSD-3-Clause Python 3.10+ PyTorch only

invexapi

A minimal, PyTorch-only toolkit for invex optimization: penalties with proven optimality certificates, and the solvers that use them.


Why invexity?

Invex functions are a strict generalization of convexity: every stationary point is still a global minimum, but the function itself need not be convex. That gives non-convex penalties (sparsity-promoting, non-smooth, highly structured) the same global-optimality guarantee convex optimization enjoys — without paying for it with local minima.

invexapi packages this idea as code: penalties that carry a machine-checkable certificate of which mathematical class they belong to (convex, invex, quasi-convex, quasi-invex), and generic solvers that read those certificates to warn you when no optimality guarantee applies.

Install

pip install -e .              # editable install
pip install -e ".[dev]"       # + pytest, numpy for the test suite
pip install -e ".[examples]"  # + deps used only by examples/

Quick start

import torch
from invexapi import QuasinormInvexPenalty
from invexapi.optim import FISTA

class DataFidelity:
    def __init__(self, y): self.y = y
    def value(self, x): return 0.5 * torch.sum((x - self.y) ** 2)
    def grad(self, x): return x - self.y

y = torch.randn(100)
smooth = DataFidelity(y)
penalty = QuasinormInvexPenalty(lamb=0.1, q=0.5)
solver = FISTA(smooth, penalty, step=1.0)

x_hat, history = solver.run(y.clone())

Any object exposing the right methods (value, grad, prox) works as a smooth/penalty/objective — the built-in penalties are just one plug-in choice.

What's inside

Penalties (invexapi.penalties) — loss/penalty terms plus a certificate of what's provably known about each one:

Penalty Form Certified as
QuasinormInvexPenalty(lamb, q) λ·|x|^q invex
LogInvexPenalty(lamb) log(1+|x|) − |x|/(2+2|x|) invex
TikhonovPenalty(lamb) λ/2·‖x‖² convex, invex, quasi-convex
L1Penalty(lamb) λ·‖x‖₁ convex, invex, quasi-convex

Certificates are attached explicitly and never inferred — convexity composes additively, but invexity does not, so a combined objective only carries a certificate someone has actually proven for it.

Solvers (invexapi.optim) — generic, decoupled from the penalties above:

  • GradientDescent — with optional Armijo backtracking line search
  • FISTA — accelerated proximal gradient for smooth(x) + penalty(x)
  • NonlinearCG — Polak-Ribière+ with automatic restart
  • LinearizedADMM — for smooth(x) + penalty(D@x) (e.g. total variation)

All four warn (never error) when run on an objective without a convex/invex certificate, since no global-optimum guarantee applies in that case.

Linear operators (invexapi.penalties.operators) — Identity and FiniteDifference2D (2D total variation), each with a verified adjoint.

Structured documentation (invexapi.metadata) — design provenance, rejected alternatives, and invariants as introspectable dataclasses rather than prose, exportable as JSON for downstream tooling:

import invexapi
print(invexapi.metadata.dump_all_json(indent=2))

GPU support

Nothing in invexapi is device-specific — every operation derives its device from its input tensors. Move your data to CUDA before calling a solver and everything downstream follows:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
x_hat, history = solver.run(y.to(device))

Testing

pytest

Penalty math is validated against independent NumPy reference implementations on fixed-seed random inputs, with no CUDA dependency anywhere in this repo.

Examples

See examples/ for denoising and deblurring scripts covering FISTA and Linearized ADMM with total variation, using both the quasinorm and log invex penalties. The ADMM/TV examples need a test image, fetched separately:

python examples/data/download.py

License

BSD 3-Clause, see LICENSE.

References

This library reproduces and generalizes results from the following papers:

  1. Pinilla, S., Sanabria, A., Bi, J., & Egiazarian, K. (2025). What makes neural networks trainable? Invexity as a structural design principle in AI.
  2. Pinilla, S., & Thiyagalingam, J. (2024). Global optimality for non-linear constrained restoration problems via invexity. International Conference on Learning Representations (ICLR), 2024, pp. 11990–12027.
  3. Pinilla, S., Mu, T., Bourne, N., & Thiyagalingam, J. (2022). Improved imaging by invex regularizers with global optima guarantees. Advances in Neural Information Processing Systems (NeurIPS), 35, pp. 10780–10794.
  4. Pinilla, S., Yeung, S.-L., & Thiyagalingam, J. (2024). Global convergence of alternating direction method of multipliers for invex objective losses. IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) 2024, pp. 9361–9365.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

invexapi-0.1.0.tar.gz (454.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

invexapi-0.1.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file invexapi-0.1.0.tar.gz.

File metadata

  • Download URL: invexapi-0.1.0.tar.gz
  • Upload date:
  • Size: 454.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.12

File hashes

Hashes for invexapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a3dc5e0d35e718f937621e8f57f672e6006efb211b50dd21f306c7b885e4a00
MD5 4537e23c9194d69900acacc5015ddb9e
BLAKE2b-256 4b7c63ecb4a2d2179b8110f3608c9733cde69208d8c1b4c4c7d25ccfa13ed408

See more details on using hashes here.

File details

Details for the file invexapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: invexapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.12

File hashes

Hashes for invexapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fee80bd29b000e1069604981c15f312902106e72867cb4ea5669346a6c141ea5
MD5 7990c3c50760669b3d60dea4ad61bcad
BLAKE2b-256 9b8a640c56b895a33a75ced99c14d04a9c3952a5f1505bb6aa0d6c0121a13144

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page