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.1.tar.gz (454.3 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.1-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: invexapi-0.1.1.tar.gz
  • Upload date:
  • Size: 454.3 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.1.tar.gz
Algorithm Hash digest
SHA256 dec45467182aeeb8392518b7e8e7bf3126c0358b619c82a4ad724f3fdd2022e6
MD5 2d5999ee078494e304e6d3a3de535ae9
BLAKE2b-256 a5eccf83b00739585780ab872eb09017ec24d1990aef702c96c3ac32ce774071

See more details on using hashes here.

File details

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

File metadata

  • Download URL: invexapi-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9afef8f6fea8f304296b83869f2abdf31eee79c3d00e55c2a9f54b2d8b50d36
MD5 137f55a8342e70cdc232dc4d6b91df4f
BLAKE2b-256 b77f1097b9bd74c570bc3514accbd7e21c61ed6e86a4bf6c688e11138e042b9d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.3

2 files

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

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